[PATCH v3 2/4] include: Use __atomic_exchange_n() for InterlockedExchange*() if possible.

Zebediah Figura z.figura12 at gmail.com
Mon Jan 18 21:55:01 CST 2021


Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
---
 include/winnt.h | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/include/winnt.h b/include/winnt.h
index 1bb29836a3d..78379996abd 100644
--- a/include/winnt.h
+++ b/include/winnt.h
@@ -7005,7 +7005,9 @@ static FORCEINLINE unsigned char WINAPI InterlockedCompareExchange128( volatile
 static FORCEINLINE LONG WINAPI InterlockedExchange( LONG volatile *dest, LONG val )
 {
     LONG ret;
-#if defined(__i386__) || defined(__x86_64__)
+#if defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)))
+    ret = __atomic_exchange_n( dest, val, __ATOMIC_SEQ_CST );
+#elif defined(__i386__) || defined(__x86_64__)
     __asm__ __volatile__( "lock; xchgl %0,(%1)"
                           : "=r" (ret) :"r" (dest), "0" (val) : "memory" );
 #else
@@ -7032,7 +7034,9 @@ static FORCEINLINE LONG WINAPI InterlockedDecrement( LONG volatile *dest )
 static FORCEINLINE void * WINAPI InterlockedExchangePointer( void *volatile *dest, void *val )
 {
     void *ret;
-#ifdef __x86_64__
+#if defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)))
+    ret = __atomic_exchange_n( dest, val, __ATOMIC_SEQ_CST );
+#elif defined(__x86_64__)
     __asm__ __volatile__( "lock; xchgq %0,(%1)" : "=r" (ret) :"r" (dest), "0" (val) : "memory" );
 #elif defined(__i386__)
     __asm__ __volatile__( "lock; xchgl %0,(%1)" : "=r" (ret) :"r" (dest), "0" (val) : "memory" );
-- 
2.29.2




More information about the wine-devel mailing list