From bf1dcaa4b5238aee2c520dae1a6a32840c0d659b Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Thu, 1 Oct 2020 10:01:36 +1000 Subject: Tidy up newTx usage and recycle from WouldBlock --- funcs.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'funcs.go') diff --git a/funcs.go b/funcs.go index b8c8464..b418cd7 100644 --- a/funcs.go +++ b/funcs.go @@ -33,13 +33,19 @@ func init() { } func newTx() *Tx { - return txPool.Get().(*Tx) + tx := txPool.Get().(*Tx) + tx.tries = 0 + return tx } func WouldBlock(fn Operation) (block bool) { tx := newTx() tx.reset() _, block = catchRetry(fn, tx) + if len(tx.watching) != 0 { + panic("shouldn't have installed any watchers") + } + tx.recycle() return } @@ -48,7 +54,6 @@ func Atomically(op Operation) interface{} { expvars.Add("atomically", 1) // run the transaction tx := newTx() - tx.tries = 0 retry: tx.tries++ tx.reset() -- cgit v1.2.3