From c3edf31616f3ef8f770999eded6ee42ccf37f191 Mon Sep 17 00:00:00 2001 From: lukechampine Date: Wed, 30 Mar 2016 17:05:31 -0400 Subject: change Get/Set to AtomicGet/Set --- stm.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'stm.go') diff --git a/stm.go b/stm.go index 2960ac3..fcd1f02 100644 --- a/stm.go +++ b/stm.go @@ -213,18 +213,16 @@ retry: globalLock.Unlock() } -// Get is a helper transaction that reads a value. -func Get(v *Var, recv *interface{}) func(*Tx) { - return func(tx *Tx) { - *recv = tx.Get(v) - } +// AtomicGet is a helper function that atomically reads a value. +func AtomicGet(v *Var) interface{} { + var i interface{} + Atomically(func(tx *Tx) { i = tx.Get(v) }) + return i } -// Set is a helper transaction that writes a value. -func Set(v *Var, val interface{}) func(*Tx) { - return func(tx *Tx) { - tx.Set(v, val) - } +// AtomicSet is a helper function that atomically writes a value. +func AtomicSet(v *Var, val interface{}) { + Atomically(func(tx *Tx) { tx.Set(v, val) }) } // Compose is a helper function that composes multiple transactions into a -- cgit v1.2.3