diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/stm.go | 13 |
1 files changed, 13 insertions, 0 deletions
@@ -350,6 +350,11 @@ func Deref[T any](v *Var[T]) T { return v.value.Load().Get().(T) } +// AtomicGet is a helper function that atomically reads a value. +func (ref *AtomT[T]) Deref() T { + return ref.value.Load().Get().(T) +} + // AtomicSet is a helper function that atomically writes a value. func AtomicSet[T any](v *Var[T], val T) { v.mu.Lock() @@ -739,6 +744,14 @@ func NewVar[T any](val T) *Var[T] { return v } +type AtomT[T any] struct{ + *Var[T] +} + +func Atom[T any](x T) *AtomT[T] { + return &AtomT[T]{NewVar(x)} +} + func NewCustomVar[T any](val T, changed func(T, T) bool) *Var[T] { v := &Var[T]{} v.value.Store(customVarValue[T]{ |