Skip to content

Commit

Permalink
counter.go: add Counter.AddInt64() method
Browse files Browse the repository at this point in the history
This method can be used for avoiding int overflows.
  • Loading branch information
valyala committed Feb 23, 2024
1 parent da211e5 commit 4d19f45
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions counter.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ func (c *Counter) Add(n int) {
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.
func (c *Counter) Get() uint64 {
return atomic.LoadUint64(&c.n)
Expand Down

0 comments on commit 4d19f45

Please sign in to comment.