diff options
author | rth <rth@138bc75d-0d04-0410-961f-82ee72b054a4> | 2014-02-20 17:43:53 +0000 |
---|---|---|
committer | rth <rth@138bc75d-0d04-0410-961f-82ee72b054a4> | 2014-02-20 17:43:53 +0000 |
commit | d86e37524da30190b22017cc46a278c3ebfceb5c (patch) | |
tree | 8ec4b08823b9b5486cecde9c93f376b7f59cf42e /libatomic/cas_n.c | |
parent | 73e15dfcff00049654d5f5eba0889e2a7d3d80cf (diff) | |
download | gcc-d86e37524da30190b22017cc46a278c3ebfceb5c.tar.gz |
PR c++/60272
gcc/
* builtins.c (expand_builtin_atomic_compare_exchange): Conditionalize
on failure the store back into EXPECT.
libatomic/
* cas_n.c (libat_compare_exchange): Conditionalize on failure
the store back to EPTR.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@207966 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libatomic/cas_n.c')
-rw-r--r-- | libatomic/cas_n.c | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/libatomic/cas_n.c b/libatomic/cas_n.c index 39c78332423..801262d551c 100644 --- a/libatomic/cas_n.c +++ b/libatomic/cas_n.c @@ -51,10 +51,9 @@ SIZE(libat_compare_exchange) (UTYPE *mptr, UTYPE *eptr, UTYPE newval, #if !DONE && N <= WORDSIZE && defined(atomic_compare_exchange_w) bool SIZE(libat_compare_exchange) (UTYPE *mptr, UTYPE *eptr, UTYPE newval, - int smodel, int fmodel UNUSED) + int smodel, int fmodel) { UWORD mask, shift, weval, woldval, wnewval, t, *wptr; - bool ret = false; pre_barrier (smodel); @@ -82,12 +81,13 @@ SIZE(libat_compare_exchange) (UTYPE *mptr, UTYPE *eptr, UTYPE newval, } while (!atomic_compare_exchange_w (wptr, &woldval, t, true, __ATOMIC_RELAXED, __ATOMIC_RELAXED)); - ret = true; + post_barrier (smodel); + return true; + failure: *eptr = woldval >> shift; - - post_barrier (smodel); - return ret; + post_barrier (fmodel); + return false; } #define DONE 1 @@ -102,18 +102,17 @@ SIZE(libat_compare_exchange) (UTYPE *mptr, UTYPE *eptr, UTYPE newval, { UTYPE oldval; UWORD magic; - bool ret = false; + bool ret; pre_seq_barrier (smodel); magic = protect_start (mptr); oldval = *mptr; - if (oldval == *eptr) - { - *mptr = newval; - ret = true; - } - *eptr = oldval; + ret = (oldval == *eptr); + if (ret) + *mptr = newval; + else + *eptr = oldval; protect_end (mptr, magic); post_seq_barrier (smodel); |