counter.go 520 B

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