counter.go: add Counter.AddInt64() method
This method can be used for avoiding int overflows.
This commit is contained in:
parent
da211e52b9
commit
4d19f45b19
@ -42,6 +42,11 @@ func (c *Counter) Add(n int) {
|
|||||||
atomic.AddUint64(&c.n, uint64(n))
|
atomic.AddUint64(&c.n, uint64(n))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddInt64 adds n to c.
|
||||||
|
func (c *Counter) AddInt64(n int64) {
|
||||||
|
atomic.AddUint64(&c.n, uint64(n))
|
||||||
|
}
|
||||||
|
|
||||||
// Get returns the current value for c.
|
// Get returns the current value for c.
|
||||||
func (c *Counter) Get() uint64 {
|
func (c *Counter) Get() uint64 {
|
||||||
return atomic.LoadUint64(&c.n)
|
return atomic.LoadUint64(&c.n)
|
||||||
|
Loading…
Reference in New Issue
Block a user