mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-12-25 03:00:46 +00:00
Add mutex to protect against S_Callback() being called from more than one thread at the same time
git-svn-id: https://svn.eduke32.com/eduke32@7310 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
bd55b2d573
commit
5882d9546c
1 changed files with 6 additions and 0 deletions
|
@ -38,6 +38,7 @@ static bool SoundPaused = false;
|
||||||
|
|
||||||
std::atomic<uint32_t> dnum;
|
std::atomic<uint32_t> dnum;
|
||||||
uint32_t dq[DQSIZE];
|
uint32_t dq[DQSIZE];
|
||||||
|
static mutex_t m_callback;
|
||||||
|
|
||||||
void S_SoundStartup(void)
|
void S_SoundStartup(void)
|
||||||
{
|
{
|
||||||
|
@ -78,6 +79,7 @@ void S_SoundStartup(void)
|
||||||
S_MusicVolume(ud.config.MusicVolume);
|
S_MusicVolume(ud.config.MusicVolume);
|
||||||
|
|
||||||
FX_SetReverseStereo(ud.config.ReverseStereo);
|
FX_SetReverseStereo(ud.config.ReverseStereo);
|
||||||
|
mutex_init(&m_callback);
|
||||||
FX_SetCallBack(S_Callback);
|
FX_SetCallBack(S_Callback);
|
||||||
FX_SetPrintf(OSD_Printf);
|
FX_SetPrintf(OSD_Printf);
|
||||||
}
|
}
|
||||||
|
@ -915,14 +917,18 @@ void S_Update(void)
|
||||||
} while (++sndnum <= highest);
|
} while (++sndnum <= highest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// S_Callback() can be called from either the audio thread when a sound ends, or the main thread
|
||||||
|
// when playing back a new sound needs an existing sound to be stopped first
|
||||||
void S_Callback(uint32_t num)
|
void S_Callback(uint32_t num)
|
||||||
{
|
{
|
||||||
if ((int32_t)num == MUSIC_ID)
|
if ((int32_t)num == MUSIC_ID)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
mutex_lock(&m_callback);
|
||||||
int const ldnum = dnum;
|
int const ldnum = dnum;
|
||||||
dq[ldnum & (DQSIZE - 1)] = num;
|
dq[ldnum & (DQSIZE - 1)] = num;
|
||||||
dnum++;
|
dnum++;
|
||||||
|
mutex_unlock(&m_callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
void S_ClearSoundLocks(void)
|
void S_ClearSoundLocks(void)
|
||||||
|
|
Loading…
Reference in a new issue