xatomic

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 2, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

README

atomic.Pointer[T] have been added in Go 1.19. I made a custom implem for compatbility with go 1.18

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pointer

type Pointer[T any] struct {
	// contains filtered or unexported fields
}

Pointer is a wrapper around the standard atomic.Pointer[T] for Go 1.19+. This provides a consistent API across Go versions.

func NewPointer

func NewPointer[T any](v *T) *Pointer[T]

NewPointer returns a new Pointer[T] initialized with the given value.

func (*Pointer[T]) CompareAndSwap

func (x *Pointer[T]) CompareAndSwap(old, nEw *T) (swapped bool)

CompareAndSwap performs a compare-and-swap operation on the pointer atomically. It stores new in the pointer if the current value is equal to old. It returns true if the swap was performed, false otherwise.

func (*Pointer[T]) Load

func (x *Pointer[T]) Load() *T

Load returns the value stored in the pointer atomically.

func (*Pointer[T]) Store

func (x *Pointer[T]) Store(val *T)

Store stores the value in the pointer atomically.

func (*Pointer[T]) Swap

func (x *Pointer[T]) Swap(val *T) (old *T)

Swap swaps the value in the pointer with the new value and returns the old value atomically.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL