]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
fix a race condition in DP's sound handling; note: there may be more of them
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 1 Jun 2009 15:25:29 +0000 (15:25 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 1 Jun 2009 15:25:29 +0000 (15:25 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@9003 d7cf8633-e32d-0410-b094-e92efae38249

snd_main.c

index f2a6d5973f23356f4f0bc806db7e1e72064ca243..c327675ac686bf8ef96bd404ae633629af0dac63 100644 (file)
@@ -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();
 }