buffered: Bug fix: Corner case of the race condition

Updates #1195
This commit is contained in:
Hajime Hoshi 2020-06-17 03:31:34 +09:00
parent 0beddf5519
commit b620b4334e

View File

@ -67,14 +67,13 @@ func getDelayedFuncsAndClearSlow() []func() error {
func tryAddDelayedCommand(f func(obj interface{}) error, ondelayed func() interface{}) bool {
if atomic.LoadUint32(&delayedCommandsFlushed) == 0 {
// Outline the slow-path to expect the fast-path is inlined.
tryAddDelayedCommandSlow(f, ondelayed)
return true
return tryAddDelayedCommandSlow(f, ondelayed)
}
return false
}
func tryAddDelayedCommandSlow(f func(obj interface{}) error, ondelayed func() interface{}) {
func tryAddDelayedCommandSlow(f func(obj interface{}) error, ondelayed func() interface{}) bool {
delayedCommandsM.Lock()
defer delayedCommandsM.Unlock()
@ -86,7 +85,10 @@ func tryAddDelayedCommandSlow(f func(obj interface{}) error, ondelayed func() in
delayedCommands = append(delayedCommands, func() error {
return f(obj)
})
return true
}
return false
}
func checkDelayedCommandsFlushed(fname string) {