46 #if defined(_WIN32) || defined(_WINDOWS) || defined(_MSC_VER)
50 #define _CRT_NONSTDC_NO_DEPRECATE 1
51 #define _CRT_SECURE_NO_DEPRECATE 1
71 #include <sys/types.h>
84 #define fseeko _fseeki64
85 #define ftello _ftelli64
103 Mutex() {
_mutex = CreateMutex(NULL, FALSE, NULL); }
105 void lock() { WaitForSingleObject(
_mutex, INFINITE); }
106 bool trylock() {
return WAIT_TIMEOUT != WaitForSingleObject(
_mutex,0);}
167 #define ATOMIC_ALIGNED __declspec(align(8))
168 #define ATOMIC_ADD32(x,y) (InterlockedExchangeAdd((volatile long*)(x),(long)(y)) + (y))
169 #define ATOMIC_ADD64(x,y) (InterlockedExchangeAdd64((volatile long long*)(x),(long long)(y)) + (y))
170 #define ATOMIC_SUB32(x,y) (InterlockedExchangeAdd((volatile long*)(x),-((long)(y))) - (y))
171 #define ATOMIC_SUB64(x,y) (InterlockedExchangeAdd64((volatile long long*)(x),-((long long)(y))) - (y))
172 #define MEM_FENCE() MemoryBarrier()
173 #define BOOL_CMPXCH32(x,y,z) (InterlockedCompareExchange((volatile long*)(x),(long)(z),(long)(y)) == (y))
174 #define BOOL_CMPXCH64(x,y,z) (InterlockedCompareExchange64((volatile long long*)(x),(long long)(z),(long long)(y)) == (y))
176 #define PTEX_INLINE __forceinline
178 #define PTEX_INLINE inline
181 #define ATOMIC_ALIGNED __attribute__((aligned(8)))
182 #define ATOMIC_ADD32(x,y) __sync_add_and_fetch(x,y)
183 #define ATOMIC_ADD64(x,y) __sync_add_and_fetch(x,y)
184 #define ATOMIC_SUB32(x,y) __sync_sub_and_fetch(x,y)
185 #define ATOMIC_SUB64(x,y) __sync_sub_and_fetch(x,y)
186 #define MEM_FENCE() __sync_synchronize()
187 #define BOOL_CMPXCH32(x,y,z) __sync_bool_compare_and_swap((x),(y),(z))
188 #define BOOL_CMPXCH64(x,y,z) __sync_bool_compare_and_swap((x),(y),(z))
191 #define PTEX_INLINE inline __attribute__((always_inline))
193 #define PTEX_INLINE inline
197 template <
typename T>
208 assert(0==
"Can only use 32 or 64 bit atomics");
213 template <
typename T>
219 template <
typename T>
230 assert(0==
"Can only use 32 or 64 bit atomics");
235 template <
typename T>
245 template <
typename T,
size_t n>
248 template <
typename T>
257 template <
typename T>
266 template <
typename T>
272 template <
typename T>
285 #ifndef CACHE_LINE_SIZE
286 #define CACHE_LINE_SIZE 64
289 #define CACHE_LINE_PAD(var,type) char var##_pad[CACHE_LINE_SIZE - sizeof(type)]
290 #define CACHE_LINE_PAD_INIT(var) memset(&var##_pad[0], 0, sizeof(var##_pad))
294 #endif // PtexPlatform_h