github.com/EagleQL/Xray-core@v1.4.3/app/stats/counter.go (about) 1 package stats 2 3 import "sync/atomic" 4 5 // Counter is an implementation of stats.Counter. 6 type Counter struct { 7 value int64 8 } 9 10 // Value implements stats.Counter. 11 func (c *Counter) Value() int64 { 12 return atomic.LoadInt64(&c.value) 13 } 14 15 // Set implements stats.Counter. 16 func (c *Counter) Set(newValue int64) int64 { 17 return atomic.SwapInt64(&c.value, newValue) 18 } 19 20 // Add implements stats.Counter. 21 func (c *Counter) Add(delta int64) int64 { 22 return atomic.AddInt64(&c.value, delta) 23 }