From: divverent Date: Mon, 1 Jun 2009 15:25:29 +0000 (+0000) Subject: fix a race condition in DP's sound handling; note: there may be more of them X-Git-Tag: xonotic-v0.1.0preview~1618 X-Git-Url: http://git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=commitdiff_plain;h=526e3243c94ca7e5e6f65fb0ddf62a21309f36fb fix a race condition in DP's sound handling; note: there may be more of them git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@9003 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/snd_main.c b/snd_main.c index f2a6d597..c327675a 100644 --- a/snd_main.c +++ b/snd_main.c @@ -1476,17 +1476,18 @@ void S_StopChannel (unsigned int channel_ind, qboolean lockmutex) if (channel_ind >= total_channels) return; + // we have to lock an audio mutex to prevent crashes if an audio mixer + // thread is currently mixing this channel + // the SndSys_LockRenderBuffer function uses such a mutex in + // threaded sound backends + if (lockmutex) + SndSys_LockRenderBuffer(); + ch = &channels[channel_ind]; if (ch->sfx != NULL) { sfx_t *sfx = ch->sfx; - // we have to lock an audio mutex to prevent crashes if an audio mixer - // thread is currently mixing this channel - // the SndSys_LockRenderBuffer function uses such a mutex in - // threaded sound backends - if (lockmutex) - SndSys_LockRenderBuffer(); if (sfx->fetcher != NULL) { snd_fetcher_endsb_t fetcher_endsb = sfx->fetcher->endsb; @@ -1499,9 +1500,9 @@ void S_StopChannel (unsigned int channel_ind, qboolean lockmutex) ch->fetcher_data = NULL; ch->sfx = NULL; - if (lockmutex) - SndSys_UnlockRenderBuffer(); } + if (lockmutex) + SndSys_UnlockRenderBuffer(); }