Initialize ALC resources in the file they're used in

This commit is contained in:
Chris Robinson 2017-07-01 15:25:11 -07:00
parent 7daefd4e77
commit af626fdded
3 changed files with 15 additions and 10 deletions

View File

@ -241,6 +241,9 @@ static const ALCint alcMajorVersion = 1;
static const ALCint alcMinorVersion = 1; static const ALCint alcMinorVersion = 1;
static almtx_t EnumerationLock;
static almtx_t ContextSwitchLock;
static ATOMIC(ALCenum) LastError = ATOMIC_INIT_STATIC(ALC_NO_ERROR); static ATOMIC(ALCenum) LastError = ATOMIC_INIT_STATIC(ALC_NO_ERROR);
static PtrIntMap DeviceIfaceMap = PTRINTMAP_STATIC_INITIALIZE; static PtrIntMap DeviceIfaceMap = PTRINTMAP_STATIC_INITIALIZE;
static PtrIntMap ContextIfaceMap = PTRINTMAP_STATIC_INITIALIZE; static PtrIntMap ContextIfaceMap = PTRINTMAP_STATIC_INITIALIZE;
@ -320,6 +323,12 @@ static ALint GetDriverIndexForName(const EnumeratedList *list, const ALCchar *na
return -1; return -1;
} }
void InitALC(void)
{
almtx_init(&EnumerationLock, almtx_recursive);
almtx_init(&ContextSwitchLock, almtx_plain);
}
void ReleaseALC(void) void ReleaseALC(void)
{ {
ClearDeviceList(&DevicesList); ClearDeviceList(&DevicesList);
@ -328,6 +337,9 @@ void ReleaseALC(void)
ResetPtrIntMap(&ContextIfaceMap); ResetPtrIntMap(&ContextIfaceMap);
ResetPtrIntMap(&DeviceIfaceMap); ResetPtrIntMap(&DeviceIfaceMap);
almtx_destroy(&ContextSwitchLock);
almtx_destroy(&EnumerationLock);
} }

View File

@ -16,9 +16,6 @@ DriverIface *DriverList = NULL;
int DriverListSize = 0; int DriverListSize = 0;
static int DriverListSizeMax = 0; static int DriverListSizeMax = 0;
almtx_t EnumerationLock;
almtx_t ContextSwitchLock;
enum LogLevel LogLevel = LogLevel_Error; enum LogLevel LogLevel = LogLevel_Error;
FILE *LogFile; FILE *LogFile;
@ -56,8 +53,8 @@ BOOL APIENTRY DllMain(HINSTANCE UNUSED(module), DWORD reason, void* UNUSED(reser
LogLevel = l; LogLevel = l;
} }
LoadDriverList(); LoadDriverList();
almtx_init(&EnumerationLock, almtx_recursive);
almtx_init(&ContextSwitchLock, almtx_plain); InitALC();
break; break;
case DLL_THREAD_ATTACH: case DLL_THREAD_ATTACH:
@ -67,8 +64,6 @@ BOOL APIENTRY DllMain(HINSTANCE UNUSED(module), DWORD reason, void* UNUSED(reser
case DLL_PROCESS_DETACH: case DLL_PROCESS_DETACH:
ReleaseALC(); ReleaseALC();
almtx_destroy(&ContextSwitchLock);
almtx_destroy(&EnumerationLock);
for(i = 0;i < DriverListSize;i++) for(i = 0;i < DriverListSize;i++)
{ {
if(DriverList[i].Module) if(DriverList[i].Module)

View File

@ -153,9 +153,7 @@ ALint RemovePtrIntMapKey(PtrIntMap *map, ALvoid *key);
ALint LookupPtrIntMapKey(PtrIntMap *map, ALvoid *key); ALint LookupPtrIntMapKey(PtrIntMap *map, ALvoid *key);
extern almtx_t EnumerationLock; void InitALC(void);
extern almtx_t ContextSwitchLock;
void ReleaseALC(void); void ReleaseALC(void);