mirror of
https://github.com/cloudflare/cloudflared.git
synced 2025-07-27 14:39:58 +00:00
TUN-528: Move cloudflared into a separate repo
This commit is contained in:
27
h2mux/bytes_counter.go
Normal file
27
h2mux/bytes_counter.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package h2mux
|
||||
|
||||
import (
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
type AtomicCounter struct {
|
||||
count uint64
|
||||
}
|
||||
|
||||
func NewAtomicCounter(initCount uint64) *AtomicCounter {
|
||||
return &AtomicCounter{count: initCount}
|
||||
}
|
||||
|
||||
func (c *AtomicCounter) IncrementBy(number uint64) {
|
||||
atomic.AddUint64(&c.count, number)
|
||||
}
|
||||
|
||||
// Count returns the current value of counter and reset it to 0
|
||||
func (c *AtomicCounter) Count() uint64 {
|
||||
return atomic.SwapUint64(&c.count, 0)
|
||||
}
|
||||
|
||||
// Value returns the current value of counter
|
||||
func (c *AtomicCounter) Value() uint64 {
|
||||
return atomic.LoadUint64(&c.count)
|
||||
}
|
Reference in New Issue
Block a user