diff options
Diffstat (limited to 'src/runtime/runtime.go')
-rw-r--r-- | src/runtime/runtime.go | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/runtime/runtime.go b/src/runtime/runtime.go index 0822d0e805..15119cf5df 100644 --- a/src/runtime/runtime.go +++ b/src/runtime/runtime.go @@ -101,12 +101,17 @@ func (g *godebugInc) IncNonDefault() { if newInc == nil { return } - // If other goroutines are racing here, no big deal. One will win, - // and all the inc functions will be using the same underlying - // *godebug.Setting. inc = new(func()) *inc = (*newInc)(g.name) - g.inc.Store(inc) + if raceenabled { + racereleasemerge(unsafe.Pointer(&g.inc)) + } + if !g.inc.CompareAndSwap(nil, inc) { + inc = g.inc.Load() + } + } + if raceenabled { + raceacquire(unsafe.Pointer(&g.inc)) } (*inc)() } |