mirror of
https://github.com/alsa-project/alsa-utils
synced 2024-09-20 18:19:58 +02:00
alsaloop: pcmjob.c: use portable way to initialize recursive mutex
PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP is not in POSIX, as _NP (non-portable) suggests. exposing such a symbol in musl libc would lock in the ABI for all times and makes it impossible to do future changes to the under- lying struct without hideous symbol versioning hacks. use the portable way instead: pthread_once was designed for such cases. Signed-off-by: John Spencer <maillist-alsa@barfooze.de> Tested-by: John Spencer <maillist-alsa@barfooze.de> Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
parent
f1e991e813
commit
0616d87fba
1 changed files with 13 additions and 2 deletions
|
@ -62,11 +62,22 @@ static const char *src_types[] = {
|
|||
};
|
||||
#endif
|
||||
|
||||
static pthread_mutex_t pcm_open_mutex =
|
||||
PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
|
||||
static pthread_once_t pcm_open_mutex_once = PTHREAD_ONCE_INIT;
|
||||
static pthread_mutex_t pcm_open_mutex;
|
||||
|
||||
static void pcm_open_init_mutex(void)
|
||||
{
|
||||
pthread_mutexattr_t attr;
|
||||
|
||||
pthread_mutexattr_init(&attr);
|
||||
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
|
||||
pthread_mutex_init(&pcm_open_mutex, &attr);
|
||||
pthread_mutexattr_destroy(&attr);
|
||||
}
|
||||
|
||||
static inline void pcm_open_lock(void)
|
||||
{
|
||||
pthread_once(&pcm_open_mutex_once, pcm_open_init_mutex);
|
||||
if (workarounds & WORKAROUND_SERIALOPEN)
|
||||
pthread_mutex_lock(&pcm_open_mutex);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue