From bed264ad776f9e27390394a8e62a4e0a9b39b382 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Wed, 6 Jul 2011 02:58:43 -0700 Subject: Use a Lock/UnlockDevice function instead of locking a NULL context --- Alc/ALc.c | 30 +++++++++++++++++++++--------- Alc/ALu.c | 8 ++++---- Alc/pulseaudio.c | 4 ++-- OpenAL32/Include/alMain.h | 2 ++ 4 files changed, 29 insertions(+), 15 deletions(-) diff --git a/Alc/ALc.c b/Alc/ALc.c index b0842819..fd4a8790 100644 --- a/Alc/ALc.c +++ b/Alc/ALc.c @@ -1328,10 +1328,10 @@ static ALCboolean UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) if((device->Flags&DEVICE_RUNNING)) return ALC_TRUE; - LockContext(NULL); + LockDevice(device); if(ALCdevice_ResetPlayback(device) == ALC_FALSE) { - UnlockContext(NULL); + UnlockDevice(device); return ALC_FALSE; } device->Flags |= DEVICE_RUNNING; @@ -1395,7 +1395,7 @@ static ALCboolean UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) if(ALEffect_DeviceUpdate(slot->EffectState, device) == AL_FALSE) { - UnlockContext(NULL); + UnlockDevice(device); ALCdevice_StopPlayback(device); device->Flags &= ~DEVICE_RUNNING; return ALC_FALSE; @@ -1420,12 +1420,24 @@ static ALCboolean UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) source->NeedsUpdate = AL_FALSE; } } - UnlockContext(NULL); + UnlockDevice(device); return ALC_TRUE; } +ALCvoid LockDevice(ALCdevice *device) +{ + (void)device; + EnterCriticalSection(&g_csMutex); +} + +ALCvoid UnlockDevice(ALCdevice *device) +{ + (void)device; + LeaveCriticalSection(&g_csMutex); +} + /* LockContext @@ -2134,7 +2146,7 @@ ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCin return NULL; } - LockContext(NULL); + LockDevice(device); ALContext = NULL; temp = realloc(device->Contexts, (device->NumContexts+1) * sizeof(*device->Contexts)); if(temp) @@ -2153,7 +2165,7 @@ ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCin { free(ALContext); alcSetError(device, ALC_OUT_OF_MEMORY); - UnlockContext(NULL); + UnlockDevice(device); if(device->NumContexts == 0) { ALCdevice_StopPlayback(device); @@ -2167,7 +2179,7 @@ ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCin ALContext->Device = device; InitContext(ALContext); - UnlockContext(NULL); + UnlockDevice(device); ALContext->next = g_pContextList; g_pContextList = ALContext; @@ -2211,7 +2223,7 @@ ALC_API ALCvoid ALC_APIENTRY alcDestroyContext(ALCcontext *context) GlobalContext = NULL; Device = context->Device; - LockContext(NULL); + LockDevice(Device); for(i = 0;i < Device->NumContexts;i++) { if(Device->Contexts[i] == context) @@ -2221,7 +2233,7 @@ ALC_API ALCvoid ALC_APIENTRY alcDestroyContext(ALCcontext *context) break; } } - UnlockContext(NULL); + UnlockDevice(Device); if(Device->NumContexts == 0) { diff --git a/Alc/ALu.c b/Alc/ALu.c index 49e957b8..c2a2c5ea 100644 --- a/Alc/ALu.c +++ b/Alc/ALu.c @@ -984,7 +984,7 @@ ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size) /* Clear mixing buffer */ memset(device->DryBuffer, 0, SamplesToDo*MAXCHANNELS*sizeof(ALfloat)); - LockContext(NULL); + LockDevice(device); ctx = device->Contexts; ctx_end = ctx + device->NumContexts; while(ctx != ctx_end) @@ -1036,7 +1036,7 @@ ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size) ctx++; } - UnlockContext(NULL); + UnlockDevice(device); //Post processing loop for(i = 0;i < SamplesToDo;i++) @@ -1087,7 +1087,7 @@ ALvoid aluHandleDisconnect(ALCdevice *device) { ALuint i; - LockContext(NULL); + LockDevice(device); for(i = 0;i < device->NumContexts;i++) { ALCcontext *Context = device->Contexts[i]; @@ -1108,5 +1108,5 @@ ALvoid aluHandleDisconnect(ALCdevice *device) } device->Connected = ALC_FALSE; - UnlockContext(NULL); + UnlockDevice(device); } diff --git a/Alc/pulseaudio.c b/Alc/pulseaudio.c index 1a4789b3..2f8c8ee0 100644 --- a/Alc/pulseaudio.c +++ b/Alc/pulseaudio.c @@ -361,7 +361,7 @@ static void stream_buffer_attr_callback(pa_stream *stream, void *pdata) //{{{ ALCdevice *Device = pdata; pulse_data *data = Device->ExtraData; - LockContext(NULL); + LockDevice(Device); data->attr = *(pa_stream_get_buffer_attr(stream)); Device->UpdateSize = data->attr.minreq / data->frame_size; @@ -372,7 +372,7 @@ static void stream_buffer_attr_callback(pa_stream *stream, void *pdata) //{{{ AL_PRINT("PulseAudio returned minreq > tlength/2; expect break up\n"); } - UnlockContext(NULL); + UnlockDevice(Device); }//}}} static void stream_device_callback(pa_stream *stream, void *pdata) //{{{ diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index 1fb75e18..f58da036 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -487,6 +487,8 @@ void AppendCaptureDeviceList(const ALCchar *name); ALCvoid alcSetError(ALCdevice *device, ALenum errorCode); +ALCvoid LockDevice(ALCdevice *device); +ALCvoid UnlockDevice(ALCdevice *device); ALCvoid LockContext(ALCcontext *context); ALCvoid UnlockContext(ALCcontext *context); -- cgit v1.2.3