diff options
author | EuAndreh <eu@euandre.org> | 2025-01-23 08:44:49 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2025-01-23 08:44:49 -0300 |
commit | 287b6584c5ed59bf1da376044bbbdafe0dd063f2 (patch) | |
tree | f477db4f716058f0ac3d9b721ad0ddda58c8a05d | |
parent | Setup stub fuzz and benchmark test files (diff) | |
download | stm-287b6584c5ed59bf1da376044bbbdafe0dd063f2.tar.gz stm-287b6584c5ed59bf1da376044bbbdafe0dd063f2.tar.xz |
src/stm.go: Rename AtomicGet => Deref and AtomicModify => Swap
-rw-r--r-- | src/stm.go | 6 | ||||
-rw-r--r-- | tests/stm.go | 8 |
2 files changed, 7 insertions, 7 deletions
@@ -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) diff --git a/tests/stm.go b/tests/stm.go index 816cdec..ab05d5c 100644 --- a/tests/stm.go +++ b/tests/stm.go @@ -83,10 +83,10 @@ func BenchmarkStdlibValueStore(b *testing.B) { } } -func BenchmarkAtomicGet(b *testing.B) { +func BenchmarkDeref(b *testing.B) { x := NewVar(0) for i := 0; i < b.N; i++ { - AtomicGet(x) + Deref(x) } } @@ -162,7 +162,7 @@ func BenchmarkReadVarSTM(b *testing.B) { x := NewVar(0) for i := 0; i < 1000; i++ { go func() { - AtomicGet(x) + Deref(x) wg.Done() }() } @@ -236,7 +236,7 @@ func Example() { v = n.Get(tx) })) // or: - v = AtomicGet(n) + v = Deref(n) _ = v // write to a variable |