Revert "tmp"

This reverts commit 9619276326.

Reason: Wrong commit
This commit is contained in:
Hajime Hoshi 2021-05-28 19:49:59 +09:00
parent 9619276326
commit c2148dcc01

View File

@ -18,7 +18,6 @@ import (
"io" "io"
"runtime" "runtime"
"sync" "sync"
"sync/atomic"
"unsafe" "unsafe"
"golang.org/x/sys/windows" "golang.org/x/sys/windows"
@ -98,7 +97,7 @@ type players struct {
context *context context *context
players map[*playerImpl]struct{} players map[*playerImpl]struct{}
buf []byte buf []byte
err atomic.Value err error
waveOut uintptr waveOut uintptr
headers []*header headers []*header
@ -113,20 +112,20 @@ func (p *players) setContext(context *context) {
} }
func (p *players) add(player *playerImpl) error { func (p *players) add(player *playerImpl) error {
if err := p.err.Load(); err != nil {
return err.(error)
}
p.cond.L.Lock() p.cond.L.Lock()
defer p.cond.L.Unlock() defer p.cond.L.Unlock()
if p.err != nil {
return p.err
}
if p.players == nil { if p.players == nil {
p.players = map[*playerImpl]struct{}{} p.players = map[*playerImpl]struct{}{}
} }
p.players[player] = struct{}{} p.players[player] = struct{}{}
p.cond.Signal() p.cond.Signal()
if atomic.LoadUintptr(&p.waveOut) != 0 { if p.waveOut != 0 {
return nil return nil
} }
@ -151,10 +150,10 @@ func (p *players) add(player *playerImpl) error {
return err return err
} }
atomic.StoreUintptr(&p.waveOut, w) p.waveOut = w
p.headers = make([]*header, 0, 4) p.headers = make([]*header, 0, 4)
for len(p.headers) < cap(p.headers) { for len(p.headers) < cap(p.headers) {
h, err := newHeader(w, headerBufferSize) h, err := newHeader(p.waveOut, headerBufferSize)
if err != nil { if err != nil {
return err return err
} }
@ -177,15 +176,15 @@ func (p *players) remove(player *playerImpl) error {
} }
func (p *players) removeImpl(player *playerImpl) error { func (p *players) removeImpl(player *playerImpl) error {
if err := p.err.Load(); err != nil { if p.err != nil {
return err.(error) return p.err
} }
delete(p.players, player) delete(p.players, player)
return nil return nil
} }
func (p *players) shouldWait() bool { func (p *players) shouldWait() bool {
if atomic.LoadUintptr(&p.waveOut) == 0 { if p.waveOut == 0 {
return false return false
} }
@ -212,13 +211,13 @@ func (p *players) loop() {
for p.shouldWait() { for p.shouldWait() {
p.cond.Wait() p.cond.Wait()
} }
if atomic.LoadUintptr(&p.waveOut) == 0 { if p.waveOut == 0 {
p.cond.L.Unlock() p.cond.L.Unlock()
return return
} }
if err := p.readAndWriteBuffers(); err != nil { if err := p.readAndWriteBuffers(); err != nil {
p.err = err
p.cond.L.Unlock() p.cond.L.Unlock()
p.err.Store(err)
break break
} }
p.cond.L.Unlock() p.cond.L.Unlock()
@ -226,30 +225,26 @@ func (p *players) loop() {
} }
func (p *players) suspend() error { func (p *players) suspend() error {
waveOut := atomic.LoadUintptr(&p.waveOut)
if waveOut == 0 {
return nil
}
p.cond.L.Lock() p.cond.L.Lock()
defer p.cond.L.Unlock() defer p.cond.L.Unlock()
if err := waveOutPause(waveOut); err != nil { if p.waveOut == 0 {
return nil
}
if err := waveOutPause(p.waveOut); err != nil {
return err return err
} }
return nil return nil
} }
func (p *players) resume() error { func (p *players) resume() error {
waveOut := atomic.LoadUintptr(&p.waveOut)
if waveOut == 0 {
return nil
}
p.cond.L.Lock() p.cond.L.Lock()
defer p.cond.L.Unlock() defer p.cond.L.Unlock()
if err := waveOutRestart(waveOut); err != nil { if p.waveOut == 0 {
return nil
}
if err := waveOutRestart(p.waveOut); err != nil {
return err return err
} }
p.cond.Signal() p.cond.Signal()