counter.go 499 B

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