#ifndef DOC_HIDDEN
+#ifdef HAVE_LIBPTHREAD
+static pthread_mutex_t snd_config_update_mutex =
+ PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
+#endif
+
struct _snd_config {
char *id;
snd_config_type_t type;
int ch;
} input_t;
+#ifdef HAVE_LIBPTHREAD
+
+static inline void snd_config_lock(void)
+{
+ pthread_mutex_lock(&snd_config_update_mutex);
+}
+
+static inline void snd_config_unlock(void)
+{
+ pthread_mutex_unlock(&snd_config_update_mutex);
+}
+
+#else
+
+static inline void snd_config_lock(void) { }
+static inline void snd_config_unlock(void) { }
+
+#endif
+
static int safe_strtoll(const char *str, long long *val)
{
long long v;
if ((err = snd_config_search(config, "@hooks", &n)) < 0)
return 0;
+ snd_config_lock();
snd_config_remove(n);
do {
hit = 0;
if (i == idx) {
err = snd_config_hooks_call(config, n, private_data);
if (err < 0)
- return err;
+ goto _err;
idx++;
hit = 1;
}
err = 0;
_err:
snd_config_delete(n);
+ snd_config_unlock();
return err;
}
return 1;
}
-#ifdef HAVE_LIBPTHREAD
-static pthread_mutex_t snd_config_update_mutex = PTHREAD_MUTEX_INITIALIZER;
-#endif
-
/**
* \brief Updates #snd_config by rereading the global configuration files (if needed).
* \return 0 if #snd_config was up to date, 1 if #snd_config was
{
int err;
-#ifdef HAVE_LIBPTHREAD
- pthread_mutex_lock(&snd_config_update_mutex);
-#endif
+ snd_config_lock();
err = snd_config_update_r(&snd_config, &snd_config_global_update, NULL);
-#ifdef HAVE_LIBPTHREAD
- pthread_mutex_unlock(&snd_config_update_mutex);
-#endif
+ snd_config_unlock();
return err;
}
*/
int snd_config_update_free_global(void)
{
-#ifdef HAVE_LIBPTHREAD
- pthread_mutex_lock(&snd_config_update_mutex);
-#endif
+ snd_config_lock();
if (snd_config)
snd_config_delete(snd_config);
snd_config = NULL;
if (snd_config_global_update)
snd_config_update_free(snd_config_global_update);
snd_config_global_update = NULL;
-#ifdef HAVE_LIBPTHREAD
- pthread_mutex_unlock(&snd_config_update_mutex);
-#endif
+ snd_config_unlock();
/* FIXME: better to place this in another place... */
snd_dlobj_cache_cleanup();
snd_config_delete(subs);
return err;
}
-
+
/**
* \brief Searches for a definition in a configuration tree, using
* aliases and expanding hooks and arguments.
* if key contains dot (.), the implicit base is ignored
* and the key starts from root given by the 'config' parameter
*/
+ snd_config_lock();
err = snd_config_search_alias_hooks(config, strchr(key, '.') ? NULL : base, key, &conf);
- if (err < 0)
+ if (err < 0) {
+ snd_config_unlock();
return err;
- return snd_config_expand(conf, config, args, NULL, result);
+ }
+ err = snd_config_expand(conf, config, args, NULL, result);
+ snd_config_unlock();
+ return err;
}
#ifndef DOC_HIDDEN