diff src/atomic/SDL_spinlock.c @ 5015:1bf9e38431ec

Use compiler intrinsics on Windows
author Sam Lantinga <slouken@libsdl.org>
date Mon, 17 Jan 2011 14:05:43 -0800
parents 0c72ae7b7cb2
children fffb33ae85e8
line wrap: on
line diff
--- 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);