aboutsummaryrefslogtreecommitdiff
path: root/tx.go
diff options
context:
space:
mode:
authorMatt Joiner <anacrolix@gmail.com>2019-10-31 19:07:45 +1100
committerMatt Joiner <anacrolix@gmail.com>2019-10-31 19:07:45 +1100
commit28b37142a55f8f105475ac4380b4e49f3a160e93 (patch)
tree1d1f813d25432712fc13128e7dcf4b56674eb5cd /tx.go
parentMerge branch 'master' into var-conds (diff)
downloadstm-28b37142a55f8f105475ac4380b4e49f3a160e93.tar.gz
stm-28b37142a55f8f105475ac4380b4e49f3a160e93.tar.xz
Optimize a bunch of stuff
Diffstat (limited to 'tx.go')
-rw-r--r--tx.go19
1 files changed, 17 insertions, 2 deletions
diff --git a/tx.go b/tx.go
index 5dd41ae..bae2006 100644
--- a/tx.go
+++ b/tx.go
@@ -24,16 +24,17 @@ func (tx *Tx) verify() bool {
return true
}
-// commit writes the values in the transaction log to their respective Vars.
+// Writes the values in the transaction log to their respective Vars.
func (tx *Tx) commit() {
for v, val := range tx.writes {
v.mu.Lock()
v.val = val
v.version++
+ v.mu.Unlock()
for tx := range v.watchers {
tx.cond.Broadcast()
+ delete(v.watchers, tx)
}
- v.mu.Unlock()
}
}
@@ -95,3 +96,17 @@ func (tx *Tx) Return(v interface{}) {
type _return struct {
value interface{}
}
+
+func (tx *Tx) reset() {
+ for k := range tx.reads {
+ delete(tx.reads, k)
+ }
+ for k := range tx.writes {
+ delete(tx.writes, k)
+ }
+}
+
+func (tx *Tx) recycle() {
+ tx.reset()
+ txPool.Put(tx)
+}