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