Skip to content

Commit

Permalink
- apply the ZMusic mutex a bit more finely grained.
Browse files Browse the repository at this point in the history
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 2d62608 commit d5ff274
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 7 additions & 1 deletion libraries/zmusic/musicformats/music_midi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}

//==========================================================================
Expand Down
4 changes: 0 additions & 4 deletions libraries/zmusic/zmusic/zmusic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down

0 comments on commit d5ff274

Please sign in to comment.