cloudflare/cloudflared

Public

mirrored from https://github.com/cloudflare/cloudflaredAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
2019.2.0

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

h2mux/bytes_counter.go

27lines · modecode

1package h2mux
2
3import (
4 "sync/atomic"
5)
6
7type AtomicCounter struct {
8 count uint64
9}
10
11func NewAtomicCounter(initCount uint64) *AtomicCounter {
12 return &AtomicCounter{count: initCount}
13}
14
15func (c *AtomicCounter) IncrementBy(number uint64) {
16 atomic.AddUint64(&c.count, number)
17}
18
19// Count returns the current value of counter and reset it to 0
20func (c *AtomicCounter) Count() uint64 {
21 return atomic.SwapUint64(&c.count, 0)
22}
23
24// Value returns the current value of counter
25func (c *AtomicCounter) Value() uint64 {
26 return atomic.LoadUint64(&c.count)
27}