Protect context switches with a lock in the router
This commit is contained in:
@@ -420,16 +420,21 @@ ALC_API ALCboolean ALC_APIENTRY alcMakeContextCurrent(ALCcontext *context)
|
||||
{
|
||||
ALint idx = -1;
|
||||
|
||||
almtx_lock(&ContextSwitchLock);
|
||||
if(context)
|
||||
{
|
||||
idx = LookupPtrIntMapKey(&ContextIfaceMap, context);
|
||||
if(idx < 0)
|
||||
{
|
||||
ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_CONTEXT);
|
||||
almtx_unlock(&ContextSwitchLock);
|
||||
return ALC_FALSE;
|
||||
}
|
||||
if(!DriverList[idx].alcMakeContextCurrent(context))
|
||||
{
|
||||
almtx_unlock(&ContextSwitchLock);
|
||||
return ALC_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/* Unset the context from the old driver if it's different from the new
|
||||
@@ -446,6 +451,7 @@ ALC_API ALCboolean ALC_APIENTRY alcMakeContextCurrent(ALCcontext *context)
|
||||
if(oldiface && oldiface != &DriverList[idx])
|
||||
oldiface->alcMakeContextCurrent(NULL);
|
||||
}
|
||||
almtx_unlock(&ContextSwitchLock);
|
||||
|
||||
return ALC_TRUE;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ int DriverListSize = 0;
|
||||
static int DriverListSizeMax = 0;
|
||||
|
||||
almtx_t EnumerationLock;
|
||||
almtx_t ContextSwitchLock;
|
||||
|
||||
static void LoadDriverList(void);
|
||||
|
||||
@@ -29,6 +30,7 @@ BOOL APIENTRY DllMain(HINSTANCE UNUSED(module), DWORD reason, void* UNUSED(reser
|
||||
case DLL_PROCESS_ATTACH:
|
||||
LoadDriverList();
|
||||
almtx_init(&EnumerationLock, almtx_recursive);
|
||||
almtx_init(&ContextSwitchLock, almtx_plain);
|
||||
break;
|
||||
|
||||
case DLL_THREAD_ATTACH:
|
||||
@@ -37,6 +39,7 @@ BOOL APIENTRY DllMain(HINSTANCE UNUSED(module), DWORD reason, void* UNUSED(reser
|
||||
|
||||
case DLL_PROCESS_DETACH:
|
||||
ReleaseALC();
|
||||
almtx_destroy(&ContextSwitchLock);
|
||||
almtx_destroy(&EnumerationLock);
|
||||
for(i = 0;i < DriverListSize;i++)
|
||||
{
|
||||
|
||||
@@ -152,6 +152,7 @@ ALint LookupPtrIntMapKey(PtrIntMap *map, ALvoid *key);
|
||||
|
||||
|
||||
extern almtx_t EnumerationLock;
|
||||
extern almtx_t ContextSwitchLock;
|
||||
|
||||
void ReleaseALC(void);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user