Skip to contentSkip to conversation

alsa-lib: conf.c: use portable way to initialize recursive mutex

PATCH Applied John Spencer 2 participants 2 messages Nov 8, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 alsa-lib: conf.c: use portable way to initialize recursive mutex

attaching the patch, as i currently have problems with git-send-email, and it would force me to use the wrong author name.

got the OK from Timo on IRC to send his patch.

thanks,
--JS

From dc28b1183af73e205d835414cacc9d9dfdf8af02 Mon Sep 17 00:00:00 2001
From: Timo Teräs <[email protected]>
Date: Fri, 8 Nov 2013 13:17:58 +0100
Subject: [PATCH] conf.c: use portable way to initialize recursive mutex
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

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.

---
 src/conf.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
src/conf.c +13 -2
index bfed1c4..5ccc8e1 100644
@@ -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);
 }
 
Signature · 1 line
1.8.4
#1 lore raw
Quoted 4 lines · John Spencer

attaching the patch, as i currently have problems with git-send-email, and it would force me to use the wrong author name.

got the OK from Timo on IRC to send his patch.

Applied. Thanks.

Jaroslav

Signature · 3 lines
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project; Red Hat, Inc.