mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
audio: Bug fix: Make ensureReadLoop exactly atomic
This commit is contained in:
parent
b1607de99d
commit
835497edd3
@ -376,22 +376,22 @@ func (p *playerImpl) ensureReadLoop() error {
|
||||
if p.closedExplicitly {
|
||||
return fmt.Errorf("audio: the player is already closed")
|
||||
}
|
||||
// TODO: This is not exactly atomic: there is a little chance not to run the loop even though the current
|
||||
// loop is about to end. Fix this.
|
||||
if p.runningReadLoop {
|
||||
return nil
|
||||
}
|
||||
p.runningReadLoop = true
|
||||
|
||||
go p.readLoop()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *playerImpl) closeImpl() error {
|
||||
p.m.Lock()
|
||||
r := p.runningReadLoop
|
||||
p.m.Unlock()
|
||||
if !r {
|
||||
defer p.m.Unlock()
|
||||
if !p.runningReadLoop {
|
||||
return nil
|
||||
}
|
||||
p.runningReadLoop = false
|
||||
|
||||
p.closeCh <- struct{}{}
|
||||
<-p.closedCh
|
||||
@ -420,15 +420,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
|
||||
p.m.Unlock()
|
||||
}()
|
||||
|
||||
timer := time.NewTimer(0)
|
||||
timerCh := timer.C
|
||||
var readErr error
|
||||
|
Loading…
Reference in New Issue
Block a user