mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-27 19:22:49 +01:00
Revert "audio: Bug fix: Make ensureReadLoop exactly atomic"
This reverts commit 835497edd3
.
Reason: This causes a dead lock at examples/piano with many notes.
This might be related to #855
This commit is contained in:
parent
fe3e8e376a
commit
89f6eba925
@ -370,23 +370,22 @@ func (p *playerImpl) ensureReadLoop() error {
|
|||||||
if p.closedExplicitly {
|
if p.closedExplicitly {
|
||||||
return fmt.Errorf("audio: the player is already closed")
|
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 {
|
if p.runningReadLoop {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
p.runningReadLoop = true
|
|
||||||
|
|
||||||
go p.readLoop()
|
go p.readLoop()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *playerImpl) closeImpl() error {
|
func (p *playerImpl) closeImpl() error {
|
||||||
p.m.Lock()
|
p.m.Lock()
|
||||||
defer p.m.Unlock()
|
r := p.runningReadLoop
|
||||||
p.playing = false
|
p.m.Unlock()
|
||||||
if !p.runningReadLoop {
|
if !r {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
p.runningReadLoop = false
|
|
||||||
|
|
||||||
p.closeCh <- struct{}{}
|
p.closeCh <- struct{}{}
|
||||||
<-p.closedCh
|
<-p.closedCh
|
||||||
@ -418,6 +417,15 @@ func (p *playerImpl) Play() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *playerImpl) readLoop() {
|
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)
|
timer := time.NewTimer(0)
|
||||||
timerCh := timer.C
|
timerCh := timer.C
|
||||||
var readErr error
|
var readErr error
|
||||||
|
Loading…
Reference in New Issue
Block a user