diff options
author | Andrea Canciani <ranma42@gmail.com> | 2010-04-28 17:23:47 +0200 |
---|---|---|
committer | Andrea Canciani <ranma42@gmail.com> | 2010-04-29 10:52:48 +0200 |
commit | 248af38b3efa3f96225eea43f4ba5b94baff34a6 (patch) | |
tree | e47b1d5bc644d021a6f483934248b50c04fab761 | |
parent | 56a367a1626b2b7ec3d9e64e74f016867f294a34 (diff) |
atomic: Add MacOSX atomic implementation
Enable atomic operation on MacOS X, using the functions provided by
libkern/OSAtomic.h
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
-rw-r--r-- | build/aclocal.cairo.m4 | 10 | ||||
-rw-r--r-- | src/cairo-atomic-private.h | 30 |
2 files changed, 40 insertions, 0 deletions
diff --git a/build/aclocal.cairo.m4 b/build/aclocal.cairo.m4 index 482763eb..f271ccf9 100644 --- a/build/aclocal.cairo.m4 +++ b/build/aclocal.cairo.m4 @@ -174,6 +174,11 @@ int atomic_cmpxchg(int i, int j, int k) { return __sync_val_compare_and_swap (&i AC_CHECK_HEADER([atomic_ops.h], cairo_cv_atomic_primitives="libatomic-ops") fi + + if test "x$cairo_cv_atomic_primitives" = "xnone"; then + AC_CHECK_HEADER([libkern/OSAtomic.h], + cairo_cv_atomic_primitives="OSAtomic") + fi ]) if test "x$cairo_cv_atomic_primitives" = xIntel; then AC_DEFINE(HAVE_INTEL_ATOMIC_PRIMITIVES, 1, @@ -184,6 +189,11 @@ int atomic_cmpxchg(int i, int j, int k) { return __sync_val_compare_and_swap (&i AC_DEFINE(HAVE_LIB_ATOMIC_OPS, 1, [Enable if you have libatomic-ops-dev installed]) fi + + if test "x$cairo_cv_atomic_primitives" = xOSAtomic; then + AC_DEFINE(HAVE_OS_ATOMIC_OPS, 1, + [Enable if you have MacOS X atomic operations]) + fi ]) dnl Usage: diff --git a/src/cairo-atomic-private.h b/src/cairo-atomic-private.h index 7dd02544..4fcb1887 100644 --- a/src/cairo-atomic-private.h +++ b/src/cairo-atomic-private.h @@ -111,6 +111,36 @@ typedef unsigned long long cairo_atomic_intptr_t; #endif +#if HAVE_OS_ATOMIC_OPS +#include <libkern/OSAtomic.h> + +#define HAS_ATOMIC_OPS 1 + +typedef int32_t cairo_atomic_int_t; + +# define _cairo_atomic_int_get(x) (OSMemoryBarrier(), *(x)) + +# define _cairo_atomic_int_inc(x) ((void) OSAtomicIncrement32Barrier (x)) +# define _cairo_atomic_int_dec_and_test(x) (OSAtomicDecrement32Barrier (x) == 0) +# define _cairo_atomic_int_cmpxchg(x, oldv, newv) OSAtomicCompareAndSwap32Barrier(oldv, newv, x) + +#if SIZEOF_VOID_P==4 +typedef int32_t cairo_atomic_intptr_t; +# define _cairo_atomic_ptr_cmpxchg(x, oldv, newv) \ + OSAtomicCompareAndSwap32Barrier((cairo_atomic_intptr_t)oldv, (cairo_atomic_intptr_t)newv, (cairo_atomic_intptr_t *)x) + +#elif SIZEOF_VOID_P==8 +typedef int64_t cairo_atomic_intptr_t; +# define _cairo_atomic_ptr_cmpxchg(x, oldv, newv) \ + OSAtomicCompareAndSwap64Barrier((cairo_atomic_intptr_t)oldv, (cairo_atomic_intptr_t)newv, (cairo_atomic_intptr_t *)x) + +#else +#error No matching integer pointer type +#endif + +# define _cairo_atomic_ptr_get(x) (OSMemoryBarrier(), *(x)) + +#endif #ifndef HAS_ATOMIC_OPS |