audio/internal/go2cpp: Bug fix: Potential deadlock at Play

Closes #1629
This commit is contained in:
Hajime Hoshi 2021-05-03 17:54:22 +09:00
parent bea5ab3335
commit fc5970768d

View File

@ -138,7 +138,7 @@ func (p *Player) Play() {
} }
n, err := p.src.Read(p.buf) n, err := p.src.Read(p.buf)
if err != nil && err != io.EOF { if err != nil && err != io.EOF {
p.setError(err) p.setErrorImpl(err)
return return
} }
if n > 0 { if n > 0 {
@ -243,7 +243,10 @@ func (p *Player) close(remove bool) error {
func (p *Player) setError(err error) { func (p *Player) setError(err error) {
p.cond.L.Lock() p.cond.L.Lock()
defer p.cond.L.Unlock() defer p.cond.L.Unlock()
p.setErrorImpl(err)
}
func (p *Player) setErrorImpl(err error) {
if p.state != playerStateClosed && p.v.Truthy() { if p.state != playerStateClosed && p.v.Truthy() {
p.v.Call("close", true) p.v.Call("close", true)
p.v = js.Undefined() p.v = js.Undefined()