github.com/ravendb/ravendb-go-client@v0.0.0-20240229102137-4474ee7aa0fa/atomic_integer.go (about) 1 package ravendb 2 3 import "sync/atomic" 4 5 // atomicInteger makes porting Java code easier 6 type atomicInteger struct { 7 N int32 8 } 9 10 func (i *atomicInteger) incrementAndGet() int { 11 res := atomic.AddInt32(&i.N, 1) 12 return int(res) 13 } 14 15 func (i *atomicInteger) get() int { 16 res := atomic.LoadInt32(&i.N) 17 return int(res) 18 } 19 20 func (i *atomicInteger) Get() int { 21 res := atomic.LoadInt32(&i.N) 22 return int(res) 23 } 24 25 func (i *atomicInteger) set(n int) { 26 atomic.StoreInt32(&i.N, int32(n)) 27 } 28 29 func (i *atomicInteger) compareAndSet(old, new int) bool { 30 return atomic.CompareAndSwapInt32(&i.N, int32(old), int32(new)) 31 } 32 33 func (i *atomicInteger) decrementAndGet() int { 34 res := atomic.AddInt32(&i.N, -1) 35 return int(res) 36 }