From ef3530173e826b33b3796d7f1218a4fecac570f3 Mon Sep 17 00:00:00 2001 From: colm Date: Tue, 13 Jun 2006 02:22:05 +0000 Subject: Implement apr_atomics using Solaris' native atomic API. * Use each of the atomic_ functions that we can. * atomic_add is NOT implemented, as Solaris' implementation can handle only signed deltas. * each function is conditionalised on its corresponding APR_OVERRIDE_* macro to avoid double-implementation. On Solaris x86/x64 with gcc we implement atomics using our inline assembly. Thank to: Mads Toftum for pointing out atomic_cas git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@413786 13f79535-47bb-0310-9956-ffa450edef68 --- atomic/unix/apr_atomic.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'atomic') diff --git a/atomic/unix/apr_atomic.c b/atomic/unix/apr_atomic.c index 5484eba0a..b06bf2ac8 100644 --- a/atomic/unix/apr_atomic.c +++ b/atomic/unix/apr_atomic.c @@ -21,6 +21,9 @@ #include "apr_private.h" #include +#if (defined(SOLARIS2) && SOLARIS2 >= 10) +#include +#endif #if defined(__GNUC__) && defined(__STRICT_ANSI__) && !defined(USE_GENERIC_ATOMICS) /* force use of generic atomics if building e.g. with -std=c89, which @@ -162,6 +165,58 @@ APR_DECLARE(apr_uint32_t) apr_atomic_add32(volatile apr_uint32_t *mem, #endif /* __PPC__ && __GNUC__ */ +#if (defined(SOLARIS2) && SOLARIS2 >= 10) \ + && !defined(USE_GENERIC_ATOMICS) + +#if !defined(APR_OVERRIDE_ATOMIC_CAS32) +APR_DECLARE(apr_uint32_t) apr_atomic_cas32(volatile apr_uint32_t *mem, + apr_uint32_t with, + apr_uint32_t cmp) +{ + return atomic_cas_32(mem, cmp, with); +} +#define APR_OVERRIDE_ATOMIC_CAS32 +#endif /* APR_OVERRIDE_ATOMIC_CAS32 */ + +#if !defined(APR_OVERRIDE_ATOMIC_DEC32) +APR_DECLARE(apr_uint32_t) apr_atomic_dec32(volatile apr_uint32_t *mem) +{ + apr_uint32_t prev = *mem; + atomic_dec_32(mem); + return prev != 1; +} +#define APR_OVERRIDE_ATOMIC_DEC32 +#endif /* APR_OVERRIDE_ATOMIC_DEC32 */ + +#if !defined(APR_OVERRIDE_ATOMIC_INC32) +APR_DECLARE(apr_uint32_t) apr_atomic_inc32(volatile apr_uint32_t *mem) +{ + apr_uint32_t prev = *mem; + atomic_inc_32(mem); + return prev; +} +#define APR_OVERRIDE_ATOMIC_INC32 +#endif /* APR_OVERRIDE_ATOMIC_INC32 */ + +#if !defined(APR_OVERRIDE_ATOMIC_SET32) +APR_DECLARE(void) apr_atomic_set32(volatile apr_uint32_t *mem, apr_uint32_t val) +{ + *mem = val; +} +#define APR_OVERRIDE_ATOMIC_SET32 +#endif /* APR_OVERRIDE_ATOMIC_SET32 */ + +#if !defined(APR_OVERRIDE_ATOMIC_XCHG32) +APR_DECLARE(apr_uint32_t) apr_atomic_xchg32(volatile apr_uint32_t *mem, + apr_uint32_t val) +{ + return atomic_swap_32(mem, val); +} +#define APR_OVERRIDE_ATOMIC_XCHG32 +#endif /* APR_OVERRIDE_ATOMIC_XCHG32 */ + +#endif /* SOLARIS2 && SOLARIS2 >= 10 */ + #if !defined(APR_OVERRIDE_ATOMIC_INIT) #if APR_HAS_THREADS -- cgit v1.2.1