Mercurial > sdl-ios-xcode
comparison 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 |
comparison
equal
deleted
inserted
replaced
5014:22751715e11a | 5015:1bf9e38431ec |
---|---|
23 | 23 |
24 #include "SDL_atomic.h" | 24 #include "SDL_atomic.h" |
25 #include "SDL_timer.h" | 25 #include "SDL_timer.h" |
26 | 26 |
27 #if defined(__WIN32__) | 27 #if defined(__WIN32__) |
28 #define WIN32_LEAN_AND_MEAN | 28 #include <intrin.h> |
29 #include <windows.h> | |
30 | 29 |
31 #elif defined(__MACOSX__) | 30 #elif defined(__MACOSX__) |
32 #include <libkern/OSAtomic.h> | 31 #include <libkern/OSAtomic.h> |
33 | 32 |
34 #endif | 33 #endif |
37 /* This function is where all the magic happens... */ | 36 /* This function is where all the magic happens... */ |
38 SDL_bool | 37 SDL_bool |
39 SDL_AtomicTryLock(SDL_SpinLock *lock) | 38 SDL_AtomicTryLock(SDL_SpinLock *lock) |
40 { | 39 { |
41 #if defined(__WIN32__) | 40 #if defined(__WIN32__) |
42 return (InterlockedExchange(lock, 1) == 0); | 41 SDL_COMPILE_TIME_ASSERT(locksize, sizeof(*lock) == sizeof(long)); |
42 return (_InterlockedExchange((long*)lock, 1) == 0); | |
43 | 43 |
44 #elif defined(__MACOSX__) | 44 #elif defined(__MACOSX__) |
45 return OSAtomicCompareAndSwap32Barrier(0, 1, lock); | 45 return OSAtomicCompareAndSwap32Barrier(0, 1, lock); |
46 | 46 |
47 #elif defined(HAVE_GCC_ATOMICS) | 47 #elif defined(HAVE_GCC_ATOMICS) |