diff options
author | Takashi Iwai <tiwai@suse.de> | 2016-07-07 15:21:14 +0200 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2016-07-11 15:25:30 +0200 |
commit | c4b690278eeaf9a6805f67f6709e4aa33e58773a (patch) | |
tree | 847eca22a7a961cec210ee96b896087cf093244f /src/pcm | |
parent | 7a8a1d155267fb6e21ddaa0787d121ec47a15bf2 (diff) | |
download | alsa-lib-c4b690278eeaf9a6805f67f6709e4aa33e58773a.tar.gz |
pcm: Add LIBASOUND_THREAD_SAFE env variable check
For making the debugging with any deadlocks by the newly introduced
thread-safety feature, add a check with LIBASOUND_THREAD_SAFE
environment variable. When this variable is set to "0", alsa-lib PCM
forcibly disables the whole thread-safe pthread mutex calls.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'src/pcm')
-rw-r--r-- | src/pcm/pcm.c | 16 | ||||
-rw-r--r-- | src/pcm/pcm_local.h | 6 |
2 files changed, 20 insertions, 2 deletions
diff --git a/src/pcm/pcm.c b/src/pcm/pcm.c index 6e7583d0..a66e8af6 100644 --- a/src/pcm/pcm.c +++ b/src/pcm/pcm.c @@ -494,6 +494,13 @@ aren't thread-safe, and application needs to call them carefully when they are called from multiple threads. In general, all the functions that are often called during streaming are covered as thread-safe. +This thread-safe behavior can be disabled also by passing 0 to the environment +variable LIBASOUND_THREAD_SAFE, e.g. +\code +LIBASOUND_THREAD_SAFE=0 aplay foo.wav +\endcode +for making the debugging easier. + \section pcm_dev_names PCM naming conventions The ALSA library uses a generic string representation for names of devices. @@ -2536,6 +2543,15 @@ int snd_pcm_new(snd_pcm_t **pcmp, snd_pcm_type_t type, const char *name, INIT_LIST_HEAD(&pcm->async_handlers); #ifdef THREAD_SAFE_API pthread_mutex_init(&pcm->lock, NULL); + { + static int default_thread_safe = -1; + if (default_thread_safe < 0) { + char *p = getenv("LIBASOUND_THREAD_SAFE"); + default_thread_safe = !p || *p != '0'; + } + if (!default_thread_safe) + pcm->thread_safe = -1; /* force to disable */ + } #endif *pcmp = pcm; return 0; diff --git a/src/pcm/pcm_local.h b/src/pcm/pcm_local.h index 5c7eeb4e..bb7964d7 100644 --- a/src/pcm/pcm_local.h +++ b/src/pcm/pcm_local.h @@ -1087,11 +1087,13 @@ static inline void sw_set_period_event(snd_pcm_sw_params_t *params, int val) #ifdef THREAD_SAFE_API static inline void __snd_pcm_lock(snd_pcm_t *pcm) { - pthread_mutex_lock(&pcm->lock); + if (pcm->thread_safe >= 0) + pthread_mutex_lock(&pcm->lock); } static inline void __snd_pcm_unlock(snd_pcm_t *pcm) { - pthread_mutex_unlock(&pcm->lock); + if (pcm->thread_safe >= 0) + pthread_mutex_unlock(&pcm->lock); } static inline void snd_pcm_lock(snd_pcm_t *pcm) { |