Use compiler intrinsics on Windows
authorSam Lantinga <slouken@libsdl.org>
Mon, 17 Jan 2011 14:05:43 -0800
changeset 5015 1bf9e38431ec
parent 5014 22751715e11a
child 5016 cc879bc6c4cf
Use compiler intrinsics on Windows
src/atomic/SDL_spinlock.c
--- a/src/atomic/SDL_spinlock.c	Mon Jan 17 14:05:14 2011 -0800
+++ b/src/atomic/SDL_spinlock.c	Mon Jan 17 14:05:43 2011 -0800
@@ -25,8 +25,7 @@
 #include "SDL_timer.h"
 
 #if defined(__WIN32__)
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
+#include <intrin.h>
 
 #elif defined(__MACOSX__)
 #include <libkern/OSAtomic.h>
@@ -39,7 +38,8 @@
 SDL_AtomicTryLock(SDL_SpinLock *lock)
 {
 #if defined(__WIN32__)
-    return (InterlockedExchange(lock, 1) == 0);
+    SDL_COMPILE_TIME_ASSERT(locksize, sizeof(*lock) == sizeof(long));
+    return (_InterlockedExchange((long*)lock, 1) == 0);
 
 #elif defined(__MACOSX__)
     return OSAtomicCompareAndSwap32Barrier(0, 1, lock);