aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--funcs.go2
-rw-r--r--var.go11
2 files changed, 10 insertions, 3 deletions
diff --git a/funcs.go b/funcs.go
index b7a2c29..59c0e74 100644
--- a/funcs.go
+++ b/funcs.go
@@ -23,7 +23,7 @@ var (
const (
profileFailedCommits = false
- sleepBetweenRetries = true
+ sleepBetweenRetries = false
)
func init() {
diff --git a/var.go b/var.go
index cdf9667..7e50cac 100644
--- a/var.go
+++ b/var.go
@@ -13,13 +13,20 @@ type Var struct {
}
func (v *Var) changeValue(new interface{}) {
- v.value.Store(v.value.Load().(VarValue).Set(new))
- v.wakeWatchers()
+ old := v.value.Load().(VarValue)
+ newVarValue := old.Set(new)
+ v.value.Store(newVarValue)
+ if old.Changed(newVarValue) {
+ v.wakeWatchers()
+ }
}
func (v *Var) wakeWatchers() {
v.watchers.Range(func(k, _ interface{}) bool {
tx := k.(*Tx)
+
+ // We have to lock here to ensure that the Tx is waiting before we signal it. Otherwise we
+ // could signal it before it goes to sleep and it will miss the notification.
tx.mu.Lock()
tx.cond.Broadcast()
tx.mu.Unlock()