diff options
author | Timo Teräs <timo.teras@iki.fi> | 2013-11-08 13:17:58 +0100 |
---|---|---|
committer | Jaroslav Kysela <perex@perex.cz> | 2013-11-08 14:55:58 +0100 |
commit | ae035b7fe5620fcaf4f5ea33ecabcf93b8e056cd (patch) | |
tree | 5285cd42fb69f9b50aa4808e7958cbb3f99da95c | |
parent | 7d06b3ed9fda0220c2863ee20acd10c32cf313fd (diff) | |
download | alsa-lib-ae035b7fe5620fcaf4f5ea33ecabcf93b8e056cd.tar.gz |
conf.c: use portable way to initialize recursive mutex
PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP is not in POSIX, as _NP
(non-portable) suggests.
exposing such a symbol in musl libc would lock in the ABI for all
times and makes it impossible to do future changes to the under-
lying struct without hideous symbol versioning hacks.
use the portable way instead: pthread_once was designed for such
cases.
Signed-off-by: Timo Teräs <timo.teras@iki.fi>
Tested-by: John Spencer <maillist-alsa@barfooze.de>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
-rw-r--r-- | src/conf.c | 15 |
1 files changed, 13 insertions, 2 deletions
@@ -427,8 +427,8 @@ beginning:</P> #ifndef DOC_HIDDEN #ifdef HAVE_LIBPTHREAD -static pthread_mutex_t snd_config_update_mutex = - PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; +static pthread_mutex_t snd_config_update_mutex; +static pthread_once_t snd_config_update_mutex_once = PTHREAD_ONCE_INIT; #endif struct _snd_config { @@ -472,8 +472,19 @@ typedef struct { #ifdef HAVE_LIBPTHREAD +static void snd_config_init_mutex(void) +{ + pthread_mutexattr_t attr; + + pthread_mutexattr_init(&attr); + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); + pthread_mutex_init(&snd_config_update_mutex, &attr); + pthread_mutexattr_destroy(&attr); +} + static inline void snd_config_lock(void) { + pthread_once(&snd_config_update_mutex_once, snd_config_init_mutex); pthread_mutex_lock(&snd_config_update_mutex); } |