Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Use compiler intrinsics, where available
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Jan 17, 2011
1 parent d5c68ad commit a425d7c
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions include/SDL_atomic.h
Expand Up @@ -113,18 +113,19 @@ extern DECLSPEC void SDLCALL SDL_AtomicUnlock(SDL_SpinLock *lock);
#ifndef SDL_DISABLE_ATOMIC_INLINE

#if defined(__WIN32__)
/* Don't include windows.h, since it may hose code that isn't expecting it,
but if someone has already included it, this is fair game... */
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <intrin.h>

#define SDL_AtomicSet(a, v) InterlockedExchange(&(a)->value, v)
#define SDL_AtomicSet(a, v) _InterlockedExchange(&(a)->value, (v))
#define SDL_AtomicGet(a) ((a)->value)
#define SDL_AtomicAdd(a, v) InterlockedAdd(&(a)->value, v)
#define SDL_AtomicCAS(a, oldval, newval) (InterlockedCompareExchange(&(a)->value, newval, oldval) == (oldval))
#define SDL_AtomicSetPtr(a, v) InterlockedExchangePointer(a, v)
#define SDL_AtomicGetPtr(a) (*(a))
#define SDL_AtomicCASPtr(a, oldval, newval) (InterlockedCompareExchangePointer(a, newval, oldval) == (oldval))
#define SDL_AtomicAdd(a, v) _InterlockedExchangeAdd(&(a)->value, (v))
#define SDL_AtomicCAS(a, oldval, newval) (_InterlockedCompareExchange(&(a)->value, (newval), (oldval)) == (oldval))
#define SDL_AtomicSetPtr(a, v) (void)_InterlockedExchangePointer((a), (v))
#define SDL_AtomicGetPtr(a) (*(a))
#if _M_IX86
#define SDL_AtomicCASPtr(a, oldval, newval) (_InterlockedCompareExchange((long*)(a), (long)(newval), (long)(oldval)) == (long)(oldval))
#else
#define SDL_AtomicCASPtr(a, oldval, newval) (_InterlockedCompareExchangePointer((a), (newval), (oldval)) == (oldval))
#endif

#elif defined(__MACOSX__)
#include <libkern/OSAtomic.h>
Expand Down

0 comments on commit a425d7c

Please sign in to comment.