audio/internal/readerdriver: Bug fix: Deadlock at resuming

This commit is contained in:
Hajime Hoshi 2021-05-09 18:30:46 +09:00
parent fa13b81d38
commit c85ef4e40b

View File

@ -259,15 +259,20 @@ func (p *players) suspend() error {
} }
func (p *players) resume() error { func (p *players) resume() error {
// playerImpl's Play can touch p. Avoid the deadlock.
p.m.Lock() p.m.Lock()
defer p.m.Unlock() players := map[*playerImpl]struct{}{}
for pl := range p.toResume { for pl := range p.toResume {
players[pl] = struct{}{}
delete(p.toResume, pl)
}
p.m.Unlock()
for pl := range players {
pl.Play() pl.Play()
if err := pl.Err(); err != nil { if err := pl.Err(); err != nil {
return err return err
} }
delete(p.toResume, pl)
} }
return nil return nil
} }