File: counter.go

package info (click to toggle)
golang-v2ray-core 4.34.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 5,060 kB
  • sloc: sh: 404; makefile: 50; asm: 38
file content (25 lines) | stat: -rw-r--r-- 499 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// +build !confonly

package stats

import "sync/atomic"

// Counter is an implementation of stats.Counter.
type Counter struct {
	value int64
}

// Value implements stats.Counter.
func (c *Counter) Value() int64 {
	return atomic.LoadInt64(&c.value)
}

// Set implements stats.Counter.
func (c *Counter) Set(newValue int64) int64 {
	return atomic.SwapInt64(&c.value, newValue)
}

// Add implements stats.Counter.
func (c *Counter) Add(delta int64) int64 {
	return atomic.AddInt64(&c.value, delta)
}