From f0be3413521fae09928f3089b4323834b34bbdad Mon Sep 17 00:00:00 2001 From: plagman Date: Mon, 11 Jan 2010 17:25:47 +0000 Subject: [PATCH] Fences access to common resources between the possible SDL_mixer effect thread and the rest of the audio code. git-svn-id: https://svn.eduke32.com/eduke32@1583 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/src/sdlayer.c | 2 +- .../eduke32/source/jaudiolib/src/driver_sdl.c | 21 ++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/polymer/eduke32/build/src/sdlayer.c b/polymer/eduke32/build/src/sdlayer.c index 82e9cd858..23d37a482 100644 --- a/polymer/eduke32/build/src/sdlayer.c +++ b/polymer/eduke32/build/src/sdlayer.c @@ -582,7 +582,7 @@ void grabmouse(char a) if (a != mouseacquired) { // #ifndef DEBUGGINGAIDS -#if 1 +#if 0 SDL_GrabMode g; g = SDL_WM_GrabInput(a ? SDL_GRAB_ON : SDL_GRAB_OFF); diff --git a/polymer/eduke32/source/jaudiolib/src/driver_sdl.c b/polymer/eduke32/source/jaudiolib/src/driver_sdl.c index 00cf4a062..82054ef38 100644 --- a/polymer/eduke32/source/jaudiolib/src/driver_sdl.c +++ b/polymer/eduke32/source/jaudiolib/src/driver_sdl.c @@ -25,6 +25,7 @@ #include #include +#include #include "driver_sdl.h" #ifndef UNREFERENCED_PARAMETER @@ -54,7 +55,8 @@ static void ( *MixCallBack )( void ) = 0; static Mix_Chunk *DummyChunk = NULL; static uint8_t *DummyBuffer = NULL; -// static int32_t InterruptsDisabled = 0; +static int32_t InterruptsDisabled = 0; +static SDL_mutex *EffectFence; static void fillData(int32_t chan, void *ptr, int32_t remaining, void *udata) { @@ -64,6 +66,8 @@ static void fillData(int32_t chan, void *ptr, int32_t remaining, void *udata) UNREFERENCED_PARAMETER(chan); UNREFERENCED_PARAMETER(udata); + SDL_LockMutex(EffectFence); + while (remaining > 0) { if (MixBufferUsed == MixBufferSize) { MixCallBack(); @@ -90,6 +94,8 @@ static void fillData(int32_t chan, void *ptr, int32_t remaining, void *udata) remaining -= len; } } + + SDL_UnlockMutex(EffectFence); } @@ -165,6 +171,8 @@ int32_t SDLDrv_PCM_Init(int32_t *mixrate, int32_t *numchannels, int32_t *sampleb //Mix_SetPostMix(fillData, NULL); + EffectFence = SDL_CreateMutex(); + // channel 0 and 1 are actual sounds // dummy channel 2 runs our fillData() callback as an effect Mix_RegisterEffect(2, fillData, NULL, NULL); @@ -200,6 +208,9 @@ void SDLDrv_PCM_Shutdown(void) } Mix_CloseAudio(); + + SDL_DestroyMutex(EffectFence); + Initialised = 0; } @@ -245,21 +256,17 @@ void SDLDrv_PCM_StopPlayback(void) void SDLDrv_PCM_Lock(void) { -/* if (InterruptsDisabled++) return; - SDL_LockAudio();*/ - + SDL_LockMutex(EffectFence); } void SDLDrv_PCM_Unlock(void) { -/* if (--InterruptsDisabled) return; - SDL_UnlockAudio();*/ - + SDL_UnlockMutex(EffectFence); }