aboutsummaryrefslogtreecommitdiffstats
path: root/Alc
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2010-05-28 23:00:59 -0700
committerChris Robinson <[email protected]>2010-05-28 23:00:59 -0700
commitebccfa93c3c1eca4b85e4cf6753bd44965350c5a (patch)
tree0ad08e67c936524d201ddb0d4eb87e78aadbf1f1 /Alc
parente9f4576d4d0340b4f4c090977ef48a56c619fd6d (diff)
Don't unload libs when they're not needed
Some libs don't really like being unloaded and reloaded all the time, and the benefits aren't that great
Diffstat (limited to 'Alc')
-rw-r--r--Alc/alsa.c39
-rw-r--r--Alc/dsound.c33
-rw-r--r--Alc/portaudio.c13
-rw-r--r--Alc/pulseaudio.c39
4 files changed, 28 insertions, 96 deletions
diff --git a/Alc/alsa.c b/Alc/alsa.c
index 4cf0a9c9..5b6213ba 100644
--- a/Alc/alsa.c
+++ b/Alc/alsa.c
@@ -119,12 +119,11 @@ static DevMap *allDevNameMap;
static ALuint numDevNames;
static DevMap *allCaptureDevNameMap;
static ALuint numCaptureDevNames;
-static volatile ALuint load_count;
void *alsa_load(void)
{
- if(load_count == 0)
+ if(!alsa_handle)
{
char *str;
@@ -212,22 +211,9 @@ LOAD_FUNC(snd_card_next);
#undef LOAD_FUNC
}
- ++load_count;
-
return alsa_handle;
}
-void alsa_unload(void)
-{
- if(load_count == 0 || --load_count > 0)
- return;
-
-#ifdef HAVE_DLFCN_H
- dlclose(alsa_handle);
-#endif
- alsa_handle = NULL;
-}
-
static DevMap *probe_devices(snd_pcm_stream_t stream, ALuint *count)
{
snd_ctl_t *handle;
@@ -561,10 +547,7 @@ static ALCboolean alsa_open_playback(ALCdevice *device, const ALCchar *deviceNam
}
}
if(idx == numDevNames)
- {
- alsa_unload();
return ALC_FALSE;
- }
}
data = (alsa_data*)calloc(1, sizeof(alsa_data));
@@ -585,7 +568,6 @@ static ALCboolean alsa_open_playback(ALCdevice *device, const ALCchar *deviceNam
{
free(data);
AL_PRINT("Could not open playback device '%s': %s\n", driver, psnd_strerror(i));
- alsa_unload();
return ALC_FALSE;
}
@@ -601,8 +583,6 @@ static void alsa_close_playback(ALCdevice *device)
psnd_pcm_close(data->pcmHandle);
free(data);
device->ExtraData = NULL;
-
- alsa_unload();
}
static ALCboolean alsa_reset_playback(ALCdevice *device)
@@ -863,10 +843,7 @@ static ALCboolean alsa_open_capture(ALCdevice *pDevice, const ALCchar *deviceNam
}
}
if(idx == numCaptureDevNames)
- {
- alsa_unload();
return ALC_FALSE;
- }
}
data = (alsa_data*)calloc(1, sizeof(alsa_data));
@@ -887,7 +864,6 @@ static ALCboolean alsa_open_capture(ALCdevice *pDevice, const ALCchar *deviceNam
{
AL_PRINT("Could not open capture device '%s': %s\n", driver, psnd_strerror(i));
free(data);
- alsa_unload();
return ALC_FALSE;
}
@@ -980,7 +956,6 @@ error:
DestroyRingBuffer(data->ring);
psnd_pcm_close(data->pcmHandle);
free(data);
- alsa_unload();
pDevice->ExtraData = NULL;
return ALC_FALSE;
@@ -999,8 +974,6 @@ static void alsa_close_capture(ALCdevice *pDevice)
free(data->buffer);
free(data);
pDevice->ExtraData = NULL;
-
- alsa_unload();
}
static void alsa_start_capture(ALCdevice *pDevice)
@@ -1065,6 +1038,14 @@ void alc_alsa_deinit(void)
free(allCaptureDevNameMap);
allCaptureDevNameMap = NULL;
numCaptureDevNames = 0;
+
+ if(alsa_handle)
+ {
+#ifdef HAVE_DLFCN_H
+ dlclose(alsa_handle);
+#endif
+ alsa_handle = NULL;
+ }
}
void alc_alsa_probe(int type)
@@ -1098,6 +1079,4 @@ void alc_alsa_probe(int type)
for(i = 0;i < numCaptureDevNames;++i)
AppendCaptureDeviceList(allCaptureDevNameMap[i].name);
}
-
- alsa_unload();
}
diff --git a/Alc/dsound.c b/Alc/dsound.c
index 3ce45874..704fb909 100644
--- a/Alc/dsound.c
+++ b/Alc/dsound.c
@@ -71,12 +71,11 @@ typedef struct {
static const ALCchar dsDevice[] = "DirectSound Software";
static DevMap *DeviceList;
static ALuint NumDevices;
-static volatile ALuint load_count;
void *DSoundLoad(void)
{
- if(load_count == 0)
+ if(!ds_handle)
{
#ifdef _WIN32
ds_handle = LoadLibraryA("dsound.dll");
@@ -105,22 +104,9 @@ LOAD_FUNC(DirectSoundCreate);
LOAD_FUNC(DirectSoundEnumerateA);
#undef LOAD_FUNC
}
- ++load_count;
-
return ds_handle;
}
-void DSoundUnload(void)
-{
- if(load_count == 0 || --load_count > 0)
- return;
-
-#ifdef _WIN32
- FreeLibrary(ds_handle);
-#endif
- ds_handle = NULL;
-}
-
static BOOL CALLBACK DSoundEnumDevices(LPGUID guid, LPCSTR desc, LPCSTR drvname, LPVOID data)
{
@@ -259,10 +245,7 @@ static ALCboolean DSoundOpenPlayback(ALCdevice *device, const ALCchar *deviceNam
}
}
if(i == NumDevices)
- {
- DSoundUnload();
return ALC_FALSE;
- }
}
//Initialise requested device
@@ -270,7 +253,6 @@ static ALCboolean DSoundOpenPlayback(ALCdevice *device, const ALCchar *deviceNam
if(!pData)
{
alcSetError(device, ALC_OUT_OF_MEMORY);
- DSoundUnload();
return ALC_FALSE;
}
@@ -283,7 +265,6 @@ static ALCboolean DSoundOpenPlayback(ALCdevice *device, const ALCchar *deviceNam
if(pData->lpDS)
IDirectSound_Release(pData->lpDS);
free(pData);
- DSoundUnload();
return ALC_FALSE;
}
@@ -299,8 +280,6 @@ static void DSoundClosePlayback(ALCdevice *device)
IDirectSound_Release(pData->lpDS);
free(pData);
device->ExtraData = NULL;
-
- DSoundUnload();
}
static ALCboolean DSoundResetPlayback(ALCdevice *device)
@@ -560,6 +539,14 @@ void alcDSoundDeinit(void)
free(DeviceList);
DeviceList = NULL;
NumDevices = 0;
+
+ if(ds_handle)
+ {
+#ifdef _WIN32
+ FreeLibrary(ds_handle);
+#endif
+ ds_handle = NULL;
+ }
}
void alcDSoundProbe(int type)
@@ -588,6 +575,4 @@ void alcDSoundProbe(int type)
AppendAllDeviceList(DeviceList[i].name);
}
}
-
- DSoundUnload();
}
diff --git a/Alc/portaudio.c b/Alc/portaudio.c
index c75c2a53..561f7470 100644
--- a/Alc/portaudio.c
+++ b/Alc/portaudio.c
@@ -125,10 +125,6 @@ LOAD_FUNC(Pa_GetStreamInfo);
return pa_handle;
}
-void pa_unload(void)
-{
-}
-
typedef struct {
PaStream *stream;
@@ -210,7 +206,6 @@ static ALCboolean pa_open_playback(ALCdevice *device, const ALCchar *deviceName)
AL_PRINT("Unknown format: 0x%x\n", device->Format);
device->ExtraData = NULL;
free(data);
- pa_unload();
return ALC_FALSE;
}
outParams.channelCount = aluChannelsFromFormat(device->Format);
@@ -224,7 +219,6 @@ static ALCboolean pa_open_playback(ALCdevice *device, const ALCchar *deviceName)
AL_PRINT("Pa_OpenStream() returned an error: %s\n", pPa_GetErrorText(err));
device->ExtraData = NULL;
free(data);
- pa_unload();
return ALC_FALSE;
}
streamInfo = pPa_GetStreamInfo(data->stream);
@@ -246,8 +240,6 @@ static void pa_close_playback(ALCdevice *device)
free(data);
device->ExtraData = NULL;
-
- pa_unload();
}
static ALCboolean pa_reset_playback(ALCdevice *device)
@@ -350,7 +342,6 @@ static ALCboolean pa_open_capture(ALCdevice *device, const ALCchar *deviceName)
error:
DestroyRingBuffer(data->ring);
free(data);
- pa_unload();
return ALC_FALSE;
}
@@ -365,8 +356,6 @@ static void pa_close_capture(ALCdevice *device)
free(data);
device->ExtraData = NULL;
-
- pa_unload();
}
static void pa_start_capture(ALCdevice *device)
@@ -447,6 +436,4 @@ void alc_pa_probe(int type)
AppendAllDeviceList(pa_device);
else if(type == CAPTURE_DEVICE_PROBE)
AppendCaptureDeviceList(pa_capture);
-
- pa_unload();
}
diff --git a/Alc/pulseaudio.c b/Alc/pulseaudio.c
index da471f8d..6166966d 100644
--- a/Alc/pulseaudio.c
+++ b/Alc/pulseaudio.c
@@ -141,12 +141,11 @@ typedef struct {
static const ALCchar pulse_device[] = "PulseAudio Software";
static const ALCchar pulse_capture_device[] = "PulseAudio Capture";
static pa_context_flags_t pulse_ctx_flags;
-static volatile ALuint load_count;
void *pulse_load(void) //{{{
{
- if(load_count == 0)
+ if(!pa_handle)
{
#ifdef _WIN32
pa_handle = LoadLibrary("libpulse-0.dll");
@@ -262,24 +261,9 @@ LOAD_OPTIONAL_FUNC(pa_stream_begin_write);
#undef LOAD_OPTIONAL_FUNC
#undef LOAD_FUNC
}
- ++load_count;
-
return pa_handle;
} //}}}
-void pulse_unload(void) //{{{
-{
- if(load_count == 0 || --load_count > 0)
- return;
-
-#ifdef _WIN32
- FreeLibrary(pa_handle);
-#elif defined (HAVE_DLFCN_H)
- dlclose(pa_handle);
-#endif
- pa_handle = NULL;
-} //}}}
-
// PulseAudio Event Callbacks //{{{
static void context_state_callback(pa_context *context, void *pdata) //{{{
@@ -618,10 +602,7 @@ static ALCboolean pulse_open_playback(ALCdevice *device, const ALCchar *device_n
return ALC_FALSE;
if(pulse_open(device, device_name) == ALC_FALSE)
- {
- pulse_unload();
return ALC_FALSE;
- }
data = device->ExtraData;
@@ -663,14 +644,12 @@ static ALCboolean pulse_open_playback(ALCdevice *device, const ALCchar *device_n
fail:
pulse_close(device);
- pulse_unload();
return ALC_FALSE;
} //}}}
static void pulse_close_playback(ALCdevice *device) //{{{
{
pulse_close(device);
- pulse_unload();
} //}}}
static ALCboolean pulse_reset_playback(ALCdevice *device) //{{{
@@ -817,10 +796,7 @@ static ALCboolean pulse_open_capture(ALCdevice *device, const ALCchar *device_na
return ALC_FALSE;
if(pulse_open(device, device_name) == ALC_FALSE)
- {
- pulse_unload();
return ALC_FALSE;
- }
data = device->ExtraData;
ppa_threaded_mainloop_lock(data->loop);
@@ -924,14 +900,12 @@ static ALCboolean pulse_open_capture(ALCdevice *device, const ALCchar *device_na
fail:
pulse_close(device);
- pulse_unload();
return ALC_FALSE;
} //}}}
static void pulse_close_capture(ALCdevice *device) //{{{
{
pulse_close(device);
- pulse_unload();
} //}}}
static void pulse_start_capture(ALCdevice *device) //{{{
@@ -1055,6 +1029,15 @@ void alc_pulse_init(BackendFuncs *func_list) //{{{
void alc_pulse_deinit(void) //{{{
{
+ if(pa_handle)
+ {
+#ifdef _WIN32
+ FreeLibrary(pa_handle);
+#elif defined (HAVE_DLFCN_H)
+ dlclose(pa_handle);
+#endif
+ pa_handle = NULL;
+ }
} //}}}
void alc_pulse_probe(int type) //{{{
@@ -1067,7 +1050,5 @@ void alc_pulse_probe(int type) //{{{
AppendAllDeviceList(pulse_device);
else if(type == CAPTURE_DEVICE_PROBE)
AppendCaptureDeviceList(pulse_capture_device);
-
- pulse_unload();
} //}}}
//}}}