cloudflared-mirror/h2mux/bytes_counter.go

23 lines
423 B
Go
Raw Normal View History

2018-03-22 15:24:52 +00:00
package h2mux
import (
"sync/atomic"
)
type AtomicCounter struct {
count uint64
}
2018-04-06 22:47:13 +00:00
func NewAtomicCounter(initCount uint64) *AtomicCounter{
return &AtomicCounter{count: initCount}
}
2018-03-22 15:24:52 +00:00
func (c *AtomicCounter) IncrementBy(number uint64) {
atomic.AddUint64(&c.count, number)
}
// Get returns the current value of counter and reset it to 0
func (c *AtomicCounter) Count() uint64 {
return atomic.SwapUint64(&c.count, 0)
}