Commit 9311af79 authored by Bryan C. Mills's avatar Bryan C. Mills Committed by Bryan Mills

sync: release m.mu during (*RWMutexMap).Range callbacks in sync_test

The mainline sync.Map has allowed mutations within Range callbacks
since https://golang.org/cl/37342. The reference implementations need
to do the same.

This change integrates https://go-review.googlesource.com/c/42956/
from x/sync.

Change-Id: I6b58cf874bb31cd4f6fdb8bfa8278888ed617a5a
Reviewed-on: https://go-review.googlesource.com/42957
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent f5eb8712
......@@ -203,12 +203,10 @@ func BenchmarkAdversarialDelete(b *testing.B) {
m.Load(i)
if i%mapSize == 0 {
var key int
m.Range(func(k, _ interface{}) bool {
key = k.(int)
m.Delete(k)
return false
})
m.Delete(key)
m.Store(i, i)
}
}
......
......@@ -64,8 +64,17 @@ func (m *RWMutexMap) Delete(key interface{}) {
func (m *RWMutexMap) Range(f func(key, value interface{}) (shouldContinue bool)) {
m.mu.RLock()
defer m.mu.RUnlock()
for k, v := range m.dirty {
keys := make([]interface{}, 0, len(m.dirty))
for k := range m.dirty {
keys = append(keys, k)
}
m.mu.RUnlock()
for _, k := range keys {
v, ok := m.Load(k)
if !ok {
continue
}
if !f(k, v) {
break
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment