mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2026-01-01 11:08:36 -05:00
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>
This commit is contained in:
parent
4c65e58325
commit
1ba655560d
2 changed files with 17 additions and 34 deletions
|
|
@ -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) \
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue