From 36366c0c9861a844100f199f3ffd6e4bc0ed307f Mon Sep 17 00:00:00 2001 From: terminx Date: Fri, 9 Aug 2019 09:28:42 +0000 Subject: [PATCH] M-M-M-MUTEX MADNESS git-svn-id: https://svn.eduke32.com/eduke32@7937 1a8010ca-5511-0410-912e-c29ae57300e0 --- source/audiolib/src/multivoc.cpp | 4 ++-- source/duke3d/src/sounds.cpp | 21 ++++++++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/source/audiolib/src/multivoc.cpp b/source/audiolib/src/multivoc.cpp index 9c0dacee0..dc1dba62e 100644 --- a/source/audiolib/src/multivoc.cpp +++ b/source/audiolib/src/multivoc.cpp @@ -101,7 +101,7 @@ static inline void MV_Unlock(void) if (!--lockdepth) SoundDriver_Unlock(); else if (lockdepth < 0 && MV_Printf) - MV_Printf("RestoreInterrupts(): lockdepth < 0!\n"); + MV_Printf("MV_Unlock(): lockdepth < 0!\n"); } static bool MV_Mix(VoiceNode * const voice, int const buffer) @@ -198,8 +198,8 @@ static void MV_CleanupVoice(VoiceNode *voice) static void MV_StopVoice(VoiceNode *voice) { - MV_Lock(); MV_CleanupVoice(voice); + MV_Lock(); // move the voice from the play list to the free list LL::Move(voice, &VoicePool); MV_Unlock(); diff --git a/source/duke3d/src/sounds.cpp b/source/duke3d/src/sounds.cpp index 72c118e7d..fb64d8b7e 100644 --- a/source/duke3d/src/sounds.cpp +++ b/source/duke3d/src/sounds.cpp @@ -40,8 +40,8 @@ static int32_t MusicVoice = -1; static bool MusicPaused; static bool SoundPaused; -std::atomic dnum, dq[DQSIZE]; -// static mutex_t m_callback; +static std::atomic dnum, dq[DQSIZE]; +static mutex_t m_callback; static inline void S_SetProperties(assvoice_t *snd, int const owner, int const voice, int const dist, int const clock) { @@ -89,9 +89,9 @@ void S_SoundStartup(void) S_MusicVolume(ud.config.MusicVolume); FX_SetReverseStereo(ud.config.ReverseStereo); - // mutex_init(&m_callback); FX_SetCallBack(S_Callback); FX_SetPrintf(OSD_Printf); + mutex_init(&m_callback); } void S_SoundShutdown(void) @@ -523,7 +523,12 @@ static int S_TakeSlot(int soundNum) if (FX_SoundActive(snd.voices[bestslot].id)) FX_StopSound(snd.voices[bestslot].id); - dq[dnum++ & (DQSIZE-1)] = (soundNum * MAXSOUNDINSTANCES) + bestslot; + mutex_lock(&m_callback); + unative_t const ldnum = dnum; + dq[ldnum & (DQSIZE-1)] = (soundNum * MAXSOUNDINSTANCES) + bestslot; + dnum++; + mutex_unlock(&m_callback); + S_Cleanup(); return bestslot; @@ -966,9 +971,11 @@ void S_Callback(intptr_t num) if (num == MUSIC_ID) return; -// mutex_lock(&m_callback); - dq[dnum++ & (DQSIZE - 1)] = num; -// mutex_unlock(&m_callback); + mutex_lock(&m_callback); + unative_t const ldnum = dnum; + dq[ldnum & (DQSIZE - 1)] = num; + dnum++; + mutex_unlock(&m_callback); } void S_ClearSoundLocks(void)