[PATCH] atomic_cmpxchg: Handle spurious failure of __atomic_compare_exchange_n in Power8 and ARMv8

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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>
---
 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




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux