All of lore.kernel.org
 help / color / mirror / Atom feed
From: Samuel Thibault <samuel.thibault@ens-lyon.org>
To: alsa-devel@alsa-project.org
Subject: locking looks odd
Date: Tue, 16 Aug 2016 23:03:22 +0200	[thread overview]
Message-ID: <20160816210322.GD4466@var.home> (raw)

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

Hello,

We are having odd issues with libasound 1.1.2 which we didn't have with
libasound 1.1.1, more precisely

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=833950

so I'm having a look at the locking API introduced in 1.1.2, and there
are some oddities:

- snd_pcm_new seems to initialize pcm->thread_safe to 0 by default, this
  does not seem safe. The attached patch initializes it to 1, which
  fixes the bug in our tests.

- snd_pcm_hw_open_fd forces it to 1, thus ignoring what snd_pcm_new set.

- one can find both __snd_pcm_lock and snd_pcm_lock functions, what is
  the expected difference between them?

- __snd_pcm_lock takes locks when thread_safe >= 0, while snd_pcm_lock
  takes locks when thread_safe == 0, this looks really odd.

- libasound could just not link against libpthread,
  pthread_mutex_lock/unlock are already provided as empty stubs by libc,
  the overhead will thus only be hit when the application links against
  libpthread (libasound will then properly use pthread locks).

Samuel

[-- Attachment #2: patch --]
[-- Type: text/plain, Size: 337 bytes --]

--- ./src/pcm/pcm.c.orig	2016-08-10 19:39:59.881564371 +0200
+++ ./src/pcm/pcm.c	2016-08-10 19:40:04.211539997 +0200
@@ -2544,6 +2544,7 @@
 	pcm->fast_op_arg = pcm;
 	INIT_LIST_HEAD(&pcm->async_handlers);
 #ifdef THREAD_SAFE_API
+	pcm->thread_safe = 1;
 	pthread_mutex_init(&pcm->lock, NULL);
 	{
 		static int default_thread_safe = -1;

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



             reply	other threads:[~2016-08-16 21:03 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-16 21:03 Samuel Thibault [this message]
2016-08-17 12:41 ` locking looks odd Takashi Sakamoto
2016-08-17 17:46 ` Jaroslav Kysela
2016-08-20 12:12   ` Samuel Thibault
2016-08-22 12:02     ` Takashi Iwai
2016-08-26 19:02     ` Samuel Thibault
2016-08-30 14:20       ` Takashi Iwai
2016-08-30 15:54         ` Alan Horstmann
2016-08-30 16:00           ` Takashi Iwai
2016-08-22 11:54   ` Takashi Iwai
2016-09-01  6:27   ` David Henningsson
2016-09-01  8:12     ` Takashi Iwai

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=20160816210322.GD4466@var.home \
    --to=samuel.thibault@ens-lyon.org \
    --cc=alsa-devel@alsa-project.org \
    /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.