gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

uint.go (2282B)


      1 package atomics
      2 
      3 import "sync/atomic"
      4 
      5 // Uint32 provides user-friendly means of performing atomic operations on uint32 types.
      6 type Uint32 uint32
      7 
      8 // NewUint32 will return a new Uint32 instance initialized with zero value.
      9 func NewUint32() *Uint32 {
     10 	return new(Uint32)
     11 }
     12 
     13 // Add will atomically add uint32 delta to value in address contained within i, returning new value.
     14 func (u *Uint32) Add(delta uint32) uint32 {
     15 	return atomic.AddUint32((*uint32)(u), delta)
     16 }
     17 
     18 // Store will atomically store uint32 value in address contained within i.
     19 func (u *Uint32) Store(val uint32) {
     20 	atomic.StoreUint32((*uint32)(u), val)
     21 }
     22 
     23 // Load will atomically load uint32 value at address contained within i.
     24 func (u *Uint32) Load() uint32 {
     25 	return atomic.LoadUint32((*uint32)(u))
     26 }
     27 
     28 // CAS performs a compare-and-swap for a(n) uint32 value at address contained within i.
     29 func (u *Uint32) CAS(cmp, swp uint32) bool {
     30 	return atomic.CompareAndSwapUint32((*uint32)(u), cmp, swp)
     31 }
     32 
     33 // Swap atomically stores new uint32 value into address contained within i, and returns previous value.
     34 func (u *Uint32) Swap(swp uint32) uint32 {
     35 	return atomic.SwapUint32((*uint32)(u), swp)
     36 }
     37 
     38 // Uint64 provides user-friendly means of performing atomic operations on uint64 types.
     39 type Uint64 uint64
     40 
     41 // NewUint64 will return a new Uint64 instance initialized with zero value.
     42 func NewUint64() *Uint64 {
     43 	return new(Uint64)
     44 }
     45 
     46 // Add will atomically add uint64 delta to value in address contained within i, returning new value.
     47 func (u *Uint64) Add(delta uint64) uint64 {
     48 	return atomic.AddUint64((*uint64)(u), delta)
     49 }
     50 
     51 // Store will atomically store uint64 value in address contained within i.
     52 func (u *Uint64) Store(val uint64) {
     53 	atomic.StoreUint64((*uint64)(u), val)
     54 }
     55 
     56 // Load will atomically load uint64 value at address contained within i.
     57 func (u *Uint64) Load() uint64 {
     58 	return atomic.LoadUint64((*uint64)(u))
     59 }
     60 
     61 // CAS performs a compare-and-swap for a(n) uint64 value at address contained within i.
     62 func (u *Uint64) CAS(cmp, swp uint64) bool {
     63 	return atomic.CompareAndSwapUint64((*uint64)(u), cmp, swp)
     64 }
     65 
     66 // Swap atomically stores new uint64 value into address contained within i, and returns previous value.
     67 func (u *Uint64) Swap(swp uint64) uint64 {
     68 	return atomic.SwapUint64((*uint64)(u), swp)
     69 }