github.com/rajveermalviya/gamen@v0.1.2-0.20220930195403-9be15877c1aa/internal/common/atomicx/uint.go (about) 1 // TODO: remove when we update go.mod to go1.19 2 package atomicx 3 4 import ( 5 "sync/atomic" 6 ) 7 8 type Uint[T ~uint8 | ~uint16 | ~uint32] struct { 9 _ noCopy 10 v uint32 11 } 12 13 func (x *Uint[T]) Load() T { 14 return T(atomic.LoadUint32(&x.v)) 15 } 16 func (x *Uint[T]) Store(val T) { 17 atomic.StoreUint32(&x.v, uint32(val)) 18 } 19 func (x *Uint[T]) Swap(new T) (old T) { 20 return T(atomic.SwapUint32(&x.v, uint32(new))) 21 } 22 func (x *Uint[T]) CompareAndSwap(old, new T) (swapped bool) { 23 return atomic.CompareAndSwapUint32(&x.v, uint32(old), uint32(new)) 24 }