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:
Lennart Poettering 2006-09-09 23:54:19 +00:00
parent 6d532029ea
commit d0dcde060b
2 changed files with 74 additions and 9 deletions

View file

@ -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