general: recoded snd_dlobj_ functions

- changed logic to get/put blocks
- added mutex locking of the symbol list
- added reference counting (do not free used dl handles)

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
Jaroslav Kysela 2010-08-23 17:05:36 +02:00
parent be06ab3ee7
commit 91c9c8f1b8
7 changed files with 153 additions and 123 deletions

View file

@ -2068,7 +2068,6 @@ static int snd_pcm_open_conf(snd_pcm_t **pcmp, const char *name,
#ifndef PIC
extern void *snd_pcm_open_symbols(void);
#endif
void *h = NULL;
if (snd_config_get_type(pcm_conf) != SND_CONFIG_TYPE_COMPOUND) {
char *val;
id = NULL;
@ -2157,39 +2156,18 @@ static int snd_pcm_open_conf(snd_pcm_t **pcmp, const char *name,
#ifndef PIC
snd_pcm_open_symbols(); /* this call is for static linking only */
#endif
open_func = snd_dlobj_cache_lookup(open_name);
open_func = snd_dlobj_cache_get(lib, open_name,
SND_DLSYM_VERSION(SND_PCM_DLSYM_VERSION), 1);
if (open_func) {
err = 0;
goto _err;
}
h = snd_dlopen(lib, RTLD_NOW);
if (h)
open_func = snd_dlsym(h, open_name, SND_DLSYM_VERSION(SND_PCM_DLSYM_VERSION));
err = 0;
if (!h) {
SNDERR("Cannot open shared library %s",
lib ? lib : "[builtin]");
err = -ENOENT;
} else if (!open_func) {
SNDERR("symbol %s is not defined inside %s", open_name,
lib ? lib : "[builtin]");
snd_dlclose(h);
err = -ENXIO;
}
_err:
if (err >= 0) {
err = open_func(pcmp, name, pcm_root, pcm_conf, stream, mode);
if (err >= 0) {
if (h /*&& (mode & SND_PCM_KEEP_ALIVE)*/) {
snd_dlobj_cache_add(open_name, h, open_func);
h = NULL;
}
(*pcmp)->dl_handle = h;
(*pcmp)->open_func = open_func;
err = 0;
} else {
if (h)
snd_dlclose(h);
snd_dlobj_cache_put(open_func);
}
} else {
err = -ENXIO;
}
if (err >= 0) {
err = snd_config_search(pcm_root, "defaults.pcm.compat", &tmp);
@ -2209,6 +2187,7 @@ static int snd_pcm_open_conf(snd_pcm_t **pcmp, const char *name,
snd_config_get_integer(tmp, &(*pcmp)->minperiodtime);
err = 0;
}
_err:
if (type_conf)
snd_config_delete(type_conf);
free(buf);
@ -2304,8 +2283,7 @@ int snd_pcm_free(snd_pcm_t *pcm)
free(pcm->name);
free(pcm->hw.link_dst);
free(pcm->appl.link_dst);
if (pcm->dl_handle)
snd_dlclose(pcm->dl_handle);
snd_dlobj_cache_put(pcm->open_func);
free(pcm);
return 0;
}