diff options
author | David Henningsson <david.henningsson@canonical.com> | 2012-05-18 22:29:41 +0200 |
---|---|---|
committer | David Henningsson <david.henningsson@canonical.com> | 2012-05-25 10:50:37 +0200 |
commit | 1ba655560d2636d952a56a6f7013ecc0df13cd5b (patch) | |
tree | b54ca7e4b04342fc4ae4296b7851aca7fa57e8d1 /src/pulsecore/once.h | |
parent | 4c65e58325fabde724eb340da6ce2c9988e45871 (diff) |
once: Fix race causing pa_once to sometimes run twice
There was a race in the existing code that could cause the pa_once code
to be run twice, see:
http://lists.freedesktop.org/archives/pulseaudio-discuss/2012-April/013354.html
Therefore the existing implementation was rewritten to instead look like
the reference implementation here:
http://www.hpl.hp.com/research/linux/atomic_ops/example.php4
Signed-off-by: David Henningsson <david.henningsson@canonical.com>
Diffstat (limited to 'src/pulsecore/once.h')
-rw-r--r-- | src/pulsecore/once.h | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/pulsecore/once.h b/src/pulsecore/once.h index edc81881..a478d1ff 100644 --- a/src/pulsecore/once.h +++ b/src/pulsecore/once.h @@ -23,16 +23,16 @@ ***/ #include <pulsecore/atomic.h> +#include <pulsecore/mutex.h> typedef struct pa_once { - pa_atomic_ptr_t mutex; - pa_atomic_t ref, done; + pa_static_mutex mutex; + pa_atomic_t done; } pa_once; #define PA_ONCE_INIT \ { \ - .mutex = PA_ATOMIC_PTR_INIT(NULL), \ - .ref = PA_ATOMIC_INIT(0), \ + .mutex = PA_STATIC_MUTEX_INIT, \ .done = PA_ATOMIC_INIT(0) \ } |