counter.go: add Counter.AddInt64() method

This method can be used for avoiding int overflows.
This commit is contained in:
Aliaksandr Valialkin 2024-02-24 01:23:20 +02:00
parent da211e52b9
commit 4d19f45b19
No known key found for this signature in database
GPG Key ID: 52C003EE2BCDB9EB

View File

@ -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)