comparison include/SDL_atomic.h @ 5012:2e282002bac3

Use compiler intrinsics, where available
author Sam Lantinga <slouken@libsdl.org>
date Mon, 17 Jan 2011 13:53:31 -0800
parents 8e8876e4aec6
children cc879bc6c4cf
comparison
equal deleted inserted replaced
5011:d306007299ac 5012:2e282002bac3
111 * you can disable these by defining SDL_DISABLE_ATOMIC_INLINE 111 * you can disable these by defining SDL_DISABLE_ATOMIC_INLINE
112 */ 112 */
113 #ifndef SDL_DISABLE_ATOMIC_INLINE 113 #ifndef SDL_DISABLE_ATOMIC_INLINE
114 114
115 #if defined(__WIN32__) 115 #if defined(__WIN32__)
116 /* Don't include windows.h, since it may hose code that isn't expecting it, 116 #include <intrin.h>
117 but if someone has already included it, this is fair game... */ 117
118 #define WIN32_LEAN_AND_MEAN 118 #define SDL_AtomicSet(a, v) _InterlockedExchange(&(a)->value, (v))
119 #include <windows.h>
120
121 #define SDL_AtomicSet(a, v) InterlockedExchange(&(a)->value, v)
122 #define SDL_AtomicGet(a) ((a)->value) 119 #define SDL_AtomicGet(a) ((a)->value)
123 #define SDL_AtomicAdd(a, v) InterlockedAdd(&(a)->value, v) 120 #define SDL_AtomicAdd(a, v) _InterlockedExchangeAdd(&(a)->value, (v))
124 #define SDL_AtomicCAS(a, oldval, newval) (InterlockedCompareExchange(&(a)->value, newval, oldval) == (oldval)) 121 #define SDL_AtomicCAS(a, oldval, newval) (_InterlockedCompareExchange(&(a)->value, (newval), (oldval)) == (oldval))
125 #define SDL_AtomicSetPtr(a, v) InterlockedExchangePointer(a, v) 122 #define SDL_AtomicSetPtr(a, v) (void)_InterlockedExchangePointer((a), (v))
126 #define SDL_AtomicGetPtr(a) (*(a)) 123 #define SDL_AtomicGetPtr(a) (*(a))
127 #define SDL_AtomicCASPtr(a, oldval, newval) (InterlockedCompareExchangePointer(a, newval, oldval) == (oldval)) 124 #if _M_IX86
125 #define SDL_AtomicCASPtr(a, oldval, newval) (_InterlockedCompareExchange((long*)(a), (long)(newval), (long)(oldval)) == (long)(oldval))
126 #else
127 #define SDL_AtomicCASPtr(a, oldval, newval) (_InterlockedCompareExchangePointer((a), (newval), (oldval)) == (oldval))
128 #endif
128 129
129 #elif defined(__MACOSX__) 130 #elif defined(__MACOSX__)
130 #include <libkern/OSAtomic.h> 131 #include <libkern/OSAtomic.h>
131 132
132 #define SDL_AtomicSet(a, v) \ 133 #define SDL_AtomicSet(a, v) \