audio: Bug fix: nosync might cause unexpected panics because of runtime.Gosched

This commit is contained in:
Hajime Hoshi 2017-06-04 03:42:26 +09:00
parent 873b3905df
commit cf452bb709

View File

@ -31,10 +31,10 @@ import (
"errors" "errors"
"io" "io"
"runtime" "runtime"
"sync"
"time" "time"
"github.com/hajimehoshi/ebiten" "github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/internal/sync"
"github.com/hajimehoshi/oto" "github.com/hajimehoshi/oto"
) )
@ -118,32 +118,32 @@ func (p *players) Read(b []byte) (int, error) {
func (p *players) addPlayer(player *Player) { func (p *players) addPlayer(player *Player) {
p.Lock() p.Lock()
defer p.Unlock()
p.players[player] = struct{}{} p.players[player] = struct{}{}
p.Unlock()
} }
func (p *players) removePlayer(player *Player) { func (p *players) removePlayer(player *Player) {
p.Lock() p.Lock()
defer p.Unlock()
delete(p.players, player) delete(p.players, player)
p.Unlock()
} }
func (p *players) addSeeking(player *Player) { func (p *players) addSeeking(player *Player) {
p.Lock() p.Lock()
defer p.Unlock()
p.seekings[player] = struct{}{} p.seekings[player] = struct{}{}
p.Unlock()
} }
func (p *players) removeSeeking(player *Player) { func (p *players) removeSeeking(player *Player) {
p.Lock() p.Lock()
defer p.Unlock()
delete(p.seekings, player) delete(p.seekings, player)
p.Unlock()
} }
func (p *players) hasPlayer(player *Player) bool { func (p *players) hasPlayer(player *Player) bool {
p.RLock() p.RLock()
defer p.RUnlock()
_, ok := p.players[player] _, ok := p.players[player]
p.RUnlock()
return ok return ok
} }