Fix Windows build errors.

This commit is contained in:
David Anderson 2013-08-23 15:45:07 -07:00
parent e5428a3c27
commit 5999b50e10

View File

@ -39,8 +39,8 @@ extern "C" {
long __cdecl _InterlockedIncrement(long volatile *dest); long __cdecl _InterlockedIncrement(long volatile *dest);
long __cdecl _InterlockedDecrement(long volatile *dest); long __cdecl _InterlockedDecrement(long volatile *dest);
} }
# pragma intrinsic(_InterlockedIncrement); # pragma intrinsic(_InterlockedIncrement)
# pragma intrinsic(_InterlockedDecrement); # pragma intrinsic(_InterlockedDecrement)
#endif #endif
template <size_t Width> template <size_t Width>
@ -49,23 +49,25 @@ struct AtomicOps;
template <> template <>
struct AtomicOps<4> struct AtomicOps<4>
{ {
typedef int Type;
#if defined(_MSC_VER) #if defined(_MSC_VER)
static int Increment(int *ptr) { typedef long Type;
static Type Increment(Type *ptr) {
return _InterlockedIncrement(ptr); return _InterlockedIncrement(ptr);
} }
static int Decrement(int *ptr) { static Type Decrement(Type *ptr) {
return _InterlockedDecrement(ptr); return _InterlockedDecrement(ptr);
}; };
#elif defined(__GNUC__) #elif defined(__GNUC__)
typedef int Type;
// x86/x64 notes: When using GCC < 4.8, this will compile to a spinlock. // x86/x64 notes: When using GCC < 4.8, this will compile to a spinlock.
// On 4.8+, or when using Clang, we'll get the more optimal "lock addl" // On 4.8+, or when using Clang, we'll get the more optimal "lock addl"
// variant. // variant.
static int Increment(int *ptr) { static Type Increment(Type *ptr) {
return __sync_add_and_fetch(ptr, 1); return __sync_add_and_fetch(ptr, 1);
} }
static int Decrement(int *ptr) { static Type Decrement(Type *ptr) {
return __sync_sub_and_fetch(ptr, 1); return __sync_sub_and_fetch(ptr, 1);
} }
#endif #endif