Documentation
¶
Index ¶
- type Int
- func (x *Int[T]) Add(delta T) (new T)
- func (x *Int[T]) And(mask T) (old T)
- func (x *Int[T]) CompareAndSwap(old, new T) (swapped bool)
- func (x *Int[T]) Load() T
- func (x *Int[T]) Or(mask T) (old T)
- func (x *Int[T]) Store(val T)
- func (x *Int[T]) Swap(new T) (old T)
- func (x *Int[T]) SwapIfGreater(new T) (old T, swapped bool)
- func (x *Int[T]) SwapIfLess(new T) (old T, swapped bool)
- type Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Int ¶
type Int[T ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr] struct { // contains filtered or unexported fields }
An Int is an atomic integer value. The zero value is zero.
Int must not be copied after first use.
func (*Int[T]) Add ¶
func (x *Int[T]) Add(delta T) (new T)
Add atomically adds delta to x and returns the new value.
func (*Int[T]) And ¶
func (x *Int[T]) And(mask T) (old T)
And atomically performs a bitwise AND operation on x using the bitmask provided as mask and returns the old value.
func (*Int[T]) CompareAndSwap ¶
CompareAndSwap executes the compare-and-swap operation for x.
func (*Int[T]) Load ¶
func (x *Int[T]) Load() T
Load atomically loads and returns the value stored in x.
func (*Int[T]) Or ¶
func (x *Int[T]) Or(mask T) (old T)
Or atomically performs a bitwise OR operation on x using the bitmask provided as mask and returns the old value.
func (*Int[T]) Swap ¶
func (x *Int[T]) Swap(new T) (old T)
Swap atomically stores new into x and returns the previous value.
func (*Int[T]) SwapIfGreater ¶
SwapIfGreater atomically stores new into x if new is greater than the current value. It returns the previous value and whether the swap occurred. The comparison uses the signedness and width of T. Equal values are not swapped.
func (*Int[T]) SwapIfLess ¶
SwapIfLess atomically stores new into x if new is less than the current value. It returns the previous value and whether the swap occurred. The comparison uses the signedness and width of T. Equal values are not swapped.
type Value ¶
type Value[T any] struct { // contains filtered or unexported fields }
A Value provides an atomic load and store of a value of type T. The zero value for a Value returns the zero value of T from Value.Load. Once Value.Store has been called, a Value must not be copied.
A Value must not be copied after first use.
func (*Value[T]) CompareAndSwap ¶
CompareAndSwap executes the compare-and-swap operation for the Value.
All calls to CompareAndSwap for a given Value must use values of the same concrete type. CompareAndSwap of an inconsistent type panics, as does CompareAndSwap(old, new) where new is a nil interface value.
func (*Value[T]) Load ¶
func (v *Value[T]) Load() (val T)
Load returns the value set by the most recent Store. It returns the zero value of T if there has been no call to Store for this Value.
func (*Value[T]) Store ¶
func (v *Value[T]) Store(val T)
Store sets the value of the Value v to val. All calls to Store for a given Value must use values of the same concrete type. Store of an inconsistent type panics, as does Store of a nil interface value.
func (*Value[T]) Swap ¶
func (v *Value[T]) Swap(new T) (old T)
Swap stores new into Value and returns the previous value. It returns the zero value of T if the Value is empty.
All calls to Swap for a given Value must use values of the same concrete type. Swap of an inconsistent type panics, as does Swap of a nil interface value.
func (*Value[T]) SwapIfFunc ¶
SwapIfFunc stores new into Value when shouldSwap returns true for the currently stored value. It returns the value observed by shouldSwap and whether the swap succeeded. For an empty Value, shouldSwap receives the zero value of T.
If another goroutine changes the Value while shouldSwap is running, SwapIfFunc retries with the latest value. Therefore, shouldSwap may be called multiple times and must be safe for concurrent use.
All calls to SwapIfFunc for a given Value must use values of the same concrete type. SwapIfFunc with an inconsistent type panics, as does SwapIfFunc with a nil interface value for new.