summaryrefslogtreecommitdiff
path: root/srclib/apr/atomic/unix
diff options
context:
space:
mode:
Diffstat (limited to 'srclib/apr/atomic/unix')
-rw-r--r--srclib/apr/atomic/unix/apr_atomic.c409
-rw-r--r--srclib/apr/atomic/unix/builtins.c81
-rw-r--r--srclib/apr/atomic/unix/ia32.c127
-rw-r--r--srclib/apr/atomic/unix/mutex.c205
-rw-r--r--srclib/apr/atomic/unix/ppc.c207
-rw-r--r--srclib/apr/atomic/unix/s390.c155
-rw-r--r--srclib/apr/atomic/unix/solaris.c79
7 files changed, 854 insertions, 409 deletions
diff --git a/srclib/apr/atomic/unix/apr_atomic.c b/srclib/apr/atomic/unix/apr_atomic.c
deleted file mode 100644
index ed85a429..00000000
--- a/srclib/apr/atomic/unix/apr_atomic.c
+++ /dev/null
@@ -1,409 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "apr.h"
-#include "apr_atomic.h"
-#include "apr_thread_mutex.h"
-
-#include "apr_private.h"
-
-#include <stdlib.h>
-
-#if defined(__GNUC__) && defined(__STRICT_ANSI__) && !defined(USE_GENERIC_ATOMICS)
-/* force use of generic atomics if building e.g. with -std=c89, which
- * doesn't allow inline asm */
-#define USE_GENERIC_ATOMICS
-#endif
-
-#if (defined(__i386__) || defined(__x86_64__)) \
- && defined(__GNUC__) && !defined(USE_GENERIC_ATOMICS)
-
-APR_DECLARE(apr_uint32_t) apr_atomic_cas32(volatile apr_uint32_t *mem,
- apr_uint32_t with,
- apr_uint32_t cmp)
-{
- apr_uint32_t prev;
-
- asm volatile ("lock; cmpxchgl %1, %2"
- : "=a" (prev)
- : "r" (with), "m" (*(mem)), "0"(cmp)
- : "memory", "cc");
- return prev;
-}
-#define APR_OVERRIDE_ATOMIC_CAS32
-
-static apr_uint32_t inline intel_atomic_add32(volatile apr_uint32_t *mem,
- apr_uint32_t val)
-{
- asm volatile ("lock; xaddl %0,%1"
- : "=r"(val), "=m"(*mem) /* outputs */
- : "0"(val), "m"(*mem) /* inputs */
- : "memory", "cc");
- return val;
-}
-
-APR_DECLARE(apr_uint32_t) apr_atomic_add32(volatile apr_uint32_t *mem,
- apr_uint32_t val)
-{
- return intel_atomic_add32(mem, val);
-}
-#define APR_OVERRIDE_ATOMIC_ADD32
-
-APR_DECLARE(void) apr_atomic_sub32(volatile apr_uint32_t *mem, apr_uint32_t val)
-{
- asm volatile ("lock; subl %1, %0"
- :
- : "m" (*(mem)), "r" (val)
- : "memory", "cc");
-}
-#define APR_OVERRIDE_ATOMIC_SUB32
-
-APR_DECLARE(int) apr_atomic_dec32(volatile apr_uint32_t *mem)
-{
- unsigned char prev;
-
- asm volatile ("lock; decl %1;\n\t"
- "setnz %%al"
- : "=a" (prev)
- : "m" (*(mem))
- : "memory", "cc");
- return prev;
-}
-#define APR_OVERRIDE_ATOMIC_DEC32
-
-APR_DECLARE(apr_uint32_t) apr_atomic_inc32(volatile apr_uint32_t *mem)
-{
- return intel_atomic_add32(mem, 1);
-}
-#define APR_OVERRIDE_ATOMIC_INC32
-
-APR_DECLARE(void) apr_atomic_set32(volatile apr_uint32_t *mem, apr_uint32_t val)
-{
- *mem = val;
-}
-#define APR_OVERRIDE_ATOMIC_SET32
-
-APR_DECLARE(apr_uint32_t) apr_atomic_xchg32(volatile apr_uint32_t *mem, apr_uint32_t val)
-{
- apr_uint32_t prev = val;
-
- asm volatile ("lock; xchgl %0, %1"
- : "=r" (prev)
- : "m" (*(mem)), "0"(prev)
- : "memory");
- return prev;
-}
-#define APR_OVERRIDE_ATOMIC_XCHG32
-
-/*#define apr_atomic_init(pool) APR_SUCCESS*/
-
-#endif /* (__linux__ || __EMX__ || __FreeBSD__) && __i386__ */
-
-#if (defined(__PPC__) || defined(__ppc__)) && defined(__GNUC__) \
- && !defined(USE_GENERIC_ATOMICS)
-
-APR_DECLARE(apr_uint32_t) apr_atomic_cas32(volatile apr_uint32_t *mem,
- apr_uint32_t swap,
- apr_uint32_t cmp)
-{
- apr_uint32_t prev;
-
- asm volatile ("0:\n\t" /* retry local label */
- "lwarx %0,0,%1\n\t" /* load prev and reserve */
- "cmpw %0,%3\n\t" /* does it match cmp? */
- "bne- 1f\n\t" /* ...no, bail out */
- "stwcx. %2,0,%1\n\t" /* ...yes, conditionally
- store swap */
- "bne- 0b\n\t" /* start over if we lost
- the reservation */
- "1:" /* exit local label */
-
- : "=&r"(prev) /* output */
- : "b" (mem), "r" (swap), "r"(cmp) /* inputs */
- : "memory", "cc"); /* clobbered */
- return prev;
-}
-#define APR_OVERRIDE_ATOMIC_CAS32
-
-APR_DECLARE(apr_uint32_t) apr_atomic_add32(volatile apr_uint32_t *mem,
- apr_uint32_t delta)
-{
- apr_uint32_t prev, temp;
-
- asm volatile ("0:\n\t" /* retry local label */
- "lwarx %0,0,%2\n\t" /* load prev and reserve */
- "add %1,%0,%3\n\t" /* temp = prev + delta */
- "stwcx. %1,0,%2\n\t" /* conditionally store */
- "bne- 0b" /* start over if we lost
- the reservation */
-
- /*XXX find a cleaner way to define the temp
- * it's not an output
- */
- : "=&r" (prev), "=&r" (temp) /* output, temp */
- : "b" (mem), "r" (delta) /* inputs */
- : "memory", "cc"); /* clobbered */
- return prev;
-}
-#define APR_OVERRIDE_ATOMIC_ADD32
-
-#endif /* __PPC__ && __GNUC__ */
-
-#if !defined(APR_OVERRIDE_ATOMIC_INIT)
-
-#if APR_HAS_THREADS
-#define NUM_ATOMIC_HASH 7
-/* shift by 2 to get rid of alignment issues */
-#define ATOMIC_HASH(x) (unsigned int)(((unsigned long)(x)>>2)%(unsigned int)NUM_ATOMIC_HASH)
-static apr_thread_mutex_t **hash_mutex;
-#endif /* APR_HAS_THREADS */
-
-#if APR_HAS_THREADS
-static apr_status_t atomic_cleanup(void *data)
-{
- if (hash_mutex == data)
- hash_mutex = NULL;
-
- return APR_SUCCESS;
-}
-#endif
-
-apr_status_t apr_atomic_init(apr_pool_t *p)
-{
-#if APR_HAS_THREADS
- int i;
- apr_status_t rv;
-
- if (hash_mutex != NULL)
- return APR_SUCCESS;
-
- hash_mutex = apr_palloc(p, sizeof(apr_thread_mutex_t*) * NUM_ATOMIC_HASH);
- apr_pool_cleanup_register(p, hash_mutex, atomic_cleanup,
- apr_pool_cleanup_null);
-
- for (i = 0; i < NUM_ATOMIC_HASH; i++) {
- rv = apr_thread_mutex_create(&(hash_mutex[i]),
- APR_THREAD_MUTEX_DEFAULT, p);
- if (rv != APR_SUCCESS) {
- return rv;
- }
- }
-#endif /* APR_HAS_THREADS */
- return APR_SUCCESS;
-}
-#endif /* !defined(APR_OVERRIDE_ATOMIC_INIT) */
-
-/* abort() if 'x' does not evaluate to APR_SUCCESS. */
-#define CHECK(x) do { if ((x) != APR_SUCCESS) abort(); } while (0)
-
-#if !defined(APR_OVERRIDE_ATOMIC_ADD32)
-#if defined(APR_OVERRIDE_ATOMIC_CAS32)
-apr_uint32_t apr_atomic_add32(volatile apr_uint32_t *mem, apr_uint32_t val)
-{
- apr_uint32_t old_value, new_value;
-
- do {
- old_value = *mem;
- new_value = old_value + val;
- } while (apr_atomic_cas32(mem, new_value, old_value) != old_value);
- return old_value;
-}
-#else
-apr_uint32_t apr_atomic_add32(volatile apr_uint32_t *mem, apr_uint32_t val)
-{
- apr_uint32_t old_value;
-
-#if APR_HAS_THREADS
- apr_thread_mutex_t *lock = hash_mutex[ATOMIC_HASH(mem)];
-
- CHECK(apr_thread_mutex_lock(lock));
- old_value = *mem;
- *mem += val;
- CHECK(apr_thread_mutex_unlock(lock));
-#else
- old_value = *mem;
- *mem += val;
-#endif /* APR_HAS_THREADS */
- return old_value;
-}
-#endif /* defined(APR_OVERRIDE_ATOMIC_CAS32) */
-#endif /* !defined(APR_OVERRIDE_ATOMIC_ADD32) */
-
-#if !defined(APR_OVERRIDE_ATOMIC_SUB32)
-#if defined(APR_OVERRIDE_ATOMIC_CAS32)
-void apr_atomic_sub32(volatile apr_uint32_t *mem, apr_uint32_t val)
-{
- apr_uint32_t old_value, new_value;
-
- do {
- old_value = *mem;
- new_value = old_value - val;
- } while (apr_atomic_cas32(mem, new_value, old_value) != old_value);
-}
-#else
-void apr_atomic_sub32(volatile apr_uint32_t *mem, apr_uint32_t val)
-{
-#if APR_HAS_THREADS
- apr_thread_mutex_t *lock = hash_mutex[ATOMIC_HASH(mem)];
-
- CHECK(apr_thread_mutex_lock(lock));
- *mem -= val;
- CHECK(apr_thread_mutex_unlock(lock));
-#else
- *mem -= val;
-#endif /* APR_HAS_THREADS */
-}
-#endif /* defined(APR_OVERRIDE_ATOMIC_CAS32) */
-#endif /* !defined(APR_OVERRIDE_ATOMIC_SUB32) */
-
-#if !defined(APR_OVERRIDE_ATOMIC_SET32)
-void apr_atomic_set32(volatile apr_uint32_t *mem, apr_uint32_t val)
-{
-#if APR_HAS_THREADS
- apr_thread_mutex_t *lock = hash_mutex[ATOMIC_HASH(mem)];
-
- CHECK(apr_thread_mutex_lock(lock));
- *mem = val;
- CHECK(apr_thread_mutex_unlock(lock));
-#else
- *mem = val;
-#endif /* APR_HAS_THREADS */
-}
-#endif /* !defined(APR_OVERRIDE_ATOMIC_SET32) */
-
-#if !defined(APR_OVERRIDE_ATOMIC_INC32)
-apr_uint32_t apr_atomic_inc32(volatile apr_uint32_t *mem)
-{
- return apr_atomic_add32(mem, 1);
-}
-#endif /* !defined(APR_OVERRIDE_ATOMIC_INC32) */
-
-#if !defined(APR_OVERRIDE_ATOMIC_DEC32)
-#if defined(APR_OVERRIDE_ATOMIC_CAS32)
-int apr_atomic_dec32(volatile apr_uint32_t *mem)
-{
- apr_uint32_t old_value, new_value;
-
- do {
- old_value = *mem;
- new_value = old_value - 1;
- } while (apr_atomic_cas32(mem, new_value, old_value) != old_value);
- return old_value != 1;
-}
-#else
-int apr_atomic_dec32(volatile apr_uint32_t *mem)
-{
-#if APR_HAS_THREADS
- apr_thread_mutex_t *lock = hash_mutex[ATOMIC_HASH(mem)];
- apr_uint32_t new;
-
- CHECK(apr_thread_mutex_lock(lock));
- (*mem)--;
- new = *mem;
- CHECK(apr_thread_mutex_unlock(lock));
- return new;
-#else
- (*mem)--;
- return *mem;
-#endif /* APR_HAS_THREADS */
-}
-#endif /* defined(APR_OVERRIDE_ATOMIC_CAS32) */
-#endif /* !defined(APR_OVERRIDE_ATOMIC_DEC32) */
-
-#if !defined(APR_OVERRIDE_ATOMIC_CAS32)
-apr_uint32_t apr_atomic_cas32(volatile apr_uint32_t *mem, apr_uint32_t with,
- apr_uint32_t cmp)
-{
- apr_uint32_t prev;
-#if APR_HAS_THREADS
- apr_thread_mutex_t *lock = hash_mutex[ATOMIC_HASH(mem)];
-
- CHECK(apr_thread_mutex_lock(lock));
- prev = *mem;
- if (prev == cmp) {
- *mem = with;
- }
- CHECK(apr_thread_mutex_unlock(lock));
-#else
- prev = *mem;
- if (prev == cmp) {
- *mem = with;
- }
-#endif /* APR_HAS_THREADS */
- return prev;
-}
-#endif /* !defined(APR_OVERRIDE_ATOMIC_CAS32) */
-
-#if !defined(APR_OVERRIDE_ATOMIC_XCHG32)
-#if defined(APR_OVERRIDE_ATOMIC_CAS32)
-apr_uint32_t apr_atomic_xchg32(volatile apr_uint32_t *mem, apr_uint32_t val)
-{
- apr_uint32_t prev;
- do {
- prev = *mem;
- } while (apr_atomic_cas32(mem, val, prev) != prev);
- return prev;
-}
-#else
-apr_uint32_t apr_atomic_xchg32(volatile apr_uint32_t *mem, apr_uint32_t val)
-{
- apr_uint32_t prev;
-#if APR_HAS_THREADS
- apr_thread_mutex_t *lock = hash_mutex[ATOMIC_HASH(mem)];
-
- CHECK(apr_thread_mutex_lock(lock));
- prev = *mem;
- *mem = val;
- CHECK(apr_thread_mutex_unlock(lock));
-#else
- prev = *mem;
- *mem = val;
-#endif /* APR_HAS_THREADS */
- return prev;
-}
-#endif /* defined(APR_OVERRIDE_ATOMIC_CAS32) */
-#endif /* !defined(APR_OVERRIDE_ATOMIC_XCHG32) */
-
-#if !defined(APR_OVERRIDE_ATOMIC_CASPTR)
-void *apr_atomic_casptr(volatile void **mem, void *with, const void *cmp)
-{
- void *prev;
-#if APR_HAS_THREADS
- apr_thread_mutex_t *lock = hash_mutex[ATOMIC_HASH(mem)];
-
- CHECK(apr_thread_mutex_lock(lock));
- prev = *(void **)mem;
- if (prev == cmp) {
- *mem = with;
- }
- CHECK(apr_thread_mutex_unlock(lock));
-#else
- prev = *(void **)mem;
- if (prev == cmp) {
- *mem = with;
- }
-#endif /* APR_HAS_THREADS */
- return prev;
-}
-#endif /* !defined(APR_OVERRIDE_ATOMIC_CASPTR) */
-
-#if !defined(APR_OVERRIDE_ATOMIC_READ32)
-APR_DECLARE(apr_uint32_t) apr_atomic_read32(volatile apr_uint32_t *mem)
-{
- return *mem;
-}
-#endif
-
diff --git a/srclib/apr/atomic/unix/builtins.c b/srclib/apr/atomic/unix/builtins.c
new file mode 100644
index 00000000..745acf15
--- /dev/null
+++ b/srclib/apr/atomic/unix/builtins.c
@@ -0,0 +1,81 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "apr_arch_atomic.h"
+
+#ifdef USE_ATOMICS_BUILTINS
+
+APR_DECLARE(apr_status_t) apr_atomic_init(apr_pool_t *p)
+{
+ return APR_SUCCESS;
+}
+
+APR_DECLARE(apr_uint32_t) apr_atomic_read32(volatile apr_uint32_t *mem)
+{
+ return *mem;
+}
+
+APR_DECLARE(void) apr_atomic_set32(volatile apr_uint32_t *mem, apr_uint32_t val)
+{
+ *mem = val;
+}
+
+APR_DECLARE(apr_uint32_t) apr_atomic_add32(volatile apr_uint32_t *mem, apr_uint32_t val)
+{
+ return __sync_fetch_and_add(mem, val);
+}
+
+APR_DECLARE(void) apr_atomic_sub32(volatile apr_uint32_t *mem, apr_uint32_t val)
+{
+ __sync_fetch_and_sub(mem, val);
+}
+
+APR_DECLARE(apr_uint32_t) apr_atomic_inc32(volatile apr_uint32_t *mem)
+{
+ return __sync_fetch_and_add(mem, 1);
+}
+
+APR_DECLARE(int) apr_atomic_dec32(volatile apr_uint32_t *mem)
+{
+ return __sync_sub_and_fetch(mem, 1);
+}
+
+APR_DECLARE(apr_uint32_t) apr_atomic_cas32(volatile apr_uint32_t *mem, apr_uint32_t with,
+ apr_uint32_t cmp)
+{
+ return __sync_val_compare_and_swap(mem, cmp, with);
+}
+
+APR_DECLARE(apr_uint32_t) apr_atomic_xchg32(volatile apr_uint32_t *mem, apr_uint32_t val)
+{
+ __sync_synchronize();
+
+ return __sync_lock_test_and_set(mem, val);
+}
+
+APR_DECLARE(void*) apr_atomic_casptr(volatile void **mem, void *with, const void *cmp)
+{
+ return (void*) __sync_val_compare_and_swap(mem, cmp, with);
+}
+
+APR_DECLARE(void*) apr_atomic_xchgptr(volatile void **mem, void *with)
+{
+ __sync_synchronize();
+
+ return (void*) __sync_lock_test_and_set(mem, with);
+}
+
+#endif /* USE_ATOMICS_BUILTINS */
diff --git a/srclib/apr/atomic/unix/ia32.c b/srclib/apr/atomic/unix/ia32.c
new file mode 100644
index 00000000..3826f927
--- /dev/null
+++ b/srclib/apr/atomic/unix/ia32.c
@@ -0,0 +1,127 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "apr_arch_atomic.h"
+
+#ifdef USE_ATOMICS_IA32
+
+APR_DECLARE(apr_status_t) apr_atomic_init(apr_pool_t *p)
+{
+ return APR_SUCCESS;
+}
+
+APR_DECLARE(apr_uint32_t) apr_atomic_read32(volatile apr_uint32_t *mem)
+{
+ return *mem;
+}
+
+APR_DECLARE(void) apr_atomic_set32(volatile apr_uint32_t *mem, apr_uint32_t val)
+{
+ *mem = val;
+}
+
+APR_DECLARE(apr_uint32_t) apr_atomic_add32(volatile apr_uint32_t *mem, apr_uint32_t val)
+{
+ asm volatile ("lock; xaddl %0,%1"
+ : "=r" (val), "=m" (*mem)
+ : "0" (val), "m" (*mem)
+ : "memory", "cc");
+ return val;
+}
+
+APR_DECLARE(void) apr_atomic_sub32(volatile apr_uint32_t *mem, apr_uint32_t val)
+{
+ asm volatile ("lock; subl %1, %0"
+ : /* no output */
+ : "m" (*(mem)), "r" (val)
+ : "memory", "cc");
+}
+
+APR_DECLARE(apr_uint32_t) apr_atomic_inc32(volatile apr_uint32_t *mem)
+{
+ return apr_atomic_add32(mem, 1);
+}
+
+APR_DECLARE(int) apr_atomic_dec32(volatile apr_uint32_t *mem)
+{
+ unsigned char prev;
+
+ asm volatile ("lock; decl %0; setnz %1"
+ : "=m" (*mem), "=qm" (prev)
+ : "m" (*mem)
+ : "memory");
+
+ return prev;
+}
+
+APR_DECLARE(apr_uint32_t) apr_atomic_cas32(volatile apr_uint32_t *mem, apr_uint32_t with,
+ apr_uint32_t cmp)
+{
+ apr_uint32_t prev;
+
+ asm volatile ("lock; cmpxchgl %1, %2"
+ : "=a" (prev)
+ : "r" (with), "m" (*(mem)), "0"(cmp)
+ : "memory", "cc");
+ return prev;
+}
+
+APR_DECLARE(apr_uint32_t) apr_atomic_xchg32(volatile apr_uint32_t *mem, apr_uint32_t val)
+{
+ apr_uint32_t prev = val;
+
+ asm volatile ("xchgl %0, %1"
+ : "=r" (prev), "+m" (*mem)
+ : "0" (prev));
+ return prev;
+}
+
+APR_DECLARE(void*) apr_atomic_casptr(volatile void **mem, void *with, const void *cmp)
+{
+ void *prev;
+#if APR_SIZEOF_VOIDP == 4
+ asm volatile ("lock; cmpxchgl %2, %1"
+ : "=a" (prev), "=m" (*mem)
+ : "r" (with), "m" (*mem), "0" (cmp));
+#elif APR_SIZEOF_VOIDP == 8
+ asm volatile ("lock; cmpxchgq %q2, %1"
+ : "=a" (prev), "=m" (*mem)
+ : "r" ((unsigned long)with), "m" (*mem),
+ "0" ((unsigned long)cmp));
+#else
+#error APR_SIZEOF_VOIDP value not supported
+#endif
+ return prev;
+}
+
+APR_DECLARE(void*) apr_atomic_xchgptr(volatile void **mem, void *with)
+{
+ void *prev;
+#if APR_SIZEOF_VOIDP == 4
+ asm volatile ("xchgl %2, %1"
+ : "=a" (prev), "+m" (*mem)
+ : "0" (with));
+#elif APR_SIZEOF_VOIDP == 8
+ asm volatile ("xchgq %q2, %1"
+ : "=a" (prev), "+m" (*mem)
+ : "r" ((unsigned long)with));
+#else
+#error APR_SIZEOF_VOIDP value not supported
+#endif
+ return prev;
+}
+
+#endif /* USE_ATOMICS_IA32 */
diff --git a/srclib/apr/atomic/unix/mutex.c b/srclib/apr/atomic/unix/mutex.c
new file mode 100644
index 00000000..fba3be2b
--- /dev/null
+++ b/srclib/apr/atomic/unix/mutex.c
@@ -0,0 +1,205 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "apr_arch_atomic.h"
+
+#ifdef USE_ATOMICS_GENERIC
+
+#include <stdlib.h>
+
+#if APR_HAS_THREADS
+# define DECLARE_MUTEX_LOCKED(name, mem) \
+ apr_thread_mutex_t *name = mutex_hash(mem)
+# define MUTEX_UNLOCK(name) \
+ do { \
+ if (apr_thread_mutex_unlock(name) != APR_SUCCESS) \
+ abort(); \
+ } while (0)
+#else
+# define DECLARE_MUTEX_LOCKED(name, mem)
+# define MUTEX_UNLOCK(name)
+# warning Be warned: using stubs for all atomic operations
+#endif
+
+#if APR_HAS_THREADS
+
+static apr_thread_mutex_t **hash_mutex;
+
+#define NUM_ATOMIC_HASH 7
+/* shift by 2 to get rid of alignment issues */
+#define ATOMIC_HASH(x) (unsigned int)(((unsigned long)(x)>>2)%(unsigned int)NUM_ATOMIC_HASH)
+
+static apr_status_t atomic_cleanup(void *data)
+{
+ if (hash_mutex == data)
+ hash_mutex = NULL;
+
+ return APR_SUCCESS;
+}
+
+APR_DECLARE(apr_status_t) apr_atomic_init(apr_pool_t *p)
+{
+ int i;
+ apr_status_t rv;
+
+ if (hash_mutex != NULL)
+ return APR_SUCCESS;
+
+ hash_mutex = apr_palloc(p, sizeof(apr_thread_mutex_t*) * NUM_ATOMIC_HASH);
+ apr_pool_cleanup_register(p, hash_mutex, atomic_cleanup,
+ apr_pool_cleanup_null);
+
+ for (i = 0; i < NUM_ATOMIC_HASH; i++) {
+ rv = apr_thread_mutex_create(&(hash_mutex[i]),
+ APR_THREAD_MUTEX_DEFAULT, p);
+ if (rv != APR_SUCCESS) {
+ return rv;
+ }
+ }
+
+ return APR_SUCCESS;
+}
+
+static APR_INLINE apr_thread_mutex_t *mutex_hash(volatile apr_uint32_t *mem)
+{
+ apr_thread_mutex_t *mutex = hash_mutex[ATOMIC_HASH(mem)];
+
+ if (apr_thread_mutex_lock(mutex) != APR_SUCCESS) {
+ abort();
+ }
+
+ return mutex;
+}
+
+#else
+
+APR_DECLARE(apr_status_t) apr_atomic_init(apr_pool_t *p)
+{
+ return APR_SUCCESS;
+}
+
+#endif /* APR_HAS_THREADS */
+
+APR_DECLARE(apr_uint32_t) apr_atomic_read32(volatile apr_uint32_t *mem)
+{
+ return *mem;
+}
+
+APR_DECLARE(void) apr_atomic_set32(volatile apr_uint32_t *mem, apr_uint32_t val)
+{
+ DECLARE_MUTEX_LOCKED(mutex, mem);
+
+ *mem = val;
+
+ MUTEX_UNLOCK(mutex);
+}
+
+APR_DECLARE(apr_uint32_t) apr_atomic_add32(volatile apr_uint32_t *mem, apr_uint32_t val)
+{
+ apr_uint32_t old_value;
+ DECLARE_MUTEX_LOCKED(mutex, mem);
+
+ old_value = *mem;
+ *mem += val;
+
+ MUTEX_UNLOCK(mutex);
+
+ return old_value;
+}
+
+APR_DECLARE(void) apr_atomic_sub32(volatile apr_uint32_t *mem, apr_uint32_t val)
+{
+ DECLARE_MUTEX_LOCKED(mutex, mem);
+ *mem -= val;
+ MUTEX_UNLOCK(mutex);
+}
+
+APR_DECLARE(apr_uint32_t) apr_atomic_inc32(volatile apr_uint32_t *mem)
+{
+ return apr_atomic_add32(mem, 1);
+}
+
+APR_DECLARE(int) apr_atomic_dec32(volatile apr_uint32_t *mem)
+{
+ apr_uint32_t new;
+ DECLARE_MUTEX_LOCKED(mutex, mem);
+
+ (*mem)--;
+ new = *mem;
+
+ MUTEX_UNLOCK(mutex);
+
+ return new;
+}
+
+APR_DECLARE(apr_uint32_t) apr_atomic_cas32(volatile apr_uint32_t *mem, apr_uint32_t with,
+ apr_uint32_t cmp)
+{
+ apr_uint32_t prev;
+ DECLARE_MUTEX_LOCKED(mutex, mem);
+
+ prev = *mem;
+ if (prev == cmp) {
+ *mem = with;
+ }
+
+ MUTEX_UNLOCK(mutex);
+
+ return prev;
+}
+
+APR_DECLARE(apr_uint32_t) apr_atomic_xchg32(volatile apr_uint32_t *mem, apr_uint32_t val)
+{
+ apr_uint32_t prev;
+ DECLARE_MUTEX_LOCKED(mutex, mem);
+
+ prev = *mem;
+ *mem = val;
+
+ MUTEX_UNLOCK(mutex);
+
+ return prev;
+}
+
+APR_DECLARE(void*) apr_atomic_casptr(volatile void **mem, void *with, const void *cmp)
+{
+ void *prev;
+ DECLARE_MUTEX_LOCKED(mutex, *mem);
+
+ prev = *(void **)mem;
+ if (prev == cmp) {
+ *mem = with;
+ }
+
+ MUTEX_UNLOCK(mutex);
+
+ return prev;
+}
+
+APR_DECLARE(void*) apr_atomic_xchgptr(volatile void **mem, void *with)
+{
+ void *prev;
+ DECLARE_MUTEX_LOCKED(mutex, *mem);
+
+ prev = *(void **)mem;
+ *mem = with;
+
+ MUTEX_UNLOCK(mutex);
+
+ return prev;
+}
+
+#endif /* USE_ATOMICS_GENERIC */
diff --git a/srclib/apr/atomic/unix/ppc.c b/srclib/apr/atomic/unix/ppc.c
new file mode 100644
index 00000000..db9fca93
--- /dev/null
+++ b/srclib/apr/atomic/unix/ppc.c
@@ -0,0 +1,207 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "apr_arch_atomic.h"
+
+#ifdef USE_ATOMICS_PPC
+
+#ifdef PPC405_ERRATA
+# define PPC405_ERR77_SYNC " sync\n"
+#else
+# define PPC405_ERR77_SYNC
+#endif
+
+APR_DECLARE(apr_status_t) apr_atomic_init(apr_pool_t *p)
+{
+ return APR_SUCCESS;
+}
+
+APR_DECLARE(apr_uint32_t) apr_atomic_read32(volatile apr_uint32_t *mem)
+{
+ return *mem;
+}
+
+APR_DECLARE(void) apr_atomic_set32(volatile apr_uint32_t *mem, apr_uint32_t val)
+{
+ *mem = val;
+}
+
+APR_DECLARE(apr_uint32_t) apr_atomic_add32(volatile apr_uint32_t *mem, apr_uint32_t val)
+{
+ apr_uint32_t prev, temp;
+
+ asm volatile ("loop_%=:\n" /* lost reservation */
+ " lwarx %0,0,%3\n" /* load and reserve */
+ " add %1,%0,%4\n" /* add val and prev */
+ PPC405_ERR77_SYNC /* ppc405 Erratum 77 */
+ " stwcx. %1,0,%3\n" /* store new value */
+ " bne- loop_%=\n" /* loop if lost */
+ : "=&r" (prev), "=&r" (temp), "=m" (*mem)
+ : "b" (mem), "r" (val)
+ : "cc", "memory");
+
+ return prev;
+}
+
+APR_DECLARE(void) apr_atomic_sub32(volatile apr_uint32_t *mem, apr_uint32_t val)
+{
+ apr_uint32_t temp;
+
+ asm volatile ("loop_%=:\n" /* lost reservation */
+ " lwarx %0,0,%2\n" /* load and reserve */
+ " subf %0,%3,%0\n" /* subtract val */
+ PPC405_ERR77_SYNC /* ppc405 Erratum 77 */
+ " stwcx. %0,0,%2\n" /* store new value */
+ " bne- loop_%=\n" /* loop if lost */
+ : "=&r" (temp), "=m" (*mem)
+ : "b" (mem), "r" (val)
+ : "cc", "memory");
+}
+
+APR_DECLARE(apr_uint32_t) apr_atomic_inc32(volatile apr_uint32_t *mem)
+{
+ apr_uint32_t prev;
+
+ asm volatile ("loop_%=:\n" /* lost reservation */
+ " lwarx %0,0,%2\n" /* load and reserve */
+ " addi %0,%0,1\n" /* add immediate */
+ PPC405_ERR77_SYNC /* ppc405 Erratum 77 */
+ " stwcx. %0,0,%2\n" /* store new value */
+ " bne- loop_%=\n" /* loop if lost */
+ " subi %0,%0,1\n" /* return old value */
+ : "=&b" (prev), "=m" (*mem)
+ : "b" (mem), "m" (*mem)
+ : "cc", "memory");
+
+ return prev;
+}
+
+APR_DECLARE(int) apr_atomic_dec32(volatile apr_uint32_t *mem)
+{
+ apr_uint32_t prev;
+
+ asm volatile ("loop_%=:\n" /* lost reservation */
+ " lwarx %0,0,%2\n" /* load and reserve */
+ " subi %0,%0,1\n" /* subtract immediate */
+ PPC405_ERR77_SYNC /* ppc405 Erratum 77 */
+ " stwcx. %0,0,%2\n" /* store new value */
+ " bne- loop_%=\n" /* loop if lost */
+ : "=&b" (prev), "=m" (*mem)
+ : "b" (mem), "m" (*mem)
+ : "cc", "memory");
+
+ return prev;
+}
+
+APR_DECLARE(apr_uint32_t) apr_atomic_cas32(volatile apr_uint32_t *mem, apr_uint32_t with,
+ apr_uint32_t cmp)
+{
+ apr_uint32_t prev;
+
+ asm volatile ("loop_%=:\n" /* lost reservation */
+ " lwarx %0,0,%1\n" /* load and reserve */
+ " cmpw %0,%3\n" /* compare operands */
+ " bne- exit_%=\n" /* skip if not equal */
+ PPC405_ERR77_SYNC /* ppc405 Erratum 77 */
+ " stwcx. %2,0,%1\n" /* store new value */
+ " bne- loop_%=\n" /* loop if lost */
+ "exit_%=:\n" /* not equal */
+ : "=&r" (prev)
+ : "b" (mem), "r" (with), "r" (cmp)
+ : "cc", "memory");
+
+ return prev;
+}
+
+APR_DECLARE(apr_uint32_t) apr_atomic_xchg32(volatile apr_uint32_t *mem, apr_uint32_t val)
+{
+ apr_uint32_t prev;
+
+ asm volatile ("loop_%=:\n" /* lost reservation */
+ " lwarx %0,0,%1\n" /* load and reserve */
+ PPC405_ERR77_SYNC /* ppc405 Erratum 77 */
+ " stwcx. %2,0,%1\n" /* store new value */
+ " bne- loop_%=" /* loop if lost */
+ : "=&r" (prev)
+ : "b" (mem), "r" (val)
+ : "cc", "memory");
+
+ return prev;
+}
+
+APR_DECLARE(void*) apr_atomic_casptr(volatile void **mem, void *with, const void *cmp)
+{
+ void *prev;
+#if APR_SIZEOF_VOIDP == 4
+ asm volatile ("loop_%=:\n" /* lost reservation */
+ " lwarx %0,0,%1\n" /* load and reserve */
+ " cmpw %0,%3\n" /* compare operands */
+ " bne- exit_%=\n" /* skip if not equal */
+ PPC405_ERR77_SYNC /* ppc405 Erratum 77 */
+ " stwcx. %2,0,%1\n" /* store new value */
+ " bne- loop_%=\n" /* loop if lost */
+ "exit_%=:\n" /* not equal */
+ : "=&r" (prev)
+ : "b" (mem), "r" (with), "r" (cmp)
+ : "cc", "memory");
+#elif APR_SIZEOF_VOIDP == 8
+ asm volatile ("loop_%=:\n" /* lost reservation */
+ " ldarx %0,0,%1\n" /* load and reserve */
+ " cmpd %0,%3\n" /* compare operands */
+ " bne- exit_%=\n" /* skip if not equal */
+ PPC405_ERR77_SYNC /* ppc405 Erratum 77 */
+ " stdcx. %2,0,%1\n" /* store new value */
+ " bne- loop_%=\n" /* loop if lost */
+ "exit_%=:\n" /* not equal */
+ : "=&r" (prev)
+ : "b" (mem), "r" (with), "r" (cmp)
+ : "cc", "memory");
+#else
+#error APR_SIZEOF_VOIDP value not supported
+#endif
+ return prev;
+}
+
+APR_DECLARE(void*) apr_atomic_xchgptr(volatile void **mem, void *with)
+{
+ void *prev;
+#if APR_SIZEOF_VOIDP == 4
+ asm volatile ("loop_%=:\n" /* lost reservation */
+ " lwarx %0,0,%1\n" /* load and reserve */
+ PPC405_ERR77_SYNC /* ppc405 Erratum 77 */
+ " stwcx. %2,0,%1\n" /* store new value */
+ " bne- loop_%=\n" /* loop if lost */
+ " isync\n" /* memory barrier */
+ : "=&r" (prev)
+ : "b" (mem), "r" (with)
+ : "cc", "memory");
+#elif APR_SIZEOF_VOIDP == 8
+ asm volatile ("loop_%=:\n" /* lost reservation */
+ " ldarx %0,0,%1\n" /* load and reserve */
+ PPC405_ERR77_SYNC /* ppc405 Erratum 77 */
+ " stdcx. %2,0,%1\n" /* store new value */
+ " bne- loop_%=\n" /* loop if lost */
+ " isync\n" /* memory barrier */
+ : "=&r" (prev)
+ : "b" (mem), "r" (with)
+ : "cc", "memory");
+#else
+#error APR_SIZEOF_VOIDP value not supported
+#endif
+ return prev;
+}
+
+#endif /* USE_ATOMICS_PPC */
diff --git a/srclib/apr/atomic/unix/s390.c b/srclib/apr/atomic/unix/s390.c
new file mode 100644
index 00000000..3e233207
--- /dev/null
+++ b/srclib/apr/atomic/unix/s390.c
@@ -0,0 +1,155 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "apr_arch_atomic.h"
+
+#ifdef USE_ATOMICS_S390
+
+APR_DECLARE(apr_status_t) apr_atomic_init(apr_pool_t *p)
+{
+ return APR_SUCCESS;
+}
+
+APR_DECLARE(apr_uint32_t) apr_atomic_read32(volatile apr_uint32_t *mem)
+{
+ return *mem;
+}
+
+APR_DECLARE(void) apr_atomic_set32(volatile apr_uint32_t *mem, apr_uint32_t val)
+{
+ *mem = val;
+}
+
+static APR_INLINE apr_uint32_t atomic_add(volatile apr_uint32_t *mem, apr_uint32_t val)
+{
+ apr_uint32_t prev = *mem, temp;
+
+ asm volatile ("loop_%=:\n"
+ " lr %1,%0\n"
+ " alr %1,%3\n"
+ " cs %0,%1,%2\n"
+ " jl loop_%=\n"
+ : "+d" (prev), "+d" (temp), "=Q" (*mem)
+ : "d" (val), "m" (*mem)
+ : "cc", "memory");
+
+ return prev;
+}
+
+APR_DECLARE(apr_uint32_t) apr_atomic_add32(volatile apr_uint32_t *mem, apr_uint32_t val)
+{
+ return atomic_add(mem, val);
+}
+
+APR_DECLARE(apr_uint32_t) apr_atomic_inc32(volatile apr_uint32_t *mem)
+{
+ return atomic_add(mem, 1);
+}
+
+static APR_INLINE apr_uint32_t atomic_sub(volatile apr_uint32_t *mem, apr_uint32_t val)
+{
+ apr_uint32_t prev = *mem, temp;
+
+ asm volatile ("loop_%=:\n"
+ " lr %1,%0\n"
+ " slr %1,%3\n"
+ " cs %0,%1,%2\n"
+ " jl loop_%=\n"
+ : "+d" (prev), "+d" (temp), "=Q" (*mem)
+ : "d" (val), "m" (*mem)
+ : "cc", "memory");
+
+ return temp;
+}
+
+APR_DECLARE(void) apr_atomic_sub32(volatile apr_uint32_t *mem, apr_uint32_t val)
+{
+ atomic_sub(mem, val);
+}
+
+APR_DECLARE(int) apr_atomic_dec32(volatile apr_uint32_t *mem)
+{
+ return atomic_sub(mem, 1);
+}
+
+APR_DECLARE(apr_uint32_t) apr_atomic_cas32(volatile apr_uint32_t *mem, apr_uint32_t with,
+ apr_uint32_t cmp)
+{
+ asm volatile (" cs %0,%2,%1\n"
+ : "+d" (cmp), "=Q" (*mem)
+ : "d" (with), "m" (*mem)
+ : "cc", "memory");
+
+ return cmp;
+}
+
+APR_DECLARE(apr_uint32_t) apr_atomic_xchg32(volatile apr_uint32_t *mem, apr_uint32_t val)
+{
+ apr_uint32_t prev = *mem;
+
+ asm volatile ("loop_%=:\n"
+ " cs %0,%2,%1\n"
+ " jl loop_%=\n"
+ : "+d" (prev), "=Q" (*mem)
+ : "d" (val), "m" (*mem)
+ : "cc", "memory");
+
+ return prev;
+}
+
+APR_DECLARE(void*) apr_atomic_casptr(volatile void **mem, void *with, const void *cmp)
+{
+ void *prev = (void *) cmp;
+#if APR_SIZEOF_VOIDP == 4
+ asm volatile (" cs %0,%2,%1\n"
+ : "+d" (prev), "=Q" (*mem)
+ : "d" (with), "m" (*mem)
+ : "cc", "memory");
+#elif APR_SIZEOF_VOIDP == 8
+ asm volatile (" csg %0,%2,%1\n"
+ : "+d" (prev), "=Q" (*mem)
+ : "d" (with), "m" (*mem)
+ : "cc", "memory");
+#else
+#error APR_SIZEOF_VOIDP value not supported
+#endif
+ return prev;
+}
+
+APR_DECLARE(void*) apr_atomic_xchgptr(volatile void **mem, void *with)
+{
+ void *prev = (void *) *mem;
+#if APR_SIZEOF_VOIDP == 4
+ asm volatile ("loop_%=:\n"
+ " cs %0,%2,%1\n"
+ " jl loop_%=\n"
+ : "+d" (prev), "=Q" (*mem)
+ : "d" (with), "m" (*mem)
+ : "cc", "memory");
+#elif APR_SIZEOF_VOIDP == 8
+ asm volatile ("loop_%=:\n"
+ " csg %0,%2,%1\n"
+ " jl loop_%=\n"
+ : "+d" (prev), "=Q" (*mem)
+ : "d" (with), "m" (*mem)
+ : "cc", "memory");
+#else
+#error APR_SIZEOF_VOIDP value not supported
+#endif
+ return prev;
+}
+
+#endif /* USE_ATOMICS_S390 */
diff --git a/srclib/apr/atomic/unix/solaris.c b/srclib/apr/atomic/unix/solaris.c
new file mode 100644
index 00000000..b3852516
--- /dev/null
+++ b/srclib/apr/atomic/unix/solaris.c
@@ -0,0 +1,79 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "apr_arch_atomic.h"
+
+#ifdef USE_ATOMICS_SOLARIS
+
+#include <atomic.h>
+
+APR_DECLARE(apr_status_t) apr_atomic_init(apr_pool_t *p)
+{
+ return APR_SUCCESS;
+}
+
+APR_DECLARE(apr_uint32_t) apr_atomic_read32(volatile apr_uint32_t *mem)
+{
+ return *mem;
+}
+
+APR_DECLARE(void) apr_atomic_set32(volatile apr_uint32_t *mem, apr_uint32_t val)
+{
+ *mem = val;
+}
+
+APR_DECLARE(apr_uint32_t) apr_atomic_add32(volatile apr_uint32_t *mem, apr_uint32_t val)
+{
+ return atomic_add_32_nv(mem, val) - val;
+}
+
+APR_DECLARE(void) apr_atomic_sub32(volatile apr_uint32_t *mem, apr_uint32_t val)
+{
+ atomic_add_32(mem, -val);
+}
+
+APR_DECLARE(apr_uint32_t) apr_atomic_inc32(volatile apr_uint32_t *mem)
+{
+ return atomic_inc_32_nv(mem) - 1;
+}
+
+APR_DECLARE(int) apr_atomic_dec32(volatile apr_uint32_t *mem)
+{
+ return atomic_dec_32_nv(mem);
+}
+
+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);
+}
+
+APR_DECLARE(apr_uint32_t) apr_atomic_xchg32(volatile apr_uint32_t *mem, apr_uint32_t val)
+{
+ return atomic_swap_32(mem, val);
+}
+
+APR_DECLARE(void*) apr_atomic_casptr(volatile void **mem, void *with, const void *cmp)
+{
+ return atomic_cas_ptr(mem, cmp, (void*) with);
+}
+
+APR_DECLARE(void*) apr_atomic_xchgptr(volatile void **mem, void *with)
+{
+ return atomic_swap_ptr(mem, with);
+}
+
+#endif /* USE_ATOMICS_SOLARIS */