Skip to content

Commit

Permalink
Allow creation of multiple contexts
Browse files Browse the repository at this point in the history
This is a dirty workaround for an issue of consuming CPU when Context is
idle, see: hajimehoshi/go-mp3#28
  • Loading branch information
dimonomid committed Feb 16, 2019
1 parent 0cf1e30 commit 54b968a
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ type Context struct {
}

var (
theContext *Context
contextM sync.Mutex
contextM sync.Mutex
)

var errClosed = errors.New("closed")
Expand All @@ -56,10 +55,6 @@ func NewContext(sampleRate, channelNum, bitDepthInBytes, bufferSizeInBytes int)
contextM.Lock()
defer contextM.Unlock()

if theContext != nil {
panic("oto: NewContext can be called only once")
}

d, err := newDriver(sampleRate, channelNum, bitDepthInBytes, bufferSizeInBytes)
if err != nil {
return nil, err
Expand All @@ -74,7 +69,6 @@ func NewContext(sampleRate, channelNum, bitDepthInBytes, bufferSizeInBytes int)
mux: mux.New(channelNum, bitDepthInBytes),
errCh: make(chan error),
}
theContext = c
go func() {
if _, err := io.Copy(c.driverWriter, c.mux); err != nil {
c.errCh <- err
Expand Down

0 comments on commit 54b968a

Please sign in to comment.