Fixing data race in count(..) method by passing sync.Map by pointer
This commit is contained in:
parent
077086ec59
commit
421eeb3750
|
@ -16,7 +16,7 @@ const maxStackLen = 1000
|
||||||
|
|
||||||
//NOTE: for simplicity not making it an atomic variable
|
//NOTE: for simplicity not making it an atomic variable
|
||||||
var enabled bool = false
|
var enabled bool = false
|
||||||
var res2track = sync.Map{}
|
var res2track = &sync.Map{}
|
||||||
|
|
||||||
type TrackedInfo struct {
|
type TrackedInfo struct {
|
||||||
Time time.Time
|
Time time.Time
|
||||||
|
@ -70,7 +70,7 @@ func Enable(flag bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Reset() {
|
func Reset() {
|
||||||
res2track = sync.Map{}
|
res2track = &sync.Map{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsOn() bool {
|
func IsOn() bool {
|
||||||
|
@ -81,7 +81,7 @@ func Count() int {
|
||||||
return count(res2track)
|
return count(res2track)
|
||||||
}
|
}
|
||||||
|
|
||||||
func count(m sync.Map) int {
|
func count(m *sync.Map) int {
|
||||||
var i int
|
var i int
|
||||||
m.Range(func(k, v interface{}) bool {
|
m.Range(func(k, v interface{}) bool {
|
||||||
i++
|
i++
|
||||||
|
|
Loading…
Reference in New Issue