From 421eeb37508b47d27260ae32c63d4a92def59801 Mon Sep 17 00:00:00 2001 From: Pavel Shevaev Date: Fri, 14 Oct 2022 14:59:16 +0300 Subject: [PATCH] Fixing data race in count(..) method by passing sync.Map by pointer --- res_tracker.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/res_tracker.go b/res_tracker.go index ceb15b9..c10268b 100644 --- a/res_tracker.go +++ b/res_tracker.go @@ -16,7 +16,7 @@ const maxStackLen = 1000 //NOTE: for simplicity not making it an atomic variable var enabled bool = false -var res2track = sync.Map{} +var res2track = &sync.Map{} type TrackedInfo struct { Time time.Time @@ -70,7 +70,7 @@ func Enable(flag bool) { } func Reset() { - res2track = sync.Map{} + res2track = &sync.Map{} } func IsOn() bool { @@ -81,7 +81,7 @@ func Count() int { return count(res2track) } -func count(m sync.Map) int { +func count(m *sync.Map) int { var i int m.Range(func(k, v interface{}) bool { i++