Hi,
this patch only makes one change in three places:
* Remove the redundant memory read from the CAS-based fallback
implementations.
Regards, Colin
Index: atomic/unix/apr_atomic.c
===================================================================
--- atomic/unix/apr_atomic.c (revision 472020)
+++ atomic/unix/apr_atomic.c (working copy)
@@ -252,12 +252,13 @@
#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;
+ apr_uint32_t old_value;
+ apr_uint32_t tmp_value = *mem;
do {
- old_value = *mem;
- new_value = old_value + val;
- } while (apr_atomic_cas32(mem, new_value, old_value) != old_value);
+ old_value = tmp_value;
+ tmp_value = apr_atomic_cas32(mem, old_value + val, old_value);
+ } while (tmp_value != old_value);
return old_value;
}
#else
@@ -285,12 +286,13 @@
#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;
+ apr_uint32_t old_value;
+ apr_uint32_t tmp_value = *mem;
do {
- old_value = *mem;
- new_value = old_value - val;
- } while (apr_atomic_cas32(mem, new_value, old_value) != old_value);
+ old_value = tmp_value;
+ tmp_value = apr_atomic_cas32(mem, old_value - val, old_value);
+ } while (tmp_value != old_value);
}
#else
void apr_atomic_sub32(volatile apr_uint32_t *mem, apr_uint32_t val)
@@ -334,12 +336,13 @@
#if defined(APR_OVERRIDE_ATOMIC_CAS32)
int apr_atomic_dec32(volatile apr_uint32_t *mem)
{
- apr_uint32_t old_value, new_value;
+ apr_uint32_t old_value;
+ apr_uint32_t tmp_value = *mem;
do {
- old_value = *mem;
- new_value = old_value - 1;
- } while (apr_atomic_cas32(mem, new_value, old_value) != old_value);
+ old_value = tmp_value;
+ tmp_value = apr_atomic_cas32(mem, old_value - 1, old_value);
+ } while (tmp_value != old_value);
return old_value != 1;
}
#else