mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-01 22:58:47 -04:00
add support for static mutexes
This commit is contained in:
parent
db27c6347e
commit
e960125011
2 changed files with 27 additions and 0 deletions
|
|
@ -138,3 +138,23 @@ int pa_cond_wait(pa_cond *c, pa_mutex *m) {
|
|||
|
||||
return pthread_cond_wait(&c->cond, &m->mutex);
|
||||
}
|
||||
|
||||
pa_mutex* pa_static_mutex_get(pa_static_mutex *s, pa_bool_t recursive, pa_bool_t inherit_priority) {
|
||||
pa_mutex *m;
|
||||
|
||||
pa_assert(s);
|
||||
|
||||
/* First, check if already initialized and short cut */
|
||||
if ((m = pa_atomic_ptr_load(&s->ptr)))
|
||||
return m;
|
||||
|
||||
/* OK, not initialized, so let's allocate, and fill in */
|
||||
m = pa_mutex_new(recursive, inherit_priority);
|
||||
if ((pa_atomic_ptr_cmpxchg(&s->ptr, NULL, m)))
|
||||
return m;
|
||||
|
||||
/* Him, filling in failed, so someone else must have filled in
|
||||
* already */
|
||||
pa_assert_se(m = pa_atomic_ptr_load(&s->ptr));
|
||||
return m;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
***/
|
||||
|
||||
#include <pulsecore/macro.h>
|
||||
#include <pulsecore/atomic.h>
|
||||
|
||||
typedef struct pa_mutex pa_mutex;
|
||||
|
||||
|
|
@ -45,4 +46,10 @@ void pa_cond_free(pa_cond *c);
|
|||
void pa_cond_signal(pa_cond *c, int broadcast);
|
||||
int pa_cond_wait(pa_cond *c, pa_mutex *m);
|
||||
|
||||
typedef struct pa_static_mutex {
|
||||
pa_atomic_ptr_t ptr;
|
||||
} pa_static_mutex;
|
||||
|
||||
pa_mutex* pa_static_mutex_get(pa_static_mutex *m, pa_bool_t recursive, pa_bool_t inherit_priority);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue