aboutsummaryrefslogtreecommitdiffstats
path: root/Alc
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2011-06-14 09:43:33 -0700
committerChris Robinson <[email protected]>2011-06-14 09:43:33 -0700
commit62036745f330ac1a9bbca52e8bf87d4549b5b31d (patch)
tree304b6a162ac7ef2025304b48cb45e1d3857c260e /Alc
parent264274685ad01c861e02c7687baef737e18fa716 (diff)
Separate config init from library init
OSX has a bug where the file descriptor resource limit can't be increased once certain functions (such as fopen) are used. Since lib initialization happens in a global constructor and includes opening and parsing config files, it prevents apps from being able to increase the rlimit once the lib is loaded, which is usually before main(). By delaying config init, it allows apps the opportunity to change the rlimit before calling certain OpenAL functions.
Diffstat (limited to 'Alc')
-rw-r--r--Alc/ALc.c71
1 files changed, 46 insertions, 25 deletions
diff --git a/Alc/ALc.c b/Alc/ALc.c
index 5e541351..edc9513a 100644
--- a/Alc/ALc.c
+++ b/Alc/ALc.c
@@ -427,6 +427,8 @@ ALdouble ZScale = 1.0;
// ALC Related helper functions
static void ReleaseALC(void);
+static void alc_initconfig(void);
+
#ifdef HAVE_GCC_DESTRUCTOR
static void alc_init(void) __attribute__((constructor));
static void alc_deinit(void) __attribute__((destructor));
@@ -445,6 +447,7 @@ BOOL APIENTRY DllMain(HANDLE hModule,DWORD ul_reason_for_call,LPVOID lpReserved)
case DLL_PROCESS_ATTACH:
DisableThreadLibraryCalls(hModule);
alc_init();
+ alc_initconfig();
break;
case DLL_PROCESS_DETACH:
@@ -463,6 +466,7 @@ static void alc_constructor(void)
{
atexit(alc_destructor);
alc_init();
+ alc_initconfig();
}
static void alc_destructor(void)
@@ -479,8 +483,7 @@ static void alc_destructor(void)
static void alc_init(void)
{
- int i;
- const char *devs, *str;
+ const char *str;
str = getenv("ALSOFT_LOGFILE");
if(str && str[0])
@@ -504,6 +507,33 @@ static void alc_init(void)
InitializeCriticalSection(&g_csMutex);
InitializeCriticalSection(&ListLock);
ALTHUNK_INIT();
+}
+
+static void alc_deinit(void)
+{
+ int i;
+
+ ReleaseALC();
+
+ for(i = 0;BackendList[i].Deinit;i++)
+ BackendList[i].Deinit();
+ BackendLoopback.Deinit();
+
+ FreeALConfig();
+ ALTHUNK_EXIT();
+ DeleteCriticalSection(&ListLock);
+ DeleteCriticalSection(&g_csMutex);
+ tls_delete(LocalContext);
+
+ if(LogFile != stderr)
+ fclose(LogFile);
+ LogFile = NULL;
+}
+
+static void alc_initconfig(void)
+{
+ int i;
+ const char *devs, *str;
ReadALConfig();
@@ -606,28 +636,12 @@ static void alc_init(void)
}
}
-static void alc_deinit(void)
-{
- int i;
-
- ReleaseALC();
-
- for(i = 0;BackendList[i].Deinit;i++)
- BackendList[i].Deinit();
- BackendLoopback.Deinit();
-
- tls_delete(LocalContext);
-
- FreeALConfig();
- ALTHUNK_EXIT();
- DeleteCriticalSection(&ListLock);
- DeleteCriticalSection(&g_csMutex);
-
- if(LogFile != stderr)
- fclose(LogFile);
- LogFile = NULL;
-}
-
+#ifndef _WIN32
+static pthread_once_t once_control = PTHREAD_ONCE_INIT;
+#define DO_INITCONFIG() pthread_once(&once_control, alc_initconfig)
+#else
+#define DO_INITCONFIG()
+#endif
static void ProbeList(ALCchar **list, size_t *listsize, int type)
{
@@ -637,6 +651,7 @@ static void ProbeList(ALCchar **list, size_t *listsize, int type)
*list = NULL;
*listsize = 0;
+ DO_INITCONFIG();
for(i = 0;BackendList[i].Probe;i++)
BackendList[i].Probe(type);
}
@@ -1547,6 +1562,8 @@ ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice(const ALCchar *deviceName,
ALCdevice *device = NULL;
ALCint i;
+ DO_INITCONFIG();
+
if(SampleSize <= 0)
{
alcSetError(NULL, ALC_INVALID_VALUE);
@@ -1733,7 +1750,7 @@ ALC_API const ALCchar* ALC_APIENTRY alcGetString(ALCdevice *pDevice,ALCenum para
{
const ALCchar *value = NULL;
- switch (param)
+ switch(param)
{
case ALC_NO_ERROR:
value = alcNoError;
@@ -2594,6 +2611,8 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName)
ALCdevice *device;
ALint i;
+ DO_INITCONFIG();
+
if(deviceName && !deviceName[0])
deviceName = NULL;
@@ -2781,6 +2800,8 @@ ALC_API ALCdevice* ALC_APIENTRY alcLoopbackOpenDeviceSOFT(void)
{
ALCdevice *device;
+ DO_INITCONFIG();
+
device = calloc(1, sizeof(ALCdevice));
if(!device)
{