Skip to content
Permalink
Browse files

- apply the ZMusic mutex a bit more finely grained.

It should only guard the critical parts, like calling Stop() but can let Update and IsPlaying method work unhindered otherwise.
  • Loading branch information...
coelckers committed Oct 20, 2019
1 parent f014e9c commit 0ee0034bebaadb2f93ba7f13be668d17ee551769
Showing with 7 additions and 5 deletions.
  1. +7 −1 libraries/zmusic/musicformats/music_midi.cpp
  2. +0 −4 libraries/zmusic/zmusic/zmusic.cpp
@@ -570,10 +570,12 @@ bool MIDIStreamer::IsPlaying()
{
if (m_Status != STATE_Stopped && (MIDI == NULL || (EndQueued != 0 && EndQueued < 4)))
{
std::lock_guard<std::mutex> lock(CritSec);
Stop();
}
if (m_Status != STATE_Stopped && !MIDI->IsOpen())
{
std::lock_guard<std::mutex> lock(CritSec);
Stop();
}
return m_Status != STATE_Stopped;
@@ -695,7 +697,11 @@ void MIDIStreamer::Callback(void *userdata)

void MIDIStreamer::Update()
{
if (MIDI != nullptr && !MIDI->Update()) Stop();
if (MIDI != nullptr && !MIDI->Update())
{
std::lock_guard<std::mutex> lock(CritSec);
Stop();
}
}

//==========================================================================
@@ -340,28 +340,24 @@ void ZMusic_Start(MusInfo *song, int subsong, bool loop)
void ZMusic_Pause(MusInfo *song)
{
if (!song) return;
std::lock_guard<std::mutex> lock(song->CritSec);
song->Pause();
}

void ZMusic_Resume(MusInfo *song)
{
if (!song) return;
std::lock_guard<std::mutex> lock(song->CritSec);
song->Resume();
}

void ZMusic_Update(MusInfo *song)
{
if (!song) return;
std::lock_guard<std::mutex> lock(song->CritSec);
song->Update();
}

bool ZMusic_IsPlaying(MusInfo *song)
{
if (!song) return false;
std::lock_guard<std::mutex> lock(song->CritSec);
return song->IsPlaying();
}

0 comments on commit 0ee0034

Please sign in to comment.
You can’t perform that action at this time.