All of lore.kernel.org
 help / color / mirror / Atom feed
From: John Spencer <maillist-alsa@barfooze.de>
To: alsa-devel <alsa-devel@alsa-project.org>
Cc: "Timo Teräs" <timo.teras@iki.fi>
Subject: [PATCH 1/2] alsa-lib: conf.c: use portable way to initialize recursive mutex
Date: Fri, 08 Nov 2013 14:03:50 +0100	[thread overview]
Message-ID: <527CE136.3090500@barfooze.de> (raw)

[-- Attachment #1: Type: text/plain, Size: 186 bytes --]

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


[-- Attachment #2: 0001-conf.c-use-portable-way-to-initialize-recursive-mute.patch --]
[-- Type: text/plain, Size: 1784 bytes --]

From dc28b1183af73e205d835414cacc9d9dfdf8af02 Mon Sep 17 00:00:00 2001
From: Timo Teräs <timo.teras@iki.fi>
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.

Signed-off-by: Timo Teräs <timo.teras@iki.fi>
Tested-by: John Spencer <maillist-alsa@barfooze.de>
---
 src/conf.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/conf.c b/src/conf.c
index bfed1c4..5ccc8e1 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -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);
 }
 
-- 
1.8.4


[-- Attachment #3: Type: text/plain, Size: 0 bytes --]



             reply	other threads:[~2013-11-08 13:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-08 13:03 John Spencer [this message]
2013-11-08 13:57 ` [PATCH 1/2] alsa-lib: conf.c: use portable way to initialize recursive mutex Jaroslav Kysela

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=527CE136.3090500@barfooze.de \
    --to=maillist-alsa@barfooze.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=timo.teras@iki.fi \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.