mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-11-09 13:30:03 -05:00
ALSA: pcm: Use recursive mutex
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>
This commit is contained in:
parent
fbc18ec771
commit
1cb217ead9
1 changed files with 7 additions and 1 deletions
|
|
@ -2581,6 +2581,10 @@ int snd_pcm_new(snd_pcm_t **pcmp, snd_pcm_type_t type, const char *name,
|
||||||
snd_pcm_stream_t stream, int mode)
|
snd_pcm_stream_t stream, int mode)
|
||||||
{
|
{
|
||||||
snd_pcm_t *pcm;
|
snd_pcm_t *pcm;
|
||||||
|
#ifdef THREAD_SAFE_API
|
||||||
|
pthread_mutexattr_t attr;
|
||||||
|
#endif
|
||||||
|
|
||||||
pcm = calloc(1, sizeof(*pcm));
|
pcm = calloc(1, sizeof(*pcm));
|
||||||
if (!pcm)
|
if (!pcm)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
@ -2595,7 +2599,9 @@ int snd_pcm_new(snd_pcm_t **pcmp, snd_pcm_type_t type, const char *name,
|
||||||
pcm->fast_op_arg = pcm;
|
pcm->fast_op_arg = pcm;
|
||||||
INIT_LIST_HEAD(&pcm->async_handlers);
|
INIT_LIST_HEAD(&pcm->async_handlers);
|
||||||
#ifdef THREAD_SAFE_API
|
#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;
|
/* use locking as default;
|
||||||
* each plugin may suppress this in its open call
|
* each plugin may suppress this in its open call
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue