Skip to content

Commit b68f3d2

Browse files
committed
oto: use mutex for Oboe APIs
Updates hajimehoshi/ebiten#3260
1 parent 5de9c71 commit b68f3d2

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

driver_android.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
package oto
1616

1717
import (
18+
"sync"
19+
1820
"github.com/ebitengine/oto/v3/internal/mux"
1921
"github.com/ebitengine/oto/v3/internal/oboe"
2022
)
@@ -23,6 +25,8 @@ type context struct {
2325
mux *mux.Mux
2426

2527
err atomicError
28+
29+
m sync.Mutex
2630
}
2731

2832
func newContext(sampleRate int, channelCount int, format mux.Format, bufferSizeInBytes int, _ string) (*context, chan struct{}, error) {
@@ -32,6 +36,9 @@ func newContext(sampleRate int, channelCount int, format mux.Format, bufferSizeI
3236
mux: mux.New(sampleRate, channelCount, format),
3337
}
3438
go func() {
39+
c.m.Lock()
40+
defer c.m.Unlock()
41+
3542
if err := oboe.Play(sampleRate, channelCount, c.mux.ReadFloat32s, bufferSizeInBytes); err != nil {
3643
c.err.TryStore(err)
3744
return
@@ -42,10 +49,14 @@ func newContext(sampleRate int, channelCount int, format mux.Format, bufferSizeI
4249
}
4350

4451
func (c *context) Suspend() error {
52+
c.m.Lock()
53+
defer c.m.Unlock()
4554
return oboe.Suspend()
4655
}
4756

4857
func (c *context) Resume() error {
58+
c.m.Lock()
59+
defer c.m.Unlock()
4960
return oboe.Resume()
5061
}
5162

0 commit comments

Comments
 (0)