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