diff options
author | Chris Robinson <[email protected]> | 2017-06-29 10:39:27 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2017-06-29 10:39:27 -0700 |
commit | 058d57ef0352ee0f46fc5e0ebe76479660bfc44e (patch) | |
tree | fbae1802299c979047e4fcf2ef2ccc3790e7b1f5 | |
parent | e8ce8924d179d515fe1439163b7ea73e895f408c (diff) |
Protect device enumeration in the router with a mutex
-rw-r--r-- | router/alc.c | 12 | ||||
-rw-r--r-- | router/router.c | 4 | ||||
-rw-r--r-- | router/router.h | 3 |
3 files changed, 19 insertions, 0 deletions
diff --git a/router/alc.c b/router/alc.c index 17ba7013..0fb9cf4e 100644 --- a/router/alc.c +++ b/router/alc.c @@ -345,6 +345,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *devicename) devicename = NULL; if(devicename) { + almtx_lock(&EnumerationLock); if(!DevicesList.Names) (void)alcGetString(NULL, ALC_DEVICE_SPECIFIER); idx = GetDriverIndexForName(&DevicesList, devicename); @@ -356,9 +357,11 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *devicename) if(idx < 0) { ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_VALUE); + almtx_unlock(&EnumerationLock); return NULL; } } + almtx_unlock(&EnumerationLock); } device = DriverList[idx].alcOpenDevice(devicename); @@ -624,6 +627,7 @@ ALC_API const ALCchar* ALC_APIENTRY alcGetString(ALCdevice *device, ALCenum para return alcExtensionList; case ALC_DEVICE_SPECIFIER: + almtx_lock(&EnumerationLock); ClearDeviceList(&DevicesList); for(i = 0;i < DriverListSize;i++) { @@ -634,9 +638,11 @@ ALC_API const ALCchar* ALC_APIENTRY alcGetString(ALCdevice *device, ALCenum para DriverList[i].alcGetString(NULL, ALC_DEVICE_SPECIFIER), i ); } + almtx_unlock(&EnumerationLock); return DevicesList.Names; case ALC_ALL_DEVICES_SPECIFIER: + almtx_lock(&EnumerationLock); ClearDeviceList(&AllDevicesList); for(i = 0;i < DriverListSize;i++) { @@ -653,9 +659,11 @@ ALC_API const ALCchar* ALC_APIENTRY alcGetString(ALCdevice *device, ALCenum para DriverList[i].alcGetString(NULL, ALC_DEVICE_SPECIFIER), i ); } + almtx_unlock(&EnumerationLock); return AllDevicesList.Names; case ALC_CAPTURE_DEVICE_SPECIFIER: + almtx_lock(&EnumerationLock); ClearDeviceList(&CaptureDevicesList); for(i = 0;i < DriverListSize;i++) { @@ -665,6 +673,7 @@ ALC_API const ALCchar* ALC_APIENTRY alcGetString(ALCdevice *device, ALCenum para DriverList[i].alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER), i ); } + almtx_unlock(&EnumerationLock); return CaptureDevicesList.Names; case ALC_DEFAULT_DEVICE_SPECIFIER: @@ -745,14 +754,17 @@ ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice(const ALCchar *devicename, devicename = NULL; if(devicename) { + almtx_lock(&EnumerationLock); if(!CaptureDevicesList.Names) (void)alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER); idx = GetDriverIndexForName(&CaptureDevicesList, devicename); if(idx < 0) { ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_VALUE); + almtx_unlock(&EnumerationLock); return NULL; } + almtx_unlock(&EnumerationLock); } device = DriverList[idx].alcCaptureOpenDevice(devicename, frequency, format, buffersize); diff --git a/router/router.c b/router/router.c index 86189b78..4dfae314 100644 --- a/router/router.c +++ b/router/router.c @@ -15,6 +15,8 @@ DriverIface *DriverList = NULL; int DriverListSize = 0; static int DriverListSizeMax = 0; +almtx_t EnumerationLock; + static void LoadDriverList(void); @@ -26,6 +28,7 @@ BOOL APIENTRY DllMain(HINSTANCE UNUSED(module), DWORD reason, void* UNUSED(reser { case DLL_PROCESS_ATTACH: LoadDriverList(); + almtx_init(&EnumerationLock, almtx_recursive); break; case DLL_THREAD_ATTACH: @@ -34,6 +37,7 @@ BOOL APIENTRY DllMain(HINSTANCE UNUSED(module), DWORD reason, void* UNUSED(reser case DLL_PROCESS_DETACH: ReleaseALC(); + almtx_destroy(&EnumerationLock); for(i = 0;i < DriverListSize;i++) { if(DriverList[i].Module) diff --git a/router/router.h b/router/router.h index 30401f88..78f7b6c0 100644 --- a/router/router.h +++ b/router/router.h @@ -9,6 +9,7 @@ #include "AL/al.h" #include "atomic.h" #include "rwlock.h" +#include "threads.h" #ifndef UNUSED @@ -150,6 +151,8 @@ ALint RemovePtrIntMapKey(PtrIntMap *map, ALvoid *key); ALint LookupPtrIntMapKey(PtrIntMap *map, ALvoid *key); +extern almtx_t EnumerationLock; + void ReleaseALC(void); #endif /* ROUTER_ROUTER_H */ |