2021-08-21 01:20:40 -04:00
|
|
|
//go:build !confonly
|
2020-09-15 11:04:26 -04:00
|
|
|
// +build !confonly
|
|
|
|
|
|
|
|
package stats
|
|
|
|
|
|
|
|
import "sync/atomic"
|
|
|
|
|
|
|
|
// Counter is an implementation of stats.Counter.
|
|
|
|
type Counter struct {
|
|
|
|
value int64
|
|
|
|
}
|
|
|
|
|
|
|
|
// Value implements stats.Counter.
|
|
|
|
func (c *Counter) Value() int64 {
|
|
|
|
return atomic.LoadInt64(&c.value)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set implements stats.Counter.
|
|
|
|
func (c *Counter) Set(newValue int64) int64 {
|
|
|
|
return atomic.SwapInt64(&c.value, newValue)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add implements stats.Counter.
|
|
|
|
func (c *Counter) Add(delta int64) int64 {
|
|
|
|
return atomic.AddInt64(&c.value, delta)
|
|
|
|
}
|