46 #if defined(_WIN32) || defined(_WINDOWS) || defined(_MSC_VER)
50 #define _CRT_NONSTDC_NO_DEPRECATE 1
51 #define _CRT_SECURE_NO_DEPRECATE 1
65 #if !defined(__FreeBSD__) && !defined(__DragonFly__)
73 #include <sys/types.h>
85 #define fseeko _fseeki64
86 #define ftello _ftelli64
104 Mutex() {
_mutex = CreateMutex(NULL, FALSE, NULL); }
106 void lock() { WaitForSingleObject(
_mutex, INFINITE); }
107 bool trylock() {
return WAIT_TIMEOUT != WaitForSingleObject(
_mutex,0);}
168 #define ATOMIC_ALIGNED __declspec(align(8))
169 #define ATOMIC_ADD32(x,y) (InterlockedExchangeAdd((volatile long*)(x),(long)(y)) + (y))
170 #define ATOMIC_ADD64(x,y) (InterlockedExchangeAdd64((volatile long long*)(x),(long long)(y)) + (y))
171 #define ATOMIC_SUB32(x,y) (InterlockedExchangeAdd((volatile long*)(x),-((long)(y))) - (y))
172 #define ATOMIC_SUB64(x,y) (InterlockedExchangeAdd64((volatile long long*)(x),-((long long)(y))) - (y))
173 #define MEM_FENCE() MemoryBarrier()
174 #define BOOL_CMPXCH32(x,y,z) (InterlockedCompareExchange((volatile long*)(x),(long)(z),(long)(y)) == (y))
175 #define BOOL_CMPXCH64(x,y,z) (InterlockedCompareExchange64((volatile long long*)(x),(long long)(z),(long long)(y)) == (y))
177 #define PTEX_INLINE __forceinline
179 #define PTEX_INLINE inline
182 #define ATOMIC_ALIGNED __attribute__((aligned(8)))
183 #define ATOMIC_ADD32(x,y) __sync_add_and_fetch(x,y)
184 #define ATOMIC_ADD64(x,y) __sync_add_and_fetch(x,y)
185 #define ATOMIC_SUB32(x,y) __sync_sub_and_fetch(x,y)
186 #define ATOMIC_SUB64(x,y) __sync_sub_and_fetch(x,y)
187 #define MEM_FENCE() __sync_synchronize()
188 #define BOOL_CMPXCH32(x,y,z) __sync_bool_compare_and_swap((x),(y),(z))
189 #define BOOL_CMPXCH64(x,y,z) __sync_bool_compare_and_swap((x),(y),(z))
192 #define PTEX_INLINE inline __attribute__((always_inline))
194 #define PTEX_INLINE inline
198 template <
typename T>
209 assert(0==
"Can only use 32 or 64 bit atomics");
214 template <
typename T>
220 template <
typename T>
231 assert(0==
"Can only use 32 or 64 bit atomics");
236 template <
typename T>
246 template <
typename T,
size_t n>
249 template <
typename T>
258 template <
typename T>
267 template <
typename T>
273 template <
typename T>
286 #ifndef CACHE_LINE_SIZE
287 #define CACHE_LINE_SIZE 64
290 #define CACHE_LINE_PAD(var,type) char var##_pad[CACHE_LINE_SIZE - sizeof(type)]
291 #define CACHE_LINE_PAD_INIT(var) memset(&var##_pad[0], 0, sizeof(var##_pad))
Portable fixed-width integer types.
#define PTEX_NAMESPACE_END
pthread_spinlock_t _spinlock
Doxygen version sizeof(uint32_t)>... Generating docs for compound AtomicCompareAndSwapImpl< T
PTEX_INLINE bool operator()(T volatile *target, T oldvalue, T newvalue)
PTEX_INLINE bool operator()(T volatile *target, T oldvalue, T newvalue)