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