diff options
Diffstat (limited to 'funcs.go')
-rw-r--r-- | funcs.go | 17 |
1 files changed, 5 insertions, 12 deletions
@@ -8,6 +8,7 @@ retry: reads: make(map[*Var]uint64), writes: make(map[*Var]interface{}), } + tx.cond.L = &globalLock var ret interface{} if func() (retry bool) { defer func() { @@ -37,10 +38,7 @@ retry: goto retry } // commit the write log and broadcast that variables have changed - if len(tx.writes) > 0 { - tx.commit() - globalCond.Broadcast() - } + tx.commit() globalLock.Unlock() return ret } @@ -58,14 +56,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 |