diff options
author | Matt Joiner <anacrolix@gmail.com> | 2022-06-14 08:59:02 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-14 08:59:02 +1000 |
commit | 4f6e80b7bb8c9a8b3036e54b6d02dcc66a690162 (patch) | |
tree | b4810cadfd0ce4a21963ccac5a051e9a50a91f4f /external_test.go | |
parent | Bump test timeout (#3) (diff) | |
parent | replace "interface{}" with "any" (diff) | |
download | stm-4f6e80b7bb8c9a8b3036e54b6d02dcc66a690162.tar.gz stm-4f6e80b7bb8c9a8b3036e54b6d02dcc66a690162.tar.xz |
Merge pull request #4 from chrismwendt/generics
Generics
Diffstat (limited to 'external_test.go')
-rw-r--r-- | external_test.go | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/external_test.go b/external_test.go index ae29ca8..abdf544 100644 --- a/external_test.go +++ b/external_test.go @@ -63,14 +63,14 @@ func BenchmarkThunderingHerd(b *testing.B) { pending := stm.NewBuiltinEqVar(0) for range iter.N(1000) { stm.Atomically(stm.VoidOperation(func(tx *stm.Tx) { - tx.Set(pending, tx.Get(pending).(int)+1) + pending.Set(tx, pending.Get(tx)+1) })) go func() { stm.Atomically(stm.VoidOperation(func(tx *stm.Tx) { - t := tx.Get(tokens).(int) + t := tokens.Get(tx) if t > 0 { - tx.Set(tokens, t-1) - tx.Set(pending, tx.Get(pending).(int)-1) + tokens.Set(tx, t-1) + pending.Set(tx, pending.Get(tx)-1) } else { tx.Retry() } @@ -78,18 +78,18 @@ func BenchmarkThunderingHerd(b *testing.B) { }() } go func() { - for stm.Atomically(func(tx *stm.Tx) interface{} { - if tx.Get(done).(bool) { + for stm.Atomically(func(tx *stm.Tx) bool { + if done.Get(tx) { return false } - tx.Assert(tx.Get(tokens).(int) < maxTokens) - tx.Set(tokens, tx.Get(tokens).(int)+1) + tx.Assert(tokens.Get(tx) < maxTokens) + tokens.Set(tx, tokens.Get(tx)+1) return true - }).(bool) { + }) { } }() stm.Atomically(stm.VoidOperation(func(tx *stm.Tx) { - tx.Assert(tx.Get(pending).(int) == 0) + tx.Assert(pending.Get(tx) == 0) })) stm.AtomicSet(done, true) } @@ -103,49 +103,49 @@ func BenchmarkInvertedThunderingHerd(b *testing.B) { for range iter.N(1000) { ready := stm.NewVar(false) stm.Atomically(stm.VoidOperation(func(tx *stm.Tx) { - tx.Set(pending, tx.Get(pending).(stmutil.Settish).Add(ready)) + pending.Set(tx, pending.Get(tx).Add(ready)) })) go func() { stm.Atomically(stm.VoidOperation(func(tx *stm.Tx) { - tx.Assert(tx.Get(ready).(bool)) - set := tx.Get(pending).(stmutil.Settish) + tx.Assert(ready.Get(tx)) + set := pending.Get(tx) if !set.Contains(ready) { panic("couldn't find ourselves in pending") } - tx.Set(pending, set.Delete(ready)) + pending.Set(tx, set.Delete(ready)) })) //b.Log("waiter finished") }() } go func() { - for stm.Atomically(func(tx *stm.Tx) interface{} { - if tx.Get(done).(bool) { + for stm.Atomically(func(tx *stm.Tx) bool { + if done.Get(tx) { return false } - tx.Assert(tx.Get(tokens).(int) < maxTokens) - tx.Set(tokens, tx.Get(tokens).(int)+1) + tx.Assert(tokens.Get(tx) < maxTokens) + tokens.Set(tx, tokens.Get(tx)+1) return true - }).(bool) { + }) { } }() go func() { - for stm.Atomically(func(tx *stm.Tx) interface{} { - tx.Assert(tx.Get(tokens).(int) > 0) - tx.Set(tokens, tx.Get(tokens).(int)-1) - tx.Get(pending).(stmutil.Settish).Range(func(i interface{}) bool { - ready := i.(*stm.Var) - if !tx.Get(ready).(bool) { - tx.Set(ready, true) + for stm.Atomically(func(tx *stm.Tx) bool { + tx.Assert(tokens.Get(tx) > 0) + tokens.Set(tx, tokens.Get(tx)-1) + pending.Get(tx).Range(func(i any) bool { + ready := i.(*stm.Var[bool]) + if !ready.Get(tx) { + ready.Set(tx, true) return false } return true }) - return !tx.Get(done).(bool) - }).(bool) { + return !done.Get(tx) + }) { } }() stm.Atomically(stm.VoidOperation(func(tx *stm.Tx) { - tx.Assert(tx.Get(pending).(stmutil.Lenner).Len() == 0) + tx.Assert(pending.Get(tx).(stmutil.Lenner).Len() == 0) })) stm.AtomicSet(done, true) } |