audio: Bug fix: runningReadLoop must be set to true before starting the goroutine

This can cause deadlock by multiple goroutines if runningReadLoop
is set to true in the goroutine.

Related to #855?
This commit is contained in:
Hajime Hoshi 2019-04-29 21:43:48 +09:00
parent 89f6eba925
commit d2979e288d

View File

@ -375,6 +375,7 @@ func (p *playerImpl) ensureReadLoop() error {
if p.runningReadLoop {
return nil
}
p.runningReadLoop = true
go p.readLoop()
return nil
}
@ -417,9 +418,6 @@ func (p *playerImpl) Play() {
}
func (p *playerImpl) readLoop() {
p.m.Lock()
p.runningReadLoop = true
p.m.Unlock()
defer func() {
p.m.Lock()
p.runningReadLoop = false