]> git.alsa-project.org Git - alsa-lib.git/commit
conf: Add thread-safe global tree reference
authorTakashi Iwai <tiwai@suse.de>
Tue, 17 May 2016 13:39:07 +0000 (15:39 +0200)
committerTakashi Iwai <tiwai@suse.de>
Tue, 17 May 2016 13:51:20 +0000 (15:51 +0200)
commitc9a0d7d601e8ab069f8745968c03c8470b24d20d
tree5c98ec3a6a972a006aad63ec47daeceaffe296a6
parent5fb3fe17249c3fffb8b8e15108ff72f27ba5e81c
conf: Add thread-safe global tree reference

Most of open functions in alsa-lib have the call pattern:
  snd_config_update();
  return snd_xxx_open(x, snd_config, ...);

This means that the toplevel config gets updated, and passed to a
local open function.  Although snd_config_update() itself has a
pthread mutex to be thread safe, the whole procedure above isn't
thread safe.  Namely, the global snd_config tree may be deleted and
recreated at any time while the open function is being processed.
This may lead to a data corruption and crash of the program.

For avoiding the corruption, this patch introduces a refcount to
config tree object.  A few new helper functions are introduced as
well:
- snd_config_update_ref() does update and take the refcount of the
  toplevel tree.   The obtained config tree has to be freed via
  snd_config_unref() below.
- snd_config_ref() and snd_config_unref() manage the refcount of the
  config object.  The latter eventually deletes the object when all
  references are gone.

Along with these additions, the caller of snd_config_update() and
snd_config global tree in alsa-lib are replaced with the new helpers.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
include/conf.h
src/conf.c
src/control/control.c
src/hwdep/hwdep.c
src/pcm/pcm.c
src/rawmidi/rawmidi.c
src/seq/seq.c
src/timer/timer.c
src/timer/timer_query.c