Add atomic ops for Solaris

Patch from Raimund Steger.
This commit is contained in:
Behdad Esfahbod 2013-01-10 01:17:02 -06:00
parent 8e8a99ae8a
commit 98efed3bca
2 changed files with 32 additions and 2 deletions

View File

@ -592,8 +592,26 @@ if $fc_cv_have_intel_atomic_primitives; then
AC_DEFINE(HAVE_INTEL_ATOMIC_PRIMITIVES, 1, [Have Intel __sync_* atomic primitives])
fi
AC_CACHE_CHECK([for Solaris atomic operations], fc_cv_have_solaris_atomic_ops, [
fc_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); }
], [], fc_cv_have_solaris_atomic_ops=true
)
])
if $fc_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_CHECK_FUNCS(sched_yield)
AC_SEARCH_LIBS(sched_yield,rt,AC_DEFINE(HAVE_SCHED_YIELD, 1, [Have sched_yield]))
fi
have_pthread=false
if test "$os_win32" = no; then

View File

@ -87,6 +87,18 @@ typedef int fc_atomic_int_t;
#define fc_atomic_ptr_cmpexch(P,O,N) __sync_bool_compare_and_swap ((P), (O), (N))
#elif !defined(FC_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(FC_NO_MT)
#define FC_ATOMIC_INT_NIL 1 /* Warn that fallback implementation is in use. */