summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Spencer <maillist-alsa@barfooze.de>2013-11-08 13:59:41 +0100
committerJaroslav Kysela <perex@perex.cz>2013-11-08 14:57:06 +0100
commit0616d87fbaae1d4a558104051cb5369504eb2068 (patch)
treef31402293fde7ff8d9f77a1d47a33812a4c6dbde
parentf1e991e81350e9388ab6cf04a64ac4b4389a588c (diff)
downloadalsa-utils-0616d87fbaae1d4a558104051cb5369504eb2068.tar.gz
alsaloop: pcmjob.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: John Spencer <maillist-alsa@barfooze.de> Tested-by: John Spencer <maillist-alsa@barfooze.de> Signed-off-by: Jaroslav Kysela <perex@perex.cz>
-rw-r--r--alsaloop/pcmjob.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/alsaloop/pcmjob.c b/alsaloop/pcmjob.c
index 139b6fd..f32180c 100644
--- a/alsaloop/pcmjob.c
+++ b/alsaloop/pcmjob.c
@@ -62,11 +62,22 @@ static const char *src_types[] = {
};
#endif
-static pthread_mutex_t pcm_open_mutex =
- PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
+static pthread_once_t pcm_open_mutex_once = PTHREAD_ONCE_INIT;
+static pthread_mutex_t pcm_open_mutex;
+
+static void pcm_open_init_mutex(void)
+{
+ pthread_mutexattr_t attr;
+
+ pthread_mutexattr_init(&attr);
+ pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
+ pthread_mutex_init(&pcm_open_mutex, &attr);
+ pthread_mutexattr_destroy(&attr);
+}
static inline void pcm_open_lock(void)
{
+ pthread_once(&pcm_open_mutex_once, pcm_open_init_mutex);
if (workarounds & WORKAROUND_SERIALOPEN)
pthread_mutex_lock(&pcm_open_mutex);
}