diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2007-10-04 11:13:33 +0100 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2007-10-04 11:26:44 +0100 |
commit | 71120727e190dfaf3ccbe63b3d91d90e36cff6f6 (patch) | |
tree | 7035ee3fa5c9310504cb249d877bf0d99d545dd1 /src/cairo-atomic-private.h | |
parent | f4356efb64a043e7a459fe77616f3b7c92b25c49 (diff) | |
download | cairo-71120727e190dfaf3ccbe63b3d91d90e36cff6f6.tar.gz |
[cairo-atomic] Use an atomic operation to set the status on a shared resource.
Since the objects can be shared and may be in use simultaneously across
multiple threads, setting the status needs to be atomic. We use a
locked compare and exchange in order to avoid overwriting an existing
error - that is we use an atomic operation that only sets the new status
value if the current value is CAIRO_STATUS_SUCCESS.
Diffstat (limited to 'src/cairo-atomic-private.h')
-rw-r--r-- | src/cairo-atomic-private.h | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/cairo-atomic-private.h b/src/cairo-atomic-private.h index 3577e0d32..3bf4e2754 100644 --- a/src/cairo-atomic-private.h +++ b/src/cairo-atomic-private.h @@ -54,6 +54,8 @@ typedef int cairo_atomic_int_t; # define _cairo_atomic_int_get(x) (*x) # define _cairo_atomic_int_set(x, value) ((*x) = value) +# define _cairo_atomic_int_cmpxchg(x, oldv, newv) __sync_val_compare_and_swap (x, oldv, newv) + #else # include "cairo-compiler-private.h" @@ -74,8 +76,14 @@ _cairo_atomic_int_get (int *x); cairo_private void _cairo_atomic_int_set (int *x, int value); +cairo_private int +_cairo_atomic_int_cmpxchg (int *x, int oldv, int newv); + #endif +#define _cairo_status_set_error(status, err) \ + (void) _cairo_atomic_int_cmpxchg (status, CAIRO_STATUS_SUCCESS, err) + CAIRO_END_DECLS #endif |