From d0dcde060bb3e5fd04512d16afdd1ed71e780e08 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sat, 9 Sep 2006 23:54:19 +0000 Subject: 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 --- src/pulsecore/once.h | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'src/pulsecore/once.h') diff --git a/src/pulsecore/once.h b/src/pulsecore/once.h index a82a3c86..0aabb3f2 100644 --- a/src/pulsecore/once.h +++ b/src/pulsecore/once.h @@ -22,21 +22,17 @@ USA. ***/ -#include +#include 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 -- cgit