mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-12-21 08:28:44 +00:00
Changed: Use of BSD function OSAtomicCompareAndSwap32 under Mac OS X
This commit is contained in:
parent
89f6f37b4d
commit
18ad6218a6
1 changed files with 22 additions and 14 deletions
|
@ -22,17 +22,19 @@
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
#ifdef NL_OS_UNIX
|
#ifdef NL_OS_WINDOWS
|
||||||
//#include <iostream>
|
|
||||||
#include <pthread.h> // PThread
|
|
||||||
#include <semaphore.h> // PThread POSIX semaphores
|
|
||||||
#include <unistd.h>
|
|
||||||
#define __forceinline
|
|
||||||
#elif defined(NL_OS_WINDOWS)
|
|
||||||
# ifdef NL_NO_ASM
|
# ifdef NL_NO_ASM
|
||||||
# include <intrin.h>
|
# include <intrin.h>
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#elif defined(NL_OS_UNIX)
|
||||||
|
# include <pthread.h> // PThread
|
||||||
|
# include <semaphore.h> // PThread POSIX semaphores
|
||||||
|
# include <unistd.h>
|
||||||
|
# define __forceinline
|
||||||
|
# ifdef NL_OS_MAC
|
||||||
|
# include <libkern/OSAtomic.h>
|
||||||
|
# endif
|
||||||
|
#endif // NL_OS_WINDOWS
|
||||||
|
|
||||||
#undef MUTEX_DEBUG
|
#undef MUTEX_DEBUG
|
||||||
|
|
||||||
|
@ -245,12 +247,18 @@ public:
|
||||||
}
|
}
|
||||||
# endif // NL_DEBUG
|
# endif // NL_DEBUG
|
||||||
# endif // NL_NO_ASM
|
# endif // NL_NO_ASM
|
||||||
#else
|
#elif defined(NL_OS_MAC)
|
||||||
|
return OSAtomicCompareAndSwap32(0, 1, reinterpret_cast<volatile sint32 *>(lockPtr));
|
||||||
|
#elif defined(NL_OS_UNIX)
|
||||||
// GCC implements the same functionality using a builtin function
|
// GCC implements the same functionality using a builtin function
|
||||||
// http://gcc.gnu.org/onlinedocs/gcc/Atomic-Builtins.html
|
// http://gcc.gnu.org/onlinedocs/gcc/Atomic-Builtins.html
|
||||||
// the macro below crashed on Mac OS X 10.6 in a 64bit build
|
// the macro below crashed on Mac OS X 10.6 in a 64bit build
|
||||||
//ASM_ASWAP_FOR_GCC_XCHG
|
# if (GCC_VERSION > 40100)
|
||||||
result = __sync_bool_compare_and_swap(lockPtr, 0, 1);
|
// 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
|
#endif // NL_OS_WINDOWS
|
||||||
return result != 0;
|
return result != 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue