From 287b6584c5ed59bf1da376044bbbdafe0dd063f2 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Thu, 23 Jan 2025 08:44:49 -0300 Subject: src/stm.go: Rename AtomicGet => Deref and AtomicModify => Swap --- src/stm.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/stm.go') diff --git a/src/stm.go b/src/stm.go index 0740d0c..362c1dd 100644 --- a/src/stm.go +++ b/src/stm.go @@ -346,7 +346,7 @@ retry: } // AtomicGet is a helper function that atomically reads a value. -func AtomicGet[T any](v *Var[T]) T { +func Deref[T any](v *Var[T]) T { return v.value.Load().Get().(T) } @@ -405,7 +405,7 @@ func VoidOperation(f func(*Tx)) Operation[struct{}] { } } -func AtomicModify[T any](v *Var[T], f func(T) T) { +func Swap[T any](v *Var[T], f func(T) T) { Atomically(VoidOperation(func(tx *Tx) { v.Set(tx, f(v.Get(tx))) })) @@ -1033,7 +1033,7 @@ func NewLimiter(rate Limit, burst numTokens) *Limiter { func (rl *Limiter) tokenGenerator(interval time.Duration) { for { - lastAdd := AtomicGet(rl.lastAdd) + lastAdd := Deref(rl.lastAdd) time.Sleep(time.Until(lastAdd.Add(interval))) now := time.Now() available := numTokens(now.Sub(lastAdd) / interval) -- cgit v1.2.3