aboutsummaryrefslogtreecommitdiffstats
path: root/erts/include/internal/libatomic_ops
diff options
context:
space:
mode:
authorRickard Green <[email protected]>2011-05-10 11:45:30 +0200
committerRickard Green <[email protected]>2011-05-11 12:11:45 +0200
commit5bcdb3ac4ea27ca47e18628aa147e7544043fa84 (patch)
treefab46e0a588d6e7cab7ef4b42a9280ccd7da3b64 /erts/include/internal/libatomic_ops
parent2ef48dca9328e0b928117f21bc9ee6dbc5a614cc (diff)
downloadotp-5bcdb3ac4ea27ca47e18628aa147e7544043fa84.tar.gz
otp-5bcdb3ac4ea27ca47e18628aa147e7544043fa84.tar.bz2
otp-5bcdb3ac4ea27ca47e18628aa147e7544043fa84.zip
Homogenize memory barriers on atomics
Atomic operations with specified barriers have specified barrier semantics. Set and read operations have undefined barrier semantics. All other atomic operations implied full memory barriers, except when using the libatomic_ops library and the tilera atomics api. Some code in the runtime system assumed that all operations used (except for set, read and specified) implied full memory barriers. The use of the libatomic_ops library and the tilera atomics api have therefore been modified to behave as the other implementations. Some atomic operations with specified barrier semantics on sparc32 have also been been relaxed in this commit.
Diffstat (limited to 'erts/include/internal/libatomic_ops')
-rw-r--r--erts/include/internal/libatomic_ops/ethr_atomic.h26
1 files changed, 11 insertions, 15 deletions
diff --git a/erts/include/internal/libatomic_ops/ethr_atomic.h b/erts/include/internal/libatomic_ops/ethr_atomic.h
index d56693dbf8..2fc82c99a8 100644
--- a/erts/include/internal/libatomic_ops/ethr_atomic.h
+++ b/erts/include/internal/libatomic_ops/ethr_atomic.h
@@ -146,13 +146,13 @@ ETHR_NATMC_FUNC__(read)(ETHR_ATMC_T__ *var)
static ETHR_INLINE ETHR_AINT_T__
ETHR_NATMC_FUNC__(add_return)(ETHR_ATMC_T__ *var, ETHR_AINT_T__ incr)
{
-#ifdef AO_HAVE_fetch_and_add
- return ((ETHR_AINT_T__) AO_fetch_and_add(&var->counter, (AO_t) incr)) + incr;
+#ifdef AO_HAVE_fetch_and_add_full
+ return ((ETHR_AINT_T__) AO_fetch_and_add_full(&var->counter, (AO_t) incr)) + incr;
#else
while (1) {
AO_t exp = AO_load(&var->counter);
AO_t new = exp + (AO_t) incr;
- if (AO_compare_and_swap(&var->counter, exp, new))
+ if (AO_compare_and_swap_full(&var->counter, exp, new))
return (ETHR_AINT_T__) new;
}
#endif
@@ -167,8 +167,8 @@ ETHR_NATMC_FUNC__(add)(ETHR_ATMC_T__ *var, ETHR_AINT_T__ incr)
static ETHR_INLINE ETHR_AINT_T__
ETHR_NATMC_FUNC__(inc_return)(ETHR_ATMC_T__ *var)
{
-#ifdef AO_HAVE_fetch_and_add1
- return ((ETHR_AINT_T__) AO_fetch_and_add1(&var->counter)) + 1;
+#ifdef AO_HAVE_fetch_and_add1_full
+ return ((ETHR_AINT_T__) AO_fetch_and_add1_full(&var->counter)) + 1;
#else
return ETHR_NATMC_FUNC__(add_return)(var, 1);
#endif
@@ -183,8 +183,8 @@ ETHR_NATMC_FUNC__(inc)(ETHR_ATMC_T__ *var)
static ETHR_INLINE ETHR_AINT_T__
ETHR_NATMC_FUNC__(dec_return)(ETHR_ATMC_T__ *var)
{
-#ifdef AO_HAVE_fetch_and_sub1
- return ((ETHR_AINT_T__) AO_fetch_and_sub1(&var->counter)) - 1;
+#ifdef AO_HAVE_fetch_and_sub1_full
+ return ((ETHR_AINT_T__) AO_fetch_and_sub1_full(&var->counter)) - 1;
#else
return ETHR_NATMC_FUNC__(add_return)(var, -1);
#endif
@@ -202,7 +202,7 @@ ETHR_NATMC_FUNC__(and_retold)(ETHR_ATMC_T__ *var, ETHR_AINT_T__ mask)
while (1) {
AO_t exp = AO_load(&var->counter);
AO_t new = exp & ((AO_t) mask);
- if (AO_compare_and_swap(&var->counter, exp, new))
+ if (AO_compare_and_swap_full(&var->counter, exp, new))
return (ETHR_AINT_T__) exp;
}
}
@@ -213,7 +213,7 @@ ETHR_NATMC_FUNC__(or_retold)(ETHR_ATMC_T__ *var, ETHR_AINT_T__ mask)
while (1) {
AO_t exp = AO_load(&var->counter);
AO_t new = exp | ((AO_t) mask);
- if (AO_compare_and_swap(&var->counter, exp, new))
+ if (AO_compare_and_swap_full(&var->counter, exp, new))
return (ETHR_AINT_T__) exp;
}
}
@@ -225,7 +225,7 @@ ETHR_NATMC_FUNC__(cmpxchg)(ETHR_ATMC_T__ *var,
{
ETHR_AINT_T__ act;
do {
- if (AO_compare_and_swap(&var->counter, (AO_t) exp, (AO_t) new))
+ if (AO_compare_and_swap_full(&var->counter, (AO_t) exp, (AO_t) new))
return exp;
act = (ETHR_AINT_T__) AO_load(&var->counter);
} while (act == exp);
@@ -237,7 +237,7 @@ ETHR_NATMC_FUNC__(xchg)(ETHR_ATMC_T__ *var, ETHR_AINT_T__ new)
{
while (1) {
AO_t exp = AO_load(&var->counter);
- if (AO_compare_and_swap(&var->counter, exp, (AO_t) new))
+ if (AO_compare_and_swap_full(&var->counter, exp, (AO_t) new))
return (ETHR_AINT_T__) exp;
}
}
@@ -265,7 +265,6 @@ ETHR_NATMC_FUNC__(inc_return_acqb)(ETHR_ATMC_T__ *var)
return ((ETHR_AINT_T__) AO_fetch_and_add1_acquire(&var->counter)) + 1;
#else
ETHR_AINT_T__ res = ETHR_NATMC_FUNC__(add_return)(var, 1);
- ETHR_MEMORY_BARRIER;
return res;
#endif
}
@@ -287,7 +286,6 @@ ETHR_NATMC_FUNC__(dec_return_relb)(ETHR_ATMC_T__ *var)
#ifdef AO_HAVE_fetch_and_sub1_release
return ((ETHR_AINT_T__) AO_fetch_and_sub1_release(&var->counter)) - 1;
#else
- ETHR_MEMORY_BARRIER;
return ETHR_NATMC_FUNC__(dec_return)(var);
#endif
}
@@ -314,7 +312,6 @@ ETHR_NATMC_FUNC__(cmpxchg_acqb)(ETHR_ATMC_T__ *var,
return act;
#else
ETHR_AINT_T__ act = ETHR_NATMC_FUNC__(cmpxchg)(var, new, exp);
- ETHR_MEMORY_BARRIER;
return act;
#endif
}
@@ -333,7 +330,6 @@ ETHR_NATMC_FUNC__(cmpxchg_relb)(ETHR_ATMC_T__ *var,
} while (act == exp);
return act;
#else
- ETHR_MEMORY_BARRIER;
return ETHR_NATMC_FUNC__(cmpxchg)(var, new, exp);
#endif
}