From d55f1b6d5f11a10a78b649259351fa20d7854af0 Mon Sep 17 00:00:00 2001 From: kervala Date: Tue, 5 Oct 2010 21:35:17 +0200 Subject: [PATCH] Changed: Use of BSD function OSAtomicCompareAndSwap32 under Mac OS X --- code/nel/include/nel/misc/mutex.h | 36 +++++++++++++++++++------------ 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/code/nel/include/nel/misc/mutex.h b/code/nel/include/nel/misc/mutex.h index 009840e3b..17f965f69 100644 --- a/code/nel/include/nel/misc/mutex.h +++ b/code/nel/include/nel/misc/mutex.h @@ -22,17 +22,19 @@ #include "common.h" #include -#ifdef NL_OS_UNIX -//#include -#include // PThread -#include // PThread POSIX semaphores -#include -#define __forceinline -#elif defined(NL_OS_WINDOWS) +#ifdef NL_OS_WINDOWS # ifdef NL_NO_ASM # include # endif -#endif +#elif defined(NL_OS_UNIX) +# include // PThread +# include // PThread POSIX semaphores +# include +# define __forceinline +# ifdef NL_OS_MAC +# include +# endif +#endif // NL_OS_WINDOWS #undef MUTEX_DEBUG @@ -245,12 +247,18 @@ public: } # endif // NL_DEBUG # endif // NL_NO_ASM -#else - // 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); +#elif defined(NL_OS_MAC) + return OSAtomicCompareAndSwap32(0, 1, reinterpret_cast(lockPtr)); +#elif defined(NL_OS_UNIX) + // 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 +# if (GCC_VERSION > 40100) + // return __sync_bool_compare_and_swap(lockPtr, 0, 1); + result = __sync_val_compare_and_swap(lockPtr, 0, 1); +# else + ASM_ASWAP_FOR_GCC_XCHG +# endif #endif // NL_OS_WINDOWS return result != 0; }