github.com/puellanivis/breton@v0.2.16/lib/metrics/internal/atomic/value.go (about) 1 package atomic 2 3 import ( 4 "sync/atomic" 5 ) 6 7 // Value is a atomic fully variable integer Value. 8 type Value int64 9 10 // Inc increments the Value by one (1). 11 func (v *Value) Inc() { 12 v.Add(1) 13 } 14 15 // Dec decrements the Value by one (1). 16 func (v *Value) Dec() { 17 v.Add(-1) 18 } 19 20 // Add increments the Value by a given integer (may be negative). 21 func (v *Value) Add(delta int64) { 22 atomic.AddInt64((*int64)(v), delta) 23 } 24 25 // Sub decrements the Value by a given integer (may be negative). 26 func (v *Value) Sub(delta int64) { 27 v.Add(-delta) 28 } 29 30 // Set assigns a value into the Value, overriding any previous value. 31 func (v *Value) Set(value int64) { 32 atomic.StoreInt64((*int64)(v), value) 33 } 34 35 // Get returns a momentary value of the Value. 36 func (v *Value) Get() int64 { 37 return atomic.LoadInt64((*int64)(v)) 38 }