From d5ff2746be69636ed17c197877407ee2ad12b8f7 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 20 Oct 2019 16:16:08 +0200 Subject: [PATCH] - 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. --- libraries/zmusic/musicformats/music_midi.cpp | 8 +++++++- libraries/zmusic/zmusic/zmusic.cpp | 4 ---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/libraries/zmusic/musicformats/music_midi.cpp b/libraries/zmusic/musicformats/music_midi.cpp index c76b13e4d13..614081e8944 100644 --- a/libraries/zmusic/musicformats/music_midi.cpp +++ b/libraries/zmusic/musicformats/music_midi.cpp @@ -570,10 +570,12 @@ bool MIDIStreamer::IsPlaying() { if (m_Status != STATE_Stopped && (MIDI == NULL || (EndQueued != 0 && EndQueued < 4))) { + std::lock_guard lock(CritSec); Stop(); } if (m_Status != STATE_Stopped && !MIDI->IsOpen()) { + std::lock_guard 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 lock(CritSec); + Stop(); + } } //========================================================================== diff --git a/libraries/zmusic/zmusic/zmusic.cpp b/libraries/zmusic/zmusic/zmusic.cpp index 50eb781633e..7d6b18f8a30 100644 --- a/libraries/zmusic/zmusic/zmusic.cpp +++ b/libraries/zmusic/zmusic/zmusic.cpp @@ -340,28 +340,24 @@ void ZMusic_Start(MusInfo *song, int subsong, bool loop) void ZMusic_Pause(MusInfo *song) { if (!song) return; - std::lock_guard lock(song->CritSec); song->Pause(); } void ZMusic_Resume(MusInfo *song) { if (!song) return; - std::lock_guard lock(song->CritSec); song->Resume(); } void ZMusic_Update(MusInfo *song) { if (!song) return; - std::lock_guard lock(song->CritSec); song->Update(); } bool ZMusic_IsPlaying(MusInfo *song) { if (!song) return false; - std::lock_guard lock(song->CritSec); return song->IsPlaying(); }