[cairo-commit] 2 commits - src/cairo-atomic.c src/cairo-atomic-private.h test/cairo-test.c
M. Joonas Pihlaja
joonas at kemper.freedesktop.org
Sun Jun 21 08:38:15 PDT 2009
src/cairo-atomic-private.h | 9 ++++++++-
src/cairo-atomic.c | 6 +++++-
test/cairo-test.c | 2 +-
3 files changed, 14 insertions(+), 3 deletions(-)
New commits:
commit a2d4fb50092c0cbb31a5df1bca9111957238139b
Author: M Joonas Pihlaja <jpihlaja at cc.helsinki.fi>
Date: Sun Jun 21 14:09:10 2009 +0100
[test] Fix a typo in the _POSIX_SOURCE version number.
I hope POSIX isn't around in 20000 AD!
diff --git a/test/cairo-test.c b/test/cairo-test.c
index 87a5940..715210f 100644
--- a/test/cairo-test.c
+++ b/test/cairo-test.c
@@ -26,7 +26,7 @@
*/
#define _GNU_SOURCE 1 /* for feenableexcept() et al */
-#define _POSIX_C_SOURCE 2000112L /* for flockfile() et al */
+#define _POSIX_C_SOURCE 200112L /* for flockfile() et al */
#if HAVE_CONFIG_H
#include "config.h"
commit 80990c7f729a666fc646182a36ffd311d7396a1a
Author: M Joonas Pihlaja <jpihlaja at cc.helsinki.fi>
Date: Sun Jun 21 14:02:46 2009 +0100
[atomic] Use an integer __sync_val_compare_and_swap() for pointer CAS.
Fix an implicit pointer/integer cast in _cairo_atomic_ptr_cmpxchg()
when building with LLVM/clang.
The Intel synchronization primitives __sync_val_compare_and_swap()
are only defined by Intel for types int, long, long long and their
unsigned variants. This patch uses one of those for
_cairo_atomic_ptr_cmpxchg() instead of relying on a gcc extension of
__sync_val_compare_and_swap() to pointer types.
diff --git a/src/cairo-atomic-private.h b/src/cairo-atomic-private.h
index 108cb39..10860fe 100644
--- a/src/cairo-atomic-private.h
+++ b/src/cairo-atomic-private.h
@@ -54,8 +54,15 @@ typedef int cairo_atomic_int_t;
# define _cairo_atomic_int_inc(x) ((void) __sync_fetch_and_add(x, 1))
# define _cairo_atomic_int_dec_and_test(x) (__sync_fetch_and_add(x, -1) == 1)
# define _cairo_atomic_int_cmpxchg(x, oldv, newv) __sync_val_compare_and_swap (x, oldv, newv)
-# define _cairo_atomic_ptr_cmpxchg(x, oldv, newv) __sync_val_compare_and_swap (x, oldv, newv)
+# define _cairo_atomic_ptr_cmpxchg(x, oldv, newv) \
+ (sizeof(void*) == sizeof(int) ?\
+ (void*)__sync_val_compare_and_swap ((int*)x, (int)oldv, (int)newv) :\
+ sizeof(void*) == sizeof(long) ?\
+ (void*)__sync_val_compare_and_swap ((long*)x, (long)oldv, (long)newv) :\
+ sizeof(void*) == sizeof(long long) ?\
+ (void*)__sync_val_compare_and_swap ((long long*)x, (long long)oldv, (long long)newv) :\
+ (void*)(oldv)/*impossible*/)
#endif
diff --git a/src/cairo-atomic.c b/src/cairo-atomic.c
index 777ba5c..146ad85 100644
--- a/src/cairo-atomic.c
+++ b/src/cairo-atomic.c
@@ -36,7 +36,11 @@
#include "cairo-atomic-private.h"
#include "cairo-mutex-private.h"
-#ifndef HAS_ATOMIC_OPS
+#ifdef HAS_ATOMIC_OPS
+COMPILE_TIME_ASSERT(sizeof(void*) == sizeof(int) ||
+ sizeof(void*) == sizeof(long) ||
+ sizeof(void*) == sizeof(long long));
+#else
void
_cairo_atomic_int_inc (int *x)
{
More information about the cairo-commit
mailing list