audio/internal/readerdriver: Bug fix: Deadlock at Close (js)

This commit is contained in:
Hajime Hoshi 2021-05-10 01:10:42 +09:00
parent 2c8d3826fa
commit 7a6bdc8388

View File

@ -272,7 +272,10 @@ func (p *player) IsPlaying() bool {
func (p *player) Reset() { func (p *player) Reset() {
p.cond.L.Lock() p.cond.L.Lock()
defer p.cond.L.Unlock() defer p.cond.L.Unlock()
p.resetImpl()
}
func (p *player) resetImpl() {
if p.err != nil { if p.err != nil {
return return
} }
@ -312,14 +315,14 @@ func (p *player) Err() error {
} }
func (p *player) Close() error { func (p *player) Close() error {
runtime.SetFinalizer(p, nil)
p.cond.L.Lock() p.cond.L.Lock()
defer p.cond.L.Unlock() defer p.cond.L.Unlock()
return p.closeImpl() return p.closeImpl()
} }
func (p *player) closeImpl() error { func (p *player) closeImpl() error {
runtime.SetFinalizer(p, nil) p.resetImpl()
p.Reset()
p.state = playerClosed p.state = playerClosed
p.appendBufferFunc.Release() p.appendBufferFunc.Release()
p.cond.Signal() p.cond.Signal()