45 #if defined(__clang__) 46 # define PTEX_COMPILER_CLANG 47 #elif defined(__GNUC__) 48 # define PTEX_COMPILER_GCC 50 # define PTEX_COMPILER_ICC 51 #elif defined(_MSC_VER) 52 # define PTEX_COMPILER_MSVC 56 #if defined(_WIN32) || defined(_WIN64) || defined(_WINDOWS) || defined(_MSC_VER) 57 #define PTEX_PLATFORM_WINDOWS 58 #define _CRT_NONSTDC_NO_DEPRECATE 1 59 #define _CRT_SECURE_NO_DEPRECATE 1 79 #include <sys/types.h> 81 #define PTEX_PLATFORM_MACOS 83 #define PTEX_PLATFORM_UNIX 93 #ifdef PTEX_PLATFORM_WINDOWS 95 #define fseeko _fseeki64 96 #define ftello _ftelli64 110 #ifdef PTEX_PLATFORM_WINDOWS 114 Mutex() {
_mutex = CreateMutex(NULL, FALSE, NULL); }
116 void lock() { WaitForSingleObject(
_mutex, INFINITE); }
117 bool trylock() {
return WAIT_TIMEOUT != WaitForSingleObject(
_mutex,0);}
177 #ifdef PTEX_PLATFORM_WINDOWS 178 #define ATOMIC_ALIGNED __declspec(align(8)) 179 #define ATOMIC_ADD32(x,y) (InterlockedExchangeAdd((volatile long*)(x),(long)(y)) + (y)) 180 #define ATOMIC_ADD64(x,y) (InterlockedExchangeAdd64((volatile long long*)(x),(long long)(y)) + (y)) 181 #define ATOMIC_SUB32(x,y) (InterlockedExchangeAdd((volatile long*)(x),-((long)(y))) - (y)) 182 #define ATOMIC_SUB64(x,y) (InterlockedExchangeAdd64((volatile long long*)(x),-((long long)(y))) - (y)) 183 #define MEM_FENCE() MemoryBarrier() 184 #define BOOL_CMPXCH32(x,y,z) (InterlockedCompareExchange((volatile long*)(x),(long)(z),(long)(y)) == (y)) 185 #define BOOL_CMPXCH64(x,y,z) (InterlockedCompareExchange64((volatile long long*)(x),(long long)(z),(long long)(y)) == (y)) 187 #define PTEX_INLINE __forceinline 189 #define PTEX_INLINE inline 192 #define ATOMIC_ALIGNED __attribute__((aligned(8))) 193 #define ATOMIC_ADD32(x,y) __sync_add_and_fetch(x,y) 194 #define ATOMIC_ADD64(x,y) __sync_add_and_fetch(x,y) 195 #define ATOMIC_SUB32(x,y) __sync_sub_and_fetch(x,y) 196 #define ATOMIC_SUB64(x,y) __sync_sub_and_fetch(x,y) 197 #define MEM_FENCE() __sync_synchronize() 198 #define BOOL_CMPXCH32(x,y,z) __sync_bool_compare_and_swap((x),(y),(z)) 199 #define BOOL_CMPXCH64(x,y,z) __sync_bool_compare_and_swap((x),(y),(z)) 202 #define PTEX_INLINE inline __attribute__((always_inline)) 204 #define PTEX_INLINE inline 208 template <
typename T>
219 assert(0==
"Can only use 32 or 64 bit atomics");
224 template <
typename T>
230 template <
typename T>
241 assert(0==
"Can only use 32 or 64 bit atomics");
246 template <
typename T>
256 template <
typename T,
size_t n>
259 template <
typename T>
268 template <
typename T>
277 template <
typename T>
283 template <
typename T>
296 #ifndef CACHE_LINE_SIZE 297 #define CACHE_LINE_SIZE 64 300 #define CACHE_LINE_PAD(var,type) char var##_pad[CACHE_LINE_SIZE - sizeof(type)] 301 #define CACHE_LINE_PAD_INIT(var) memset(&var##_pad[0], 0, sizeof(var##_pad)) 305 #endif // PtexPlatform_h
PTEX_INLINE bool operator()(T volatile *target, T oldvalue, T newvalue)
pthread_spinlock_t _spinlock
Portable fixed-width integer types.
#define PTEX_NAMESPACE_END
PTEX_INLINE bool operator()(T volatile *target, T oldvalue, T newvalue)