counter.go 478 B

1234567891011121314151617181920212223
  1. package stats
  2. import "sync/atomic"
  3. // Counter is an implementation of stats.Counter.
  4. type Counter struct {
  5. value int64
  6. }
  7. // Value implements stats.Counter.
  8. func (c *Counter) Value() int64 {
  9. return atomic.LoadInt64(&c.value)
  10. }
  11. // Set implements stats.Counter.
  12. func (c *Counter) Set(newValue int64) int64 {
  13. return atomic.SwapInt64(&c.value, newValue)
  14. }
  15. // Add implements stats.Counter.
  16. func (c *Counter) Add(delta int64) int64 {
  17. return atomic.AddInt64(&c.value, delta)
  18. }