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>
This commit is contained in:
Andrea Canciani 2010-04-28 17:23:47 +02:00
parent 56a367a162
commit 248af38b3e
2 changed files with 40 additions and 0 deletions

View file

@ -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:

View file

@ -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