Commit fc5dc0dd authored by Sam Lantinga's avatar Sam Lantinga

More fixes for compilation on Visual Studio

parent 81dee435
...@@ -127,7 +127,7 @@ extern DECLSPEC void SDLCALL SDL_AtomicUnlock(SDL_SpinLock *lock); ...@@ -127,7 +127,7 @@ extern DECLSPEC void SDLCALL SDL_AtomicUnlock(SDL_SpinLock *lock);
void _ReadWriteBarrier(void); void _ReadWriteBarrier(void);
#pragma intrinsic(_ReadWriteBarrier) #pragma intrinsic(_ReadWriteBarrier)
#define SDL_CompilerBarrier() _ReadWriteBarrier() #define SDL_CompilerBarrier() _ReadWriteBarrier()
#elif __GNUC__ #elif defined(__GNUC__)
#define SDL_CompilerBarrier() __asm__ __volatile__ ("" : : : "memory") #define SDL_CompilerBarrier() __asm__ __volatile__ ("" : : : "memory")
#else #else
#define SDL_CompilerBarrier() \ #define SDL_CompilerBarrier() \
...@@ -139,7 +139,7 @@ void _ReadWriteBarrier(void); ...@@ -139,7 +139,7 @@ void _ReadWriteBarrier(void);
*/ */
#ifndef SDL_DISABLE_ATOMIC_INLINE #ifndef SDL_DISABLE_ATOMIC_INLINE
#if HAVE_MSC_ATOMICS #ifdef HAVE_MSC_ATOMICS
#define SDL_AtomicSet(a, v) _InterlockedExchange((long*)&(a)->value, (v)) #define SDL_AtomicSet(a, v) _InterlockedExchange((long*)&(a)->value, (v))
#define SDL_AtomicAdd(a, v) _InterlockedExchangeAdd((long*)&(a)->value, (v)) #define SDL_AtomicAdd(a, v) _InterlockedExchangeAdd((long*)&(a)->value, (v))
...@@ -151,7 +151,7 @@ void _ReadWriteBarrier(void); ...@@ -151,7 +151,7 @@ void _ReadWriteBarrier(void);
#define SDL_AtomicCASPtr(a, oldval, newval) (_InterlockedCompareExchangePointer((a), (newval), (oldval)) == (oldval)) #define SDL_AtomicCASPtr(a, oldval, newval) (_InterlockedCompareExchangePointer((a), (newval), (oldval)) == (oldval))
#endif #endif
#elif __MACOSX__ #elif defined(__MACOSX__)
#include <libkern/OSAtomic.h> #include <libkern/OSAtomic.h>
#define SDL_AtomicCAS(a, oldval, newval) OSAtomicCompareAndSwap32Barrier((oldval), (newval), &(a)->value) #define SDL_AtomicCAS(a, oldval, newval) OSAtomicCompareAndSwap32Barrier((oldval), (newval), &(a)->value)
...@@ -161,7 +161,7 @@ void _ReadWriteBarrier(void); ...@@ -161,7 +161,7 @@ void _ReadWriteBarrier(void);
#define SDL_AtomicCASPtr(a, oldval, newval) OSAtomicCompareAndSwap64Barrier((int64_t)(oldval), (int64_t)(newval), (int64_t*)(a)) #define SDL_AtomicCASPtr(a, oldval, newval) OSAtomicCompareAndSwap64Barrier((int64_t)(oldval), (int64_t)(newval), (int64_t*)(a))
#endif #endif
#elif HAVE_GCC_ATOMICS #elif defined(HAVE_GCC_ATOMICS)
#define SDL_AtomicSet(a, v) __sync_lock_test_and_set(&(a)->value, v) #define SDL_AtomicSet(a, v) __sync_lock_test_and_set(&(a)->value, v)
#define SDL_AtomicAdd(a, v) __sync_fetch_and_add(&(a)->value, v) #define SDL_AtomicAdd(a, v) __sync_fetch_and_add(&(a)->value, v)
...@@ -182,32 +182,44 @@ void _ReadWriteBarrier(void); ...@@ -182,32 +182,44 @@ void _ReadWriteBarrier(void);
typedef struct { int value; } SDL_atomic_t; typedef struct { int value; } SDL_atomic_t;
#endif #endif
/**
* \brief Set an atomic variable to a new value if it is currently an old value.
*
* \return SDL_TRUE if the atomic variable was set, SDL_FALSE otherwise.
*
* \note If you don't know what this function is for, you shouldn't use it!
*/
#ifndef SDL_AtomicCAS
#define SDL_AtomicCAS SDL_AtomicCAS_
#endif
extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCAS_(SDL_atomic_t *a, int oldval, int newval);
/** /**
* \brief Set an atomic variable to a value. * \brief Set an atomic variable to a value.
* *
* \return The previous value of the atomic variable. * \return The previous value of the atomic variable.
*/ */
#ifndef SDL_AtomicSet #ifndef SDL_AtomicSet
#define SDL_AtomicSet(a, v) \ static __inline__ int SDL_AtomicSet(SDL_atomic_t *a, int v)
({ \ {
int _value; \ int value;
do { \ do {
_value = (a)->value; \ value = a->value;
} while (!SDL_AtomicCAS(a, _value, (v))); \ } while (!SDL_AtomicCAS(a, value, v));
_value; \ return value;
}) }
#endif #endif
/** /**
* \brief Get the value of an atomic variable * \brief Get the value of an atomic variable
*/ */
#ifndef SDL_AtomicGet #ifndef SDL_AtomicGet
#define SDL_AtomicGet(a) \ static __inline__ int SDL_AtomicGet(SDL_atomic_t *a)
({ \ {
int _value = (a)->value; \ int value = a->value;
SDL_CompilerBarrier(); \ SDL_CompilerBarrier();
_value; \ return value;
}) }
#endif #endif
/** /**
...@@ -218,14 +230,14 @@ typedef struct { int value; } SDL_atomic_t; ...@@ -218,14 +230,14 @@ typedef struct { int value; } SDL_atomic_t;
* \note This same style can be used for any number operation * \note This same style can be used for any number operation
*/ */
#ifndef SDL_AtomicAdd #ifndef SDL_AtomicAdd
#define SDL_AtomicAdd(a, v) \ static __inline__ int SDL_AtomicAdd(SDL_atomic_t *a, int v)
({ \ {
int _value; \ int value;
do { \ do {
_value = (a)->value; \ value = a->value;
} while (!SDL_AtomicCAS(a, _value, (_value + (v)))); \ } while (!SDL_AtomicCAS(a, value, (value + v)));
_value; \ return value;
}) }
#endif #endif
/** /**
...@@ -246,16 +258,16 @@ typedef struct { int value; } SDL_atomic_t; ...@@ -246,16 +258,16 @@ typedef struct { int value; } SDL_atomic_t;
#endif #endif
/** /**
* \brief Set an atomic variable to a new value if it is currently an old value. * \brief Set a pointer to a new value if it is currently an old value.
* *
* \return SDL_TRUE if the atomic variable was set, SDL_FALSE otherwise. * \return SDL_TRUE if the pointer was set, SDL_FALSE otherwise.
* *
* \note If you don't know what this function is for, you shouldn't use it! * \note If you don't know what this function is for, you shouldn't use it!
*/ */
#ifndef SDL_AtomicCAS #ifndef SDL_AtomicCASPtr
#define SDL_AtomicCAS SDL_AtomicCAS_ #define SDL_AtomicCASPtr SDL_AtomicCASPtr_
#endif #endif
extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCAS_(SDL_atomic_t *a, int oldval, int newval); extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCASPtr_(void **a, void *oldval, void *newval);
/** /**
* \brief Set a pointer to a value atomically. * \brief Set a pointer to a value atomically.
...@@ -263,39 +275,28 @@ extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCAS_(SDL_atomic_t *a, int oldval, int ...@@ -263,39 +275,28 @@ extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCAS_(SDL_atomic_t *a, int oldval, int
* \return The previous value of the pointer. * \return The previous value of the pointer.
*/ */
#ifndef SDL_AtomicSetPtr #ifndef SDL_AtomicSetPtr
#define SDL_AtomicSetPtr(a, v) \ static __inline__ void* SDL_AtomicSetPtr(void* *a, void* v)
({ \ {
void* _value; \ void* value;
do { \ do {
_value = *(a); \ value = *a;
} while (!SDL_AtomicCASPtr(a, _value, (v))); \ } while (!SDL_AtomicCASPtr(a, value, v));
_value; \ return value;
}) }
#endif #endif
/** /**
* \brief Get the value of a pointer atomically. * \brief Get the value of a pointer atomically.
*/ */
#ifndef SDL_AtomicGetPtr #ifndef SDL_AtomicGetPtr
#define SDL_AtomicGetPtr(a) \ static __inline__ void* SDL_AtomicGetPtr(void* *a)
({ \ {
void* _value = *(a); \ void* value = *a;
SDL_CompilerBarrier(); \ SDL_CompilerBarrier();
_value; \ return value;
}) }
#endif #endif
/**
* \brief Set a pointer to a new value if it is currently an old value.
*
* \return SDL_TRUE if the pointer was set, SDL_FALSE otherwise.
*
* \note If you don't know what this function is for, you shouldn't use it!
*/
#ifndef SDL_AtomicCASPtr
#define SDL_AtomicCASPtr SDL_AtomicCASPtr_
#endif
extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCASPtr_(void **a, void *oldval, void *newval);
/* Ends C function definitions when using C++ */ /* Ends C function definitions when using C++ */
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -37,20 +37,20 @@ SDL_AtomicTryLock(SDL_SpinLock *lock) ...@@ -37,20 +37,20 @@ SDL_AtomicTryLock(SDL_SpinLock *lock)
SDL_COMPILE_TIME_ASSERT(locksize, sizeof(*lock) == sizeof(long)); SDL_COMPILE_TIME_ASSERT(locksize, sizeof(*lock) == sizeof(long));
return (InterlockedExchange((long*)lock, 1) == 0); return (InterlockedExchange((long*)lock, 1) == 0);
#elif __MACOSX__ #elif defined(__MACOSX__)
return OSAtomicCompareAndSwap32Barrier(0, 1, lock); return OSAtomicCompareAndSwap32Barrier(0, 1, lock);
#elif HAVE_GCC_ATOMICS || HAVE_GCC_SYNC_LOCK_TEST_AND_SET #elif HAVE_GCC_ATOMICS || HAVE_GCC_SYNC_LOCK_TEST_AND_SET
return (__sync_lock_test_and_set(lock, 1) == 0); return (__sync_lock_test_and_set(lock, 1) == 0);
#elif __GNUC__ && __arm__ && __ARM_ARCH_5__ #elif defined(__GNUC__) && defined(__arm__) && defined(__ARM_ARCH_5__)
int result; int result;
__asm__ __volatile__ ( __asm__ __volatile__ (
"swp %0, %1, [%2]\n" "swp %0, %1, [%2]\n"
: "=&r,&r" (result) : "r,0" (1), "r,r" (lock) : "memory"); : "=&r,&r" (result) : "r,0" (1), "r,r" (lock) : "memory");
return (result == 0); return (result == 0);
#elif __GNUC__ && __arm__ #elif defined(__GNUC__) && defined(__arm__)
int result; int result;
__asm__ __volatile__ ( __asm__ __volatile__ (
"ldrex %0, [%2]\nteq %0, #0\nstrexeq %0, %1, [%2]" "ldrex %0, [%2]\nteq %0, #0\nstrexeq %0, %1, [%2]"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment