diff options
author | Matt Joiner <anacrolix@gmail.com> | 2020-09-04 15:44:51 +1000 |
---|---|---|
committer | Matt Joiner <anacrolix@gmail.com> | 2020-09-10 09:22:35 +1000 |
commit | 2a64b89bdbc8fec645dd688bd0322f45c067f295 (patch) | |
tree | 6e1e7d5606d3a16a77ccdd47eb8654296862acf7 /funcs.go | |
parent | Add exponentially longer sleeping between transaction attempts (diff) | |
download | stm-2a64b89bdbc8fec645dd688bd0322f45c067f295.tar.gz stm-2a64b89bdbc8fec645dd688bd0322f45c067f295.tar.xz |
Add custom VarValue and const for sleep backoff
Diffstat (limited to 'funcs.go')
-rw-r--r-- | funcs.go | 31 |
1 files changed, 18 insertions, 13 deletions
@@ -11,7 +11,7 @@ var ( txPool = sync.Pool{New: func() interface{} { expvars.Add("new txs", 1) tx := &Tx{ - reads: make(map[*Var]uint64), + reads: make(map[*Var]VarValue), writes: make(map[*Var]interface{}), watching: make(map[*Var]struct{}), } @@ -21,7 +21,10 @@ var ( failedCommitsProfile *pprof.Profile ) -const profileFailedCommits = false +const ( + profileFailedCommits = false + sleepBetweenRetries = false +) func init() { if profileFailedCommits { @@ -49,16 +52,18 @@ func Atomically(op Operation) interface{} { retry: tx.tries++ tx.reset() - shift := int64(tx.tries - 1) - const maxShift = 30 - if shift > maxShift { - shift = maxShift - } - ns := int64(1) << shift - ns = rand.Int63n(ns) - if ns > 0 { - tx.updateWatchers() - time.Sleep(time.Duration(ns)) + if sleepBetweenRetries { + shift := int64(tx.tries - 1) + const maxShift = 30 + if shift > maxShift { + shift = maxShift + } + ns := int64(1) << shift + ns = rand.Int63n(ns) + if ns > 0 { + tx.updateWatchers() + time.Sleep(time.Duration(ns)) + } } ret, retry := catchRetry(op, tx) if retry { @@ -87,7 +92,7 @@ retry: // AtomicGet is a helper function that atomically reads a value. func AtomicGet(v *Var) interface{} { - return v.loadState().val + return v.value.Load().(VarValue).Get() } // AtomicSet is a helper function that atomically writes a value. |