mirror of
https://github.com/golang/go
synced 2024-11-18 09:04:49 -07:00
expvar: don't recursively acquire Map.RLock
Fixes #7575 LGTM=iant R=dvyukov, iant CC=golang-codereviews https://golang.org/cl/77540044
This commit is contained in:
parent
d7039b71a9
commit
666f5b4a89
@ -108,7 +108,7 @@ func (v *Map) String() string {
|
||||
var b bytes.Buffer
|
||||
fmt.Fprintf(&b, "{")
|
||||
first := true
|
||||
v.Do(func(kv KeyValue) {
|
||||
v.doLocked(func(kv KeyValue) {
|
||||
if !first {
|
||||
fmt.Fprintf(&b, ", ")
|
||||
}
|
||||
@ -202,6 +202,12 @@ func (v *Map) AddFloat(key string, delta float64) {
|
||||
func (v *Map) Do(f func(KeyValue)) {
|
||||
v.mu.RLock()
|
||||
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 {
|
||||
f(KeyValue{k, v.m[k]})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user