diff options
author | Chris Robinson <[email protected]> | 2011-03-12 06:23:17 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2011-03-12 06:23:17 -0800 |
commit | 66ee3bc21757c71aaa6af7f872a8db9eda0b5be2 (patch) | |
tree | 807d4a6b9891758bb073edaf6190dd7197c8d2da /Alc | |
parent | 031a2a1b1e37a198c64f49ac8994d4c589dabcf9 (diff) |
Better protect the device for multi-threading access
Diffstat (limited to 'Alc')
-rw-r--r-- | Alc/ALc.c | 68 |
1 files changed, 33 insertions, 35 deletions
@@ -1854,7 +1854,6 @@ ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCin void *temp; SuspendContext(NULL); - if(!IsDevice(device) || device->IsCaptureDevice || !device->Connected) { alcSetError(device, ALC_INVALID_DEVICE); @@ -1924,18 +1923,28 @@ ALC_API ALCvoid ALC_APIENTRY alcDestroyContext(ALCcontext *context) ALCcontext **list; ALuint i; + SuspendContext(NULL); if(!IsContext(context)) { alcSetError(NULL, ALC_INVALID_CONTEXT); + ProcessContext(NULL); return; } - Device = context->Device; + list = &g_pContextList; + while(*list != context) + list = &(*list)->next; + + *list = (*list)->next; + g_ulContextCount--; + Device = context->Device; if(Device->NumContexts == 1) + { + ProcessContext(NULL); ALCdevice_StopPlayback(Device); - - SuspendContext(NULL); + SuspendContext(NULL); + } if(context == GlobalContext) GlobalContext = NULL; @@ -1976,13 +1985,6 @@ ALC_API ALCvoid ALC_APIENTRY alcDestroyContext(ALCcontext *context) context->MaxActiveSources = 0; context->ActiveSourceCount = 0; - list = &g_pContextList; - while(*list != context) - list = &(*list)->next; - - *list = (*list)->next; - g_ulContextCount--; - // Unlock context ProcessContext(context); ProcessContext(NULL); @@ -2336,14 +2338,14 @@ ALC_API ALCboolean ALC_APIENTRY alcCloseDevice(ALCdevice *pDevice) { ALCdevice **list; + SuspendContext(NULL); if(!IsDevice(pDevice) || pDevice->IsCaptureDevice) { alcSetError(pDevice, ALC_INVALID_DEVICE); + ProcessContext(NULL); return ALC_FALSE; } - SuspendContext(NULL); - list = &g_pDeviceList; while(*list != pDevice) list = &(*list)->next; @@ -2488,33 +2490,29 @@ ALC_API ALCdevice* ALC_APIENTRY alcLoopbackOpenDevice(void) ALC_API ALCboolean ALC_APIENTRY alcIsRenderFormatSupported(ALCdevice *device, ALCsizei freq, ALenum channels, ALenum type) { + ALCboolean ret = ALC_FALSE; + + SuspendContext(NULL); if(!IsDevice(device) || !device->IsLoopbackDevice) - { alcSetError(device, ALC_INVALID_DEVICE); - return ALC_FALSE; - } - - if(freq < 8000) - { - if(freq <= 0) - alcSetError(device, ALC_INVALID_VALUE); - return ALC_FALSE; - } - - if(IsValidType(type) == AL_FALSE || IsValidChannels(channels) == AL_FALSE) - { + else if(freq <= 0) + alcSetError(device, ALC_INVALID_VALUE); + else if(IsValidType(type) == AL_FALSE || + IsValidChannels(channels) == AL_FALSE) alcSetError(device, ALC_INVALID_ENUM); - return ALC_FALSE; + else + { + if((type == DevFmtByte || type == DevFmtUByte || type == DevFmtShort || + type == DevFmtUShort || type == DevFmtFloat) && + (channels == DevFmtMono || channels == DevFmtStereo || + channels == DevFmtQuad || channels == DevFmtX51 || + channels == DevFmtX61 || channels == DevFmtX71) && + freq >= 8000) + ret = ALC_TRUE; } + ProcessContext(NULL); - if((type == DevFmtByte || type == DevFmtUByte || type == DevFmtShort || - type == DevFmtUShort || type == DevFmtFloat) && - (channels == DevFmtMono || channels == DevFmtStereo || - channels == DevFmtQuad || channels == DevFmtX51 || - channels == DevFmtX61 || channels == DevFmtX71)) - return ALC_TRUE; - - return ALC_FALSE; + return ret; } ALC_API void ALC_APIENTRY alcRenderSamples(ALCdevice *device, ALCvoid *buffer, ALCsizei samples) |