summaryrefslogtreecommitdiff
path: root/atomic
diff options
context:
space:
mode:
authorcolm <colm@13f79535-47bb-0310-9956-ffa450edef68>2006-06-13 02:22:05 +0000
committercolm <colm@13f79535-47bb-0310-9956-ffa450edef68>2006-06-13 02:22:05 +0000
commitef3530173e826b33b3796d7f1218a4fecac570f3 (patch)
tree9faf68d499dd5678fee9233847b3eea49cc7ef06 /atomic
parent06968a35a6e2acf96378737d5e5edabff3064cc5 (diff)
downloadlibapr-ef3530173e826b33b3796d7f1218a4fecac570f3.tar.gz
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
Diffstat (limited to 'atomic')
-rw-r--r--atomic/unix/apr_atomic.c55
1 files changed, 55 insertions, 0 deletions
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 <stdlib.h>
+#if (defined(SOLARIS2) && SOLARIS2 >= 10)
+#include <atomic.h>
+#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