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