github.com/go-eden/common@v0.1.15-0.20210617133546-059099253264/esync/sync_atomic_uint32.go (about) 1 package esync 2 3 import ( 4 "fmt" 5 "sync/atomic" 6 ) 7 8 // AtomicUint32 support atomic operation 9 type AtomicUint32 struct { 10 value uint32 11 } 12 13 func (t *AtomicUint32) Inc() uint32 { 14 return t.Add(1) 15 } 16 17 func (t *AtomicUint32) Add(v uint32) uint32 { 18 return atomic.AddUint32(&t.value, v) 19 } 20 21 func (t *AtomicUint32) Set(v uint32) { 22 atomic.StoreUint32(&t.value, v) 23 } 24 25 func (t *AtomicUint32) Get() uint32 { 26 return atomic.LoadUint32(&t.value) 27 } 28 29 func (t *AtomicUint32) Swap(v uint32) uint32 { 30 return atomic.SwapUint32(&t.value, v) 31 } 32 33 func (t *AtomicUint32) String() string { 34 return fmt.Sprint(t.Get()) 35 }