From b067ed2147c907f01e8863cbfaee4b23071f5c70 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 26 Oct 2021 12:49:27 +0200 Subject: [PATCH] Introduce Counter.Reset() --- pkg/com/counter.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/com/counter.go b/pkg/com/counter.go index 3692c63d..beea0e51 100644 --- a/pkg/com/counter.go +++ b/pkg/com/counter.go @@ -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())