diff options
author | rpj <rpj> | 2011-06-29 05:10:00 +0000 |
---|---|---|
committer | rpj <rpj> | 2011-06-29 05:10:00 +0000 |
commit | 3f334b78ab4447a37ed40b34c5fdd1aac76d3df7 (patch) | |
tree | 18dee585760e0b4d84efe15647bb5b630621cc7f /implement.h | |
parent | 26ed1ebeb95caec8d733a6a91e71e31312a8eb06 (diff) |
PTW32_INTERLOCKED_* fixups
Diffstat (limited to 'implement.h')
-rw-r--r-- | implement.h | 75 |
1 files changed, 36 insertions, 39 deletions
diff --git a/implement.h b/implement.h index bd2836b..0053193 100644 --- a/implement.h +++ b/implement.h @@ -82,14 +82,14 @@ typedef VOID (APIENTRY *PAPCFUNC)(DWORD dwParam); #define INLINE #endif -#if defined(__MINGW64__) || defined(__MINGW32__) || defined(_MSC_VER) -#define PTW32_INTERLOCKED_LONG unsigned long -#define PTW32_INTERLOCKED_LPLONG volatile unsigned long* +#if defined(_WIN64) +#define PTW32_INTERLOCKED_VALUE size_t +#define PTW32_INTERLOCKED_PTR volatile size_t* #define PTW32_INTERLOCKED_PVOID PVOID #define PTW32_INTERLOCKED_PVOID_PTR volatile PVOID* #else -#define PTW32_INTERLOCKED_LONG PVOID -#define PTW32_INTERLOCKED_LPLONG volatile PVOID* +#define PTW32_INTERLOCKED_VALUE size_t +#define PTW32_INTERLOCKED_PTR volatile size_t* #define PTW32_INTERLOCKED_PVOID PVOID #define PTW32_INTERLOCKED_PVOID_PTR volatile PVOID* #endif @@ -736,13 +736,14 @@ extern "C" * The above aren't available in Mingw32 as of gcc 4.5.2 so define our own. */ #if defined(__GNUC__) +# if defined(_WIN64) # define PTW32_INTERLOCKED_COMPARE_EXCHANGE(location, value, comparand) \ ({ \ __typeof (value) _result; \ __asm__ __volatile__ \ ( \ "lock\n\t" \ - "cmpxchgl %2,(%1)" \ + "cmpxchgq %2,(%1)" \ :"=a" (_result) \ :"r" (location), "r" (value), "a" (comparand) \ :"memory", "cc"); \ @@ -753,7 +754,7 @@ extern "C" __typeof (value) _result; \ __asm__ __volatile__ \ ( \ - "xchgl %0,(%1)" \ + "xchgq %0,(%1)" \ :"=r" (_result) \ :"r" (location), "0" (value) \ :"memory", "cc"); \ @@ -765,7 +766,7 @@ extern "C" __asm__ __volatile__ \ ( \ "lock\n\t" \ - "xaddl %0,(%1)" \ + "xaddq %0,(%1)" \ :"=r" (_result) \ :"r" (location), "0" (value) \ :"memory", "cc"); \ @@ -773,11 +774,11 @@ extern "C" }) # define PTW32_INTERLOCKED_INCREMENT(location) \ ({ \ - long _temp = 1; \ + long long _temp = 1; \ __asm__ __volatile__ \ ( \ "lock\n\t" \ - "xaddl %0,(%1)" \ + "xaddq %0,(%1)" \ :"+r" (_temp) \ :"r" (location) \ :"memory", "cc"); \ @@ -785,100 +786,96 @@ extern "C" }) # define PTW32_INTERLOCKED_DECREMENT(location) \ ({ \ - long _temp = -1; \ + long long _temp = -1; \ __asm__ __volatile__ \ ( \ "lock\n\t" \ - "xaddl %0,(%1)" \ + "xaddq %2,(%1)" \ :"+r" (_temp) \ :"r" (location) \ :"memory", "cc"); \ --_temp; \ }) -# if defined(_WIN64) -# define PTW32_INTERLOCKED_COMPARE_EXCHANGE64(location, value, comparand) \ +#else +# define PTW32_INTERLOCKED_COMPARE_EXCHANGE(location, value, comparand) \ ({ \ __typeof (value) _result; \ __asm__ __volatile__ \ ( \ "lock\n\t" \ - "cmpxchgq %2,(%1)" \ + "cmpxchgl %2,(%1)" \ :"=a" (_result) \ :"r" (location), "r" (value), "a" (comparand) \ :"memory", "cc"); \ _result; \ }) -# define PTW32_INTERLOCKED_EXCHANGE64(location, value) \ +# define PTW32_INTERLOCKED_EXCHANGE(location, value) \ ({ \ __typeof (value) _result; \ __asm__ __volatile__ \ ( \ - "xchgq %0,(%1)" \ + "xchgl %0,(%1)" \ :"=r" (_result) \ :"r" (location), "0" (value) \ :"memory", "cc"); \ _result; \ }) -# define PTW32_INTERLOCKED_EXCHANGE_ADD64(location, value) \ +# define PTW32_INTERLOCKED_EXCHANGE_ADD(location, value) \ ({ \ __typeof (value) _result; \ __asm__ __volatile__ \ ( \ "lock\n\t" \ - "xaddq %0,(%1)" \ + "xaddl %0,(%1)" \ :"=r" (_result) \ :"r" (location), "0" (value) \ :"memory", "cc"); \ _result; \ }) -# define PTW32_INTERLOCKED_INCREMENT64(location) \ +# define PTW32_INTERLOCKED_INCREMENT(location) \ ({ \ long _temp = 1; \ __asm__ __volatile__ \ ( \ "lock\n\t" \ - "xaddq %0,(%1)" \ + "xaddl %0,(%1)" \ :"+r" (_temp) \ :"r" (location) \ :"memory", "cc"); \ ++_temp; \ }) -# define PTW32_INTERLOCKED_DECREMENT64(location) \ +# define PTW32_INTERLOCKED_DECREMENT(location) \ ({ \ long _temp = -1; \ __asm__ __volatile__ \ ( \ "lock\n\t" \ - "xaddq %0,(%1)" \ + "xaddl %0,(%1)" \ :"+r" (_temp) \ :"r" (location) \ :"memory", "cc"); \ --_temp; \ }) -# define PTW32_INTERLOCKED_COMPARE_EXCHANGE_PTR(location, value, comparand) \ - PTW32_INTERLOCKED_COMPARE_EXCHANGE64(location, (size_t)value, (size_t)comparand) -# define PTW32_INTERLOCKED_EXCHANGE_PTR(location, value) \ - PTW32_INTERLOCKED_EXCHANGE64(location, (size_t)value) -# else +#endif # define PTW32_INTERLOCKED_COMPARE_EXCHANGE_PTR(location, value, comparand) \ PTW32_INTERLOCKED_COMPARE_EXCHANGE(location, (size_t)value, (size_t)comparand) # define PTW32_INTERLOCKED_EXCHANGE_PTR(location, value) \ PTW32_INTERLOCKED_EXCHANGE(location, (size_t)value) -# endif #else -# define PTW32_INTERLOCKED_COMPARE_EXCHANGE InterlockedCompareExchange # define PTW32_INTERLOCKED_COMPARE_EXCHANGE_PTR InterlockedCompareExchangePointer -# define PTW32_INTERLOCKED_EXCHANGE InterlockedExchange # define PTW32_INTERLOCKED_EXCHANGE_PTR InterlockedExchangePointer -# define PTW32_INTERLOCKED_EXCHANGE_ADD InterlockedExchangeAdd -# define PTW32_INTERLOCKED_INCREMENT InterlockedIncrement -# define PTW32_INTERLOCKED_DECREMENT InterlockedDecrement # if defined(_WIN64) -# define PTW32_INTERLOCKED_COMPARE_EXCHANGE64 InterlockedCompareExchange64 -# define PTW32_INTERLOCKED_EXCHANGE64 InterlockedExchange64 -# define PTW32_INTERLOCKED_EXCHANGE_ADD64 InterlockedExchangeAdd64 -# define PTW32_INTERLOCKED_INCREMENT64 InterlockedIncrement64 -# define PTW32_INTERLOCKED_DECREMENT64 InterlockedDecrement64 +# define PTW32_INTERLOCKED_COMPARE_EXCHANGE InterlockedCompareExchange64 +# define PTW32_INTERLOCKED_EXCHANGE InterlockedExchange64 +# define PTW32_INTERLOCKED_EXCHANGE_ADD InterlockedExchangeAdd64 +# define PTW32_INTERLOCKED_INCREMENT InterlockedIncrement64 +# define PTW32_INTERLOCKED_DECREMENT InterlockedDecrement64 +# else +# define PTW32_INTERLOCKED_COMPARE_EXCHANGE InterlockedCompareExchange +# define PTW32_INTERLOCKED_EXCHANGE InterlockedExchange +# define PTW32_INTERLOCKED_EXCHANGE_ADD InterlockedExchangeAdd +# define PTW32_INTERLOCKED_INCREMENT InterlockedIncrement +# define PTW32_INTERLOCKED_DECREMENT InterlockedDecrement # endif #endif |