From f21b1eefdae35eb3e0078e8783cb043b5543491a Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 10 Sep 2011 09:12:02 -0700 Subject: [PATCH] Lock the lists while probing devices --- Alc/ALc.c | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/Alc/ALc.c b/Alc/ALc.c index 03082f1f..0d8d39ea 100644 --- a/Alc/ALc.c +++ b/Alc/ALc.c @@ -701,17 +701,31 @@ static void alc_initconfig(void) } +static void LockLists(void) +{ + EnterCriticalSection(&ListLock); +} + +static void UnlockLists(void) +{ + LeaveCriticalSection(&ListLock); +} + + static void ProbeList(ALCchar **list, size_t *listsize, enum DevProbe type) { + DO_INITCONFIG(); + + LockLists(); free(*list); *list = NULL; *listsize = 0; - DO_INITCONFIG(); if(type == CAPTURE_DEVICE_PROBE) CaptureBackend.Probe(type); else PlaybackBackend.Probe(type); + UnlockLists(); } static void ProbeDeviceList(void) @@ -1001,17 +1015,6 @@ static ALCboolean IsValidALCChannels(ALCenum channels) return ALC_FALSE; } - -static void LockLists(void) -{ - EnterCriticalSection(&ListLock); -} - -static void UnlockLists(void) -{ - LeaveCriticalSection(&ListLock); -} - /* IsDevice * * Check if the device pointer is valid (caller is responsible for holding the @@ -1884,11 +1887,11 @@ ALC_API const ALCchar* ALC_APIENTRY alcGetString(ALCdevice *pDevice,ALCenum para /* Default devices are always first in the list */ case ALC_DEFAULT_DEVICE_SPECIFIER: - pDevice = VerifyDevice(pDevice); - if(!alcDeviceList) ProbeDeviceList(); + pDevice = VerifyDevice(pDevice); + free(alcDefaultDeviceSpecifier); alcDefaultDeviceSpecifier = strdup(alcDeviceList ? alcDeviceList : ""); if(!alcDefaultDeviceSpecifier) @@ -1899,11 +1902,11 @@ ALC_API const ALCchar* ALC_APIENTRY alcGetString(ALCdevice *pDevice,ALCenum para break; case ALC_DEFAULT_ALL_DEVICES_SPECIFIER: - pDevice = VerifyDevice(pDevice); - if(!alcAllDeviceList) ProbeAllDeviceList(); + pDevice = VerifyDevice(pDevice); + free(alcDefaultAllDeviceSpecifier); alcDefaultAllDeviceSpecifier = strdup(alcAllDeviceList ? alcAllDeviceList : ""); @@ -1915,11 +1918,11 @@ ALC_API const ALCchar* ALC_APIENTRY alcGetString(ALCdevice *pDevice,ALCenum para break; case ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER: - pDevice = VerifyDevice(pDevice); - if(!alcCaptureDeviceList) ProbeCaptureDeviceList(); + pDevice = VerifyDevice(pDevice); + free(alcCaptureDefaultDeviceSpecifier); alcCaptureDefaultDeviceSpecifier = strdup(alcCaptureDeviceList ? alcCaptureDeviceList : "");