Add atomic ops for Solaris
authorBehdad Esfahbod <behdad@behdad.org>
Thu, 10 Jan 2013 07:17:59 +0000 (01:17 -0600)
committerBehdad Esfahbod <behdad@behdad.org>
Thu, 10 Jan 2013 07:18:10 +0000 (01:18 -0600)
Based on fontconfig patch from Raimund Steger.

config.h.in
configure.ac
src/hb-atomic-private.hh

index 0973c93..4b5c99a 100644 (file)
 /* Define to 1 if you have the <sched.h> header file. */
 #undef HAVE_SCHED_H
 
-/* Define to 1 if you have the `sched_yield' function. */
+/* Have sched_yield */
 #undef HAVE_SCHED_YIELD
 
+/* Have Solaris __machine_*_barrier and atomic_* operations */
+#undef HAVE_SOLARIS_ATOMIC_OPS
+
 /* Define to 1 if you have the <stdint.h> header file. */
 #undef HAVE_STDINT_H
 
index 8b74b45..c5a7f13 100644 (file)
@@ -55,8 +55,8 @@ dnl GOBJECT_INTROSPECTION_CHECK([0.9.0])
 dnl GTK_DOC_CHECK([1.15],[--flavour no-tmpl])
 
 # Functions and headers
-AC_CHECK_FUNCS(atexit mprotect sysconf getpagesize sched_yield mmap _setmode isatty)
-AC_CHECK_HEADERS(unistd.h sys/mman.h sched.h io.h)
+AC_CHECK_FUNCS(atexit mprotect sysconf getpagesize mmap _setmode isatty)
+AC_CHECK_HEADERS(unistd.h sys/mman.h io.h)
 
 # Compiler flags
 AC_CANONICAL_HOST
@@ -261,6 +261,29 @@ fi
 
 dnl ===========================================================================
 
+AC_CACHE_CHECK([for Solaris atomic operations], hb_cv_have_solaris_atomic_ops, [
+       hb_cv_have_solaris_atomic_ops=false
+       AC_TRY_LINK([
+               #include <atomic.h>
+               /* This requires Solaris Studio 12.2 or newer: */
+               #include <mbarrier.h>
+               void memory_barrier (void) { __machine_rw_barrier (); }
+               int atomic_add (volatile unsigned *i) { return atomic_add_int_nv (i, 1); }
+               void *atomic_ptr_cmpxchg (volatile void **target, void *cmp, void *newval) { return atomic_cas_ptr (target, cmp, newval); }
+               ], [], hb_cv_have_solaris_atomic_ops=true
+       )
+])
+if $hb_cv_have_solaris_atomic_ops; then
+       AC_DEFINE(HAVE_SOLARIS_ATOMIC_OPS, 1, [Have Solaris __machine_*_barrier and atomic_* operations])
+fi
+
+if test "$os_win32" = no && ! $have_pthread; then
+       AC_CHECK_HEADERS(sched.h)
+       AC_SEARCH_LIBS(sched_yield,rt,AC_DEFINE(HAVE_SCHED_YIELD, 1, [Have sched_yield]))
+fi
+
+dnl ===========================================================================
+
 AC_CONFIG_FILES([
 Makefile
 harfbuzz.pc
index 67579cd..75fbcd6 100644 (file)
@@ -99,6 +99,18 @@ typedef int hb_atomic_int_t;
 #define hb_atomic_ptr_cmpexch(P,O,N)   __sync_bool_compare_and_swap ((P), (O), (N))
 
 
+#elif !defined(HB_NO_MT) && defined(HAVE_SOLARIS_ATOMIC_OPS)
+
+#include <atomic.h>
+#include <mbarrier.h>
+
+typedef unsigned int fc_atomic_int_t;
+#define fc_atomic_int_add(AI, V)       ( ({__machine_rw_barrier ();}), atomic_add_int_nv (&(AI), (V)) - (V))
+
+#define fc_atomic_ptr_get(P)           ( ({__machine_rw_barrier ();}), (void *) *(P))
+#define fc_atomic_ptr_cmpexch(P,O,N)   ( ({__machine_rw_barrier ();}), atomic_cas_ptr ((P), (O), (N)) == (void *) (O) ? FcTrue : FcFalse)
+
+
 #elif !defined(HB_NO_MT)
 
 #define HB_ATOMIC_INT_NIL 1 /* Warn that fallback implementation is in use. */