Limits
This commit is contained in:
parent
42e46a7c22
commit
6598ce2fe4
10 changed files with 157 additions and 160 deletions
|
@ -1,32 +0,0 @@
|
|||
package util
|
||||
|
||||
import "sync"
|
||||
|
||||
type AtomicCounter[T int | int32 | int64] struct {
|
||||
value T
|
||||
mu sync.Mutex
|
||||
}
|
||||
|
||||
func NewAtomicCounter[T int | int32 | int64](value T) *AtomicCounter[T] {
|
||||
return &AtomicCounter[T]{
|
||||
value: value,
|
||||
}
|
||||
}
|
||||
func (c *AtomicCounter[T]) Inc() T {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
c.value++
|
||||
return c.value
|
||||
}
|
||||
|
||||
func (c *AtomicCounter[T]) Value() T {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
return c.value
|
||||
}
|
||||
|
||||
func (c *AtomicCounter[T]) Reset() {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
c.value = 0
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue