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.
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;
#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)
{