aboutsummaryrefslogtreecommitdiff
path: root/funcs.go
diff options
context:
space:
mode:
authorMatt Joiner <anacrolix@gmail.com>2019-10-23 18:27:11 +1100
committerMatt Joiner <anacrolix@gmail.com>2019-10-23 18:27:11 +1100
commit5d3a8dccf84bcdccb5e51eec11db732eb1911277 (patch)
tree3bb008720e99e1f6e0e8d5b53a4f6e7100a49ccb /funcs.go
parentImprove comment on Tx.verify (diff)
downloadstm-5d3a8dccf84bcdccb5e51eec11db732eb1911277.tar.gz
stm-5d3a8dccf84bcdccb5e51eec11db732eb1911277.tar.xz
Register transaction condition with each read Var only
Diffstat (limited to 'funcs.go')
-rw-r--r--funcs.go12
1 files changed, 4 insertions, 8 deletions
diff --git a/funcs.go b/funcs.go
index f87efb8..2170004 100644
--- a/funcs.go
+++ b/funcs.go
@@ -8,6 +8,7 @@ retry:
reads: make(map[*Var]uint64),
writes: make(map[*Var]interface{}),
}
+ tx.cond.L = &globalLock
if catchRetry(fn, tx) {
// wait for one of the variables we read to change before retrying
tx.wait()
@@ -40,14 +41,9 @@ func AtomicGet(v *Var) interface{} {
// AtomicSet is a helper function that atomically writes a value.
func AtomicSet(v *Var, val interface{}) {
- // since we're only doing one operation, we don't need a full transaction
- globalLock.Lock()
- v.mu.Lock()
- v.val = val
- v.version++
- v.mu.Unlock()
- globalCond.Broadcast()
- globalLock.Unlock()
+ Atomically(func(tx *Tx) {
+ tx.Set(v, val)
+ })
}
// Compose is a helper function that composes multiple transactions into a