include/SDL_atomic.h
changeset 8088 e5d77d5e0fe2
parent 7678 286c42d7c5ed
child 8149 681eb46b8ac4
     1.1 --- a/include/SDL_atomic.h	Sun Nov 24 21:15:58 2013 -0500
     1.2 +++ b/include/SDL_atomic.h	Sun Nov 24 21:04:51 2013 -0500
     1.3 @@ -64,13 +64,6 @@
     1.4  
     1.5  #include "begin_code.h"
     1.6  
     1.7 -/* Need to do this here because intrin.h has C++ code in it */
     1.8 -/* Visual Studio 2005 has a bug where intrin.h conflicts with winnt.h */
     1.9 -#if defined(_MSC_VER) && (_MSC_VER >= 1500)
    1.10 -#include <intrin.h>
    1.11 -#define HAVE_MSC_ATOMICS 1
    1.12 -#endif
    1.13 -
    1.14  /* Set up for C function definitions, even when using C++ */
    1.15  #ifdef __cplusplus
    1.16  extern "C" {
    1.17 @@ -181,57 +174,11 @@
    1.18  #define SDL_MemoryBarrierAcquire()  SDL_CompilerBarrier()
    1.19  #endif
    1.20  
    1.21 -
    1.22 -/* Platform specific optimized versions of the atomic functions,
    1.23 - * you can disable these by defining SDL_DISABLE_ATOMIC_INLINE
    1.24 - */
    1.25 -#if defined(SDL_ATOMIC_DISABLED) && SDL_ATOMIC_DISABLED
    1.26 -#define SDL_DISABLE_ATOMIC_INLINE
    1.27 -#endif
    1.28 -#ifndef SDL_DISABLE_ATOMIC_INLINE
    1.29 -
    1.30 -#ifdef HAVE_MSC_ATOMICS
    1.31 -
    1.32 -#define SDL_AtomicSet(a, v)     _InterlockedExchange((long*)&(a)->value, (v))
    1.33 -#define SDL_AtomicAdd(a, v)     _InterlockedExchangeAdd((long*)&(a)->value, (v))
    1.34 -#define SDL_AtomicCAS(a, oldval, newval) (_InterlockedCompareExchange((long*)&(a)->value, (newval), (oldval)) == (oldval))
    1.35 -#define SDL_AtomicSetPtr(a, v)  _InterlockedExchangePointer((a), (v))
    1.36 -#if _M_IX86
    1.37 -#define SDL_AtomicCASPtr(a, oldval, newval) (_InterlockedCompareExchange((long*)(a), (long)(newval), (long)(oldval)) == (long)(oldval))
    1.38 -#else
    1.39 -#define SDL_AtomicCASPtr(a, oldval, newval) (_InterlockedCompareExchangePointer((a), (newval), (oldval)) == (oldval))
    1.40 -#endif
    1.41 -
    1.42 -#elif defined(__MACOSX__)
    1.43 -#include <libkern/OSAtomic.h>
    1.44 -
    1.45 -#define SDL_AtomicCAS(a, oldval, newval) OSAtomicCompareAndSwap32Barrier((oldval), (newval), &(a)->value)
    1.46 -#ifdef __LP64__
    1.47 -#define SDL_AtomicCASPtr(a, oldval, newval) OSAtomicCompareAndSwap64Barrier((int64_t)(oldval), (int64_t)(newval), (int64_t*)(a))
    1.48 -#else
    1.49 -#define SDL_AtomicCASPtr(a, oldval, newval) OSAtomicCompareAndSwap32Barrier((int32_t)(oldval), (int32_t)(newval), (int32_t*)(a))
    1.50 -#endif
    1.51 -
    1.52 -#elif defined(HAVE_GCC_ATOMICS)
    1.53 -
    1.54 -#define SDL_AtomicSet(a, v)     __sync_lock_test_and_set(&(a)->value, v)
    1.55 -#define SDL_AtomicAdd(a, v)     __sync_fetch_and_add(&(a)->value, v)
    1.56 -#define SDL_AtomicSetPtr(a, v)  __sync_lock_test_and_set(a, v)
    1.57 -#define SDL_AtomicCAS(a, oldval, newval) __sync_bool_compare_and_swap(&(a)->value, oldval, newval)
    1.58 -#define SDL_AtomicCASPtr(a, oldval, newval) __sync_bool_compare_and_swap(a, oldval, newval)
    1.59 -
    1.60 -#endif
    1.61 -
    1.62 -#endif /* !SDL_DISABLE_ATOMIC_INLINE */
    1.63 -
    1.64 -
    1.65  /**
    1.66   * \brief A type representing an atomic integer value.  It is a struct
    1.67   *        so people don't accidentally use numeric operations on it.
    1.68   */
    1.69 -#ifndef SDL_atomic_t_defined
    1.70  typedef struct { int value; } SDL_atomic_t;
    1.71 -#endif
    1.72  
    1.73  /**
    1.74   * \brief Set an atomic variable to a new value if it is currently an old value.
    1.75 @@ -240,37 +187,19 @@
    1.76   *
    1.77   * \note If you don't know what this function is for, you shouldn't use it!
    1.78  */
    1.79 -#ifndef SDL_AtomicCAS
    1.80  extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCAS(SDL_atomic_t *a, int oldval, int newval);
    1.81 -#endif
    1.82  
    1.83  /**
    1.84   * \brief Set an atomic variable to a value.
    1.85   *
    1.86   * \return The previous value of the atomic variable.
    1.87   */
    1.88 -#ifndef SDL_AtomicSet
    1.89 -SDL_FORCE_INLINE int SDL_AtomicSet(SDL_atomic_t *a, int v)
    1.90 -{
    1.91 -    int value;
    1.92 -    do {
    1.93 -        value = a->value;
    1.94 -    } while (!SDL_AtomicCAS(a, value, v));
    1.95 -    return value;
    1.96 -}
    1.97 -#endif
    1.98 +extern DECLSPEC int SDLCALL SDL_AtomicSet(SDL_atomic_t *a, int v);
    1.99  
   1.100  /**
   1.101   * \brief Get the value of an atomic variable
   1.102   */
   1.103 -#ifndef SDL_AtomicGet
   1.104 -SDL_FORCE_INLINE int SDL_AtomicGet(SDL_atomic_t *a)
   1.105 -{
   1.106 -    int value = a->value;
   1.107 -    SDL_CompilerBarrier();
   1.108 -    return value;
   1.109 -}
   1.110 -#endif
   1.111 +extern DECLSPEC int SDLCALL SDL_AtomicGet(SDL_atomic_t *a);
   1.112  
   1.113  /**
   1.114   * \brief Add to an atomic variable.
   1.115 @@ -279,16 +208,7 @@
   1.116   *
   1.117   * \note This same style can be used for any number operation
   1.118   */
   1.119 -#ifndef SDL_AtomicAdd
   1.120 -SDL_FORCE_INLINE int SDL_AtomicAdd(SDL_atomic_t *a, int v)
   1.121 -{
   1.122 -    int value;
   1.123 -    do {
   1.124 -        value = a->value;
   1.125 -    } while (!SDL_AtomicCAS(a, value, (value + v)));
   1.126 -    return value;
   1.127 -}
   1.128 -#endif
   1.129 +extern DECLSPEC int SDLCALL SDL_AtomicAdd(SDL_atomic_t *a, int v);
   1.130  
   1.131  /**
   1.132   * \brief Increment an atomic variable used as a reference count.
   1.133 @@ -314,38 +234,19 @@
   1.134   *
   1.135   * \note If you don't know what this function is for, you shouldn't use it!
   1.136  */
   1.137 -#ifndef SDL_AtomicCASPtr
   1.138 -extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCASPtr(void* *a, void *oldval, void *newval);
   1.139 -#endif
   1.140 +extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCASPtr(void **a, void *oldval, void *newval);
   1.141  
   1.142  /**
   1.143   * \brief Set a pointer to a value atomically.
   1.144   *
   1.145   * \return The previous value of the pointer.
   1.146   */
   1.147 -#ifndef SDL_AtomicSetPtr
   1.148 -SDL_FORCE_INLINE void* SDL_AtomicSetPtr(void* *a, void* v)
   1.149 -{
   1.150 -    void* value;
   1.151 -    do {
   1.152 -        value = *a;
   1.153 -    } while (!SDL_AtomicCASPtr(a, value, v));
   1.154 -    return value;
   1.155 -}
   1.156 -#endif
   1.157 +extern DECLSPEC void* SDLCALL SDL_AtomicSetPtr(void **a, void* v);
   1.158  
   1.159  /**
   1.160   * \brief Get the value of a pointer atomically.
   1.161   */
   1.162 -#ifndef SDL_AtomicGetPtr
   1.163 -SDL_FORCE_INLINE void* SDL_AtomicGetPtr(void* *a)
   1.164 -{
   1.165 -    void* value = *a;
   1.166 -    SDL_CompilerBarrier();
   1.167 -    return value;
   1.168 -}
   1.169 -#endif
   1.170 -
   1.171 +extern DECLSPEC void* SDLCALL SDL_AtomicGetPtr(void **a);
   1.172  
   1.173  /* Ends C function definitions when using C++ */
   1.174  #ifdef __cplusplus