On Sat, Oct 27, 2018 at 12:03:25AM +0800, Junchang Wang wrote: > If the 4th parameter (field *weak*) of __atomic_compare_exchange_n is set, it > may refuse to perform the CAS operation and return a failure, even if the value > of field *old* is equal to the content of the specified memory location. This > happens in architectures where LL/SC is used to emulate CAS primitive (e.g., PPC > and ARM). > > This patch returns the *old* value if __atomic_compare_exchange_n has been > successfully performed; otherwise, *old*+1 is returned, which forces the caller > to retry the CAS loop. > > Signed-off-by: Junchang Wang <junchangwang@xxxxxxxxx> > Signed-off-by: kira Yokosawa <akiyks@xxxxxxxxx> Very good, queued and pushed with adjustments to the commit log above, thank you!!! Please let me know if further adjustments are required. Thanx, Paul > --- > CodeSamples/api-pthreads/api-gcc.h | 5 ++--- > 1 file changed, 2 insertions(+), 3 deletions(-) > > diff --git a/CodeSamples/api-pthreads/api-gcc.h b/CodeSamples/api-pthreads/api-gcc.h > index 1dd26ca..3afe340 100644 > --- a/CodeSamples/api-pthreads/api-gcc.h > +++ b/CodeSamples/api-pthreads/api-gcc.h > @@ -168,9 +168,8 @@ struct __xchg_dummy { > ({ \ > typeof(*ptr) _____actual = (o); \ > \ > - (void)__atomic_compare_exchange_n(ptr, (void *)&_____actual, (n), 1, \ > - __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); \ > - _____actual; \ > + __atomic_compare_exchange_n(ptr, (void *)&_____actual, (n), 1, \ > + __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) ? (o) : (o)+1; \ > }) > > static __inline__ int atomic_cmpxchg(atomic_t *v, int old, int new) > -- > 2.7.4 >