46 #if defined(_WIN32) || defined(_WINDOWS) || defined(_MSC_VER) 50 #define _CRT_NONSTDC_NO_DEPRECATE 1 51 #define _CRT_SECURE_NO_DEPRECATE 1 70 #include <libkern/OSAtomic.h> 71 #include <sys/types.h> 83 #define fseeko _fseeki64 84 #define ftello _ftelli64 102 Mutex() {
_mutex = CreateMutex(NULL, FALSE, NULL); }
104 void lock() { WaitForSingleObject(
_mutex, INFINITE); }
105 bool trylock() {
return WAIT_TIMEOUT != WaitForSingleObject(
_mutex,0);}
166 #define ATOMIC_ALIGNED __declspec(align(8)) 167 #define ATOMIC_ADD32(x,y) InterlockedExchangeAdd((volatile long*)(x),(long)(y)) 168 #define ATOMIC_ADD64(x,y) InterlockedExchangeAdd64((volatile long long*)(x),(long long)(y)) 169 #define ATOMIC_SUB32(x,y) InterlockedExchangeAdd((volatile long*)(x),-((long)(y))) 170 #define ATOMIC_SUB64(x,y) InterlockedExchangeAdd64((volatile long long*)(x),-((long long)(y))) 171 #define MEM_FENCE() MemoryBarrier() 172 #define BOOL_CMPXCH32(x,y,z) (InterlockedCompareExchange((volatile long*)(x),(long)(z),(long)(y)) == (y)) 173 #define BOOL_CMPXCH64(x,y,z) (InterlockedCompareExchange64((volatile long long*)(x),(long long)(z),(long long)(y)) == (y)) 175 #define PTEX_INLINE __forceinline 177 #define PTEX_INLINE inline 180 #define ATOMIC_ALIGNED __attribute__((aligned(8))) 181 #define ATOMIC_ADD32(x,y) __sync_add_and_fetch(x,y) 182 #define ATOMIC_ADD64(x,y) __sync_add_and_fetch(x,y) 183 #define ATOMIC_SUB32(x,y) __sync_sub_and_fetch(x,y) 184 #define ATOMIC_SUB64(x,y) __sync_sub_and_fetch(x,y) 185 #define MEM_FENCE() __sync_synchronize() 186 #define BOOL_CMPXCH32(x,y,z) __sync_bool_compare_and_swap((x),(y),(z)) 187 #define BOOL_CMPXCH64(x,y,z) __sync_bool_compare_and_swap((x),(y),(z)) 190 #define PTEX_INLINE inline __attribute__((always_inline)) 192 #define PTEX_INLINE inline 196 template <
typename T>
207 assert(0==
"Can only use 32 or 64 bit atomics");
212 template <
typename T>
218 template <
typename T>
229 assert(0==
"Can only use 32 or 64 bit atomics");
234 template <
typename T>
244 template <
typename T,
size_t n>
247 template <
typename T>
256 template <
typename T>
265 template <
typename T>
271 template <
typename T>
284 #ifndef CACHE_LINE_SIZE 285 #define CACHE_LINE_SIZE 64 288 #define CACHE_LINE_PAD(var,type) char var##_pad[CACHE_LINE_SIZE - sizeof(type)] 289 #define CACHE_LINE_PAD_INIT(var) memset(&var##_pad[0], 0, sizeof(var##_pad)) 293 #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)