Introduce Counter.Reset()

This commit is contained in:
Eric Lippmann 2021-10-26 12:49:27 +02:00
parent 8a03745273
commit b067ed2147

View file

@ -15,6 +15,11 @@ func (c *Counter) Inc() {
c.Add(1)
}
// Reset resets the counter to 0 and returns its previous value.
func (c *Counter) Reset() uint64 {
return atomic.SwapUint64(c.ptr(), 0)
}
// Val returns the counter value.
func (c *Counter) Val() uint64 {
return atomic.LoadUint64(c.ptr())