The recent thread-safety pthread implementation caused deadlocks in
some situations, e.g. when an external plugin calls snd_pcm_state() in
its callback. One can avoid the deadlock by carefully using the
unlocked version, but it's often error-prone, and it might be still
problem with the old binaries.
In this patch, we initialize the pthread mutex as recursive for fixing
such a problem.
Suggested-by: Timo Wischer <twischer@de.adit-jv.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
snd_pcm_stream_t stream, int mode)
{
snd_pcm_t *pcm;
+#ifdef THREAD_SAFE_API
+ pthread_mutexattr_t attr;
+#endif
+
pcm = calloc(1, sizeof(*pcm));
if (!pcm)
return -ENOMEM;
pcm->fast_op_arg = pcm;
INIT_LIST_HEAD(&pcm->async_handlers);
#ifdef THREAD_SAFE_API
- pthread_mutex_init(&pcm->lock, NULL);
+ pthread_mutexattr_init(&attr);
+ pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
+ pthread_mutex_init(&pcm->lock, &attr);
/* use locking as default;
* each plugin may suppress this in its open call
*/