Hunter0x7c7
2022-08-11 a82f9cb69f63aaeba40c024960deda7d75b9fece
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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)
}