Add atomic ops for Solaris

Based on fontconfig patch from Raimund Steger.
This commit is contained in:
Behdad Esfahbod 2013-01-10 01:17:59 -06:00
parent 69fd6e157c
commit 2dcb333f52
3 changed files with 41 additions and 3 deletions

View File

@ -78,9 +78,12 @@
/* Define to 1 if you have the <sched.h> header file. */ /* Define to 1 if you have the <sched.h> header file. */
#undef HAVE_SCHED_H #undef HAVE_SCHED_H
/* Define to 1 if you have the `sched_yield' function. */ /* Have sched_yield */
#undef 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. */ /* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H #undef HAVE_STDINT_H

View File

@ -55,8 +55,8 @@ dnl GOBJECT_INTROSPECTION_CHECK([0.9.0])
dnl GTK_DOC_CHECK([1.15],[--flavour no-tmpl]) dnl GTK_DOC_CHECK([1.15],[--flavour no-tmpl])
# Functions and headers # Functions and headers
AC_CHECK_FUNCS(atexit mprotect sysconf getpagesize sched_yield mmap _setmode isatty) AC_CHECK_FUNCS(atexit mprotect sysconf getpagesize mmap _setmode isatty)
AC_CHECK_HEADERS(unistd.h sys/mman.h sched.h io.h) AC_CHECK_HEADERS(unistd.h sys/mman.h io.h)
# Compiler flags # Compiler flags
AC_CANONICAL_HOST AC_CANONICAL_HOST
@ -261,6 +261,29 @@ fi
dnl =========================================================================== 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([ AC_CONFIG_FILES([
Makefile Makefile
harfbuzz.pc harfbuzz.pc

View 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)) #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) #elif !defined(HB_NO_MT)
#define HB_ATOMIC_INT_NIL 1 /* Warn that fallback implementation is in use. */ #define HB_ATOMIC_INT_NIL 1 /* Warn that fallback implementation is in use. */