From 0347a1839d8544d18203eebe683e5450efc24ac9 Mon Sep 17 00:00:00 2001 From: vl Date: Tue, 11 May 2010 11:18:32 +0200 Subject: [PATCH] Fixed: #874 commented the old asm g++ code and use the builtin function. patch by rti --- code/nel/include/nel/misc/mutex.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/code/nel/include/nel/misc/mutex.h b/code/nel/include/nel/misc/mutex.h index 746f101e3..9837cd158 100644 --- a/code/nel/include/nel/misc/mutex.h +++ b/code/nel/include/nel/misc/mutex.h @@ -109,6 +109,7 @@ private: // - () instead of [], // - immediate values prefixed by $ +/* // Tested: works on multi-processor #ifdef HAVE_X86_64 # define ASM_ASWAP_FOR_GCC_XCHG __asm__ volatile( \ @@ -129,7 +130,9 @@ private: : "m" (lockPtr) \ : "eax", "ecx", "memory" ); // force to use registers and memory #endif +*/ +/* // Tested: does not work (at least on multi-processor)! (with or without 'lock' prefix) #define ASM_ASWAP_FOR_GCC_CMPXCHG __asm__ volatile( \ "mov $1, %%edx;" \ @@ -142,7 +145,7 @@ private: : "=m" (result) \ : "m" (lockPtr) \ : "eax", "ecx", "edx", "memory" ); // force to use registers and memory - +*/ // Tested: does not work on hyper-threading processors! /*ASM_ASWAP_FOR_MSVC_CMPXCHG @@ -237,7 +240,11 @@ public: # endif // NL_DEBUG # endif // NL_NO_ASM #else - ASM_ASWAP_FOR_GCC_XCHG + // GCC implements the same functionality using a builtin function + // http://gcc.gnu.org/onlinedocs/gcc/Atomic-Builtins.html + // the macro below crashed on Mac OS X 10.6 in a 64bit build + //ASM_ASWAP_FOR_GCC_XCHG + result = __sync_bool_compare_and_swap(lockPtr, 0, 1); #endif // NL_OS_WINDOWS return result != 0; }