mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-08 13:29:59 -05:00
rework pa_once once again, because the once function needs to have terminated before pa_once returns, regardless whether the local call executes it or another thread does.
With the previous code it might happen that an long-running initializing in a once function is not terminated yet when another thread thinks it already is. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1387 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
parent
6d532029ea
commit
d0dcde060b
2 changed files with 74 additions and 9 deletions
|
|
@ -22,21 +22,17 @@
|
|||
USA.
|
||||
***/
|
||||
|
||||
#include <pulsecore/atomic.h>
|
||||
#include <pulsecore/mutex.h>
|
||||
|
||||
typedef struct pa_once {
|
||||
pa_atomic_int_t atomic;
|
||||
unsigned int once_value;
|
||||
pa_mutex *mutex;
|
||||
} pa_once_t;
|
||||
|
||||
#define PA_ONCE_INIT { PA_ATOMIC_INIT(0) }
|
||||
|
||||
#define pa_once_test(o) (pa_atomic_cmpxchg(&(o)->atomic, 0, 1))
|
||||
#define PA_ONCE_INIT { .once_value = 0, .mutex = NULL }
|
||||
|
||||
typedef void (*pa_once_func_t) (void);
|
||||
|
||||
static inline void pa_once(pa_once_t *o, pa_once_func_t f) {
|
||||
if (pa_once_test(o))
|
||||
f();
|
||||
}
|
||||
void pa_once(pa_once_t *o, pa_once_func_t f);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue