github.com/Uhtred009/v2ray-core-1@v4.31.2+incompatible/app/stats/counter.go (about)

     1  // +build !confonly
     2  
     3  package stats
     4  
     5  import "sync/atomic"
     6  
     7  // Counter is an implementation of stats.Counter.
     8  type Counter struct {
     9  	value int64
    10  }
    11  
    12  // Value implements stats.Counter.
    13  func (c *Counter) Value() int64 {
    14  	return atomic.LoadInt64(&c.value)
    15  }
    16  
    17  // Set implements stats.Counter.
    18  func (c *Counter) Set(newValue int64) int64 {
    19  	return atomic.SwapInt64(&c.value, newValue)
    20  }
    21  
    22  // Add implements stats.Counter.
    23  func (c *Counter) Add(delta int64) int64 {
    24  	return atomic.AddInt64(&c.value, delta)
    25  }