Commit 666f5b4a authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

expvar: don't recursively acquire Map.RLock

Fixes #7575

LGTM=iant
R=dvyukov, iant
CC=golang-codereviews
https://golang.org/cl/77540044
parent d7039b71
...@@ -108,7 +108,7 @@ func (v *Map) String() string { ...@@ -108,7 +108,7 @@ func (v *Map) String() string {
var b bytes.Buffer var b bytes.Buffer
fmt.Fprintf(&b, "{") fmt.Fprintf(&b, "{")
first := true first := true
v.Do(func(kv KeyValue) { v.doLocked(func(kv KeyValue) {
if !first { if !first {
fmt.Fprintf(&b, ", ") fmt.Fprintf(&b, ", ")
} }
...@@ -202,6 +202,12 @@ func (v *Map) AddFloat(key string, delta float64) { ...@@ -202,6 +202,12 @@ func (v *Map) AddFloat(key string, delta float64) {
func (v *Map) Do(f func(KeyValue)) { func (v *Map) Do(f func(KeyValue)) {
v.mu.RLock() v.mu.RLock()
defer v.mu.RUnlock() defer v.mu.RUnlock()
v.doLocked(f)
}
// doRLocked calls f for each entry in the map.
// v.mu must be held for reads.
func (v *Map) doLocked(f func(KeyValue)) {
for _, k := range v.keys { for _, k := range v.keys {
f(KeyValue{k, v.m[k]}) f(KeyValue{k, v.m[k]})
} }
......
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