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