All of lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: alsa-devel@alsa-project.org
Subject: [PATCH RFC alsa-lib 0/5] Add thread-safety to PCM API
Date: Tue,  5 Jul 2016 17:20:19 +0200	[thread overview]
Message-ID: <20160705152024.20152-1-tiwai@suse.de> (raw)

Hi,

here is an experimental patchset to add multi thread safety to PCM
functions.  Basically ALSA PCM functions are thread-unsafe, and
applications are supposed to do the proper protection against racy
accesses.  The reality is, however, that application developers don't
care such, as alsa-lib works in most cases.  Of course, users still
get occasionally mysterious crashes.

As a workaround, this patchset adds the pthread mutex protection to
most of exported PCM functions.  This is slightly an overkill, but the
biggest merit is that it's easy to implement; I just wrapped the
functions and replaced the internal ones with unlocked versions.

To be noted, there is an optimization for the direct hw PCM access.
Performance-sensitive applications like JACK should work like before
without any overhead.

Another bonus by this addition is that we can finally get rid of home
brew (and deadly smelling) atomic macros from the tree, since it's now
more widely protected.

I lightly tested on my local machines and it seems working well, so
far.

Comments and suggestions welcome.


thanks,

Takashi

===

Takashi Iwai (5):
  pcm: Add thread-safety to PCM API
  test: Add pcm-multi-thread program
  Add pcm-multi-thread to .gitignore
  pcm: Remove superfluous rmb() from PCM meter plugin
  pcm: Remove home brew atomic operations

 .gitignore              |   1 +
 configure.ac            |  15 ++
 include/Makefile.am     |   2 +-
 include/iatomic.h       | 170 ------------------
 src/pcm/Makefile.am     |   2 +-
 src/pcm/atomic.c        |  43 -----
 src/pcm/pcm.c           | 468 +++++++++++++++++++++++++++++++++++++++++-------
 src/pcm/pcm_direct.c    |   4 +-
 src/pcm/pcm_dmix.c      |  13 +-
 src/pcm/pcm_dshare.c    |  13 +-
 src/pcm/pcm_dsnoop.c    |  15 +-
 src/pcm/pcm_file.c      |  21 ++-
 src/pcm/pcm_generic.c   |  10 +-
 src/pcm/pcm_hw.c        |   3 +
 src/pcm/pcm_ioplug.c    |  11 +-
 src/pcm/pcm_local.h     |  62 ++++++-
 src/pcm/pcm_meter.c     |   1 -
 src/pcm/pcm_mmap.c      |  16 +-
 src/pcm/pcm_params.c    |   2 +-
 src/pcm/pcm_plugin.c    |  72 ++------
 src/pcm/pcm_plugin.h    |   2 -
 src/pcm/pcm_rate.c      |  41 ++---
 src/pcm/pcm_route.c     |   2 +-
 test/Makefile.am        |   3 +-
 test/pcm-multi-thread.c | 263 +++++++++++++++++++++++++++
 25 files changed, 851 insertions(+), 404 deletions(-)
 delete mode 100644 include/iatomic.h
 delete mode 100644 src/pcm/atomic.c
 create mode 100644 test/pcm-multi-thread.c

-- 
2.9.0

             reply	other threads:[~2016-07-05 15:20 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-05 15:20 Takashi Iwai [this message]
2016-07-05 15:20 ` [PATCH RFC alsa-lib 1/5] pcm: Add thread-safety to PCM API Takashi Iwai
2016-07-05 16:30   ` Clemens Ladisch
2016-07-05 16:36     ` Takashi Iwai
2016-07-05 15:20 ` [PATCH RFC alsa-lib 2/5] test: Add pcm-multi-thread program Takashi Iwai
2016-07-05 15:20 ` [PATCH RFC alsa-lib 3/5] Add pcm-multi-thread to .gitignore Takashi Iwai
2016-07-05 15:20 ` [PATCH RFC alsa-lib 4/5] pcm: Remove superfluous rmb() from PCM meter plugin Takashi Iwai
2016-07-05 15:20 ` [PATCH RFC alsa-lib 5/5] pcm: Remove home brew atomic operations 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=20160705152024.20152-1-tiwai@suse.de \
    --to=tiwai@suse.de \
    --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.