comparison include/SDL_atomic.h @ 5006:8e8876e4aec6

Include windows.h in SDL_atomic.h by default, but don't include the atomic API in SDL.h This allows all SDL code to take advantage of the atomic intrinsics on Windows, but doesn't cause applications just including SDL.h to pull in windows.h
author Sam Lantinga <slouken@libsdl.org>
date Sun, 16 Jan 2011 17:45:42 -0800
parents 7f0265279b68
children 2e282002bac3
comparison
equal deleted inserted replaced
5005:7f0265279b68 5006:8e8876e4aec6
105 */ 105 */
106 extern DECLSPEC void SDLCALL SDL_AtomicUnlock(SDL_SpinLock *lock); 106 extern DECLSPEC void SDLCALL SDL_AtomicUnlock(SDL_SpinLock *lock);
107 107
108 /*@}*//*SDL AtomicLock*/ 108 /*@}*//*SDL AtomicLock*/
109 109
110 /* Platform specific optimized versions of the atomic functions */ 110 /* Platform specific optimized versions of the atomic functions,
111 #if defined(__WIN32__) && defined(_INC_WINDOWS) 111 * you can disable these by defining SDL_DISABLE_ATOMIC_INLINE
112 */
113 #ifndef SDL_DISABLE_ATOMIC_INLINE
114
115 #if defined(__WIN32__)
112 /* Don't include windows.h, since it may hose code that isn't expecting it, 116 /* Don't include windows.h, since it may hose code that isn't expecting it,
113 but if someone has already included it, this is fair game... */ 117 but if someone has already included it, this is fair game... */
114 #if 0
115 #define WIN32_LEAN_AND_MEAN 118 #define WIN32_LEAN_AND_MEAN
116 #include <windows.h> 119 #include <windows.h>
117 #endif
118 120
119 #define SDL_AtomicSet(a, v) InterlockedExchange(&(a)->value, v) 121 #define SDL_AtomicSet(a, v) InterlockedExchange(&(a)->value, v)
120 #define SDL_AtomicGet(a) ((a)->value) 122 #define SDL_AtomicGet(a) ((a)->value)
121 #define SDL_AtomicAdd(a, v) InterlockedAdd(&(a)->value, v) 123 #define SDL_AtomicAdd(a, v) InterlockedAdd(&(a)->value, v)
122 #define SDL_AtomicCAS(a, oldval, newval) (InterlockedCompareExchange(&(a)->value, newval, oldval) == (oldval)) 124 #define SDL_AtomicCAS(a, oldval, newval) (InterlockedCompareExchange(&(a)->value, newval, oldval) == (oldval))
167 #define SDL_AtomicGetPtr(a) (*(a)) 169 #define SDL_AtomicGetPtr(a) (*(a))
168 #define SDL_AtomicCASPtr(a, oldval, newval) __sync_bool_compare_and_swap(a, oldval, newval) 170 #define SDL_AtomicCASPtr(a, oldval, newval) __sync_bool_compare_and_swap(a, oldval, newval)
169 171
170 #endif 172 #endif
171 173
174 #endif /* !SDL_DISABLE_ATOMIC_INLINE */
175
176
172 /** 177 /**
173 * \brief A type representing an atomic integer value. It is a struct 178 * \brief A type representing an atomic integer value. It is a struct
174 * so people don't accidentally use numeric operations on it. 179 * so people don't accidentally use numeric operations on it.
175 */ 180 */
176 #ifndef SDL_atomic_t_defined 181 #ifndef SDL_atomic_t_defined