gallium: Use MSVC atomic intrinsics directly instead of the Windows header wrappers.
authorJosé Fonseca <jfonseca@vmware.com>
Mon, 1 Feb 2010 16:12:44 +0000 (16:12 +0000)
committerJosé Fonseca <jfonseca@vmware.com>
Mon, 1 Feb 2010 16:12:44 +0000 (16:12 +0000)
src/gallium/include/pipe/p_atomic.h

index d50526662fed596cfaf2284eb66e255f77192b1d..a4b769d0bf5fc40bdd99be0bef63a5bf96ab35df 100644 (file)
@@ -26,8 +26,8 @@ extern "C" {
 #if (defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY) || \
      defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT))
 #define PIPE_ATOMIC_OS_UNLOCKED 
-#elif (defined(PIPE_CC_MSVC) && defined(PIPE_SUBSYSTEM_WINDOWS_USER))
-#define PIPE_ATOMIC_OS_MS_INTERLOCK
+#elif defined(PIPE_CC_MSVC)
+#define PIPE_ATOMIC_MSVC_INTRINSIC
 #elif (defined(PIPE_CC_MSVC) && defined(PIPE_ARCH_X86))
 #define PIPE_ATOMIC_ASM_MSVC_X86                
 #elif (defined(PIPE_CC_GCC) && defined(PIPE_ARCH_X86))
@@ -217,42 +217,46 @@ p_atomic_cmpxchg(struct pipe_atomic *v, int32_t old, int32_t _new)
 #endif
 
 
-#if defined(PIPE_ATOMIC_OS_MS_INTERLOCK)
+#if defined(PIPE_ATOMIC_MSVC_INTRINSIC)
 
-#define PIPE_ATOMIC "MS userspace interlocks"
-
-#include <windows.h>
+#define PIPE_ATOMIC "MSVC Intrinsics"
 
 struct pipe_atomic
 {
-   volatile long count;
+   int32_t count;
 };
 
+#include <intrin.h>
+
+#pragma intrinsic(_InterlockedIncrement)
+#pragma intrinsic(_InterlockedDecrement)
+#pragma intrinsic(_InterlockedCompareExchange)
+
 #define p_atomic_set(_v, _i) ((_v)->count = (_i))
 #define p_atomic_read(_v) ((_v)->count)
 
 static INLINE boolean
 p_atomic_dec_zero(struct pipe_atomic *v)
 {
-   return InterlockedDecrement(&v->count) == 0;
+   return _InterlockedDecrement(&v->count) == 0;
 }
 
 static INLINE void
 p_atomic_inc(struct pipe_atomic *v)
 {
-   InterlockedIncrement(&v->count);
+   _InterlockedIncrement(&v->count);
 }
 
 static INLINE void
 p_atomic_dec(struct pipe_atomic *v)
 {
-   InterlockedDecrement(&v->count);
+   _InterlockedDecrement(&v->count);
 }
 
 static INLINE int32_t
 p_atomic_cmpxchg(struct pipe_atomic *v, int32_t old, int32_t _new)
 {
-   return InterlockedCompareExchange(&v->count, _new, old);
+   return _InterlockedCompareExchange(&v->count, _new, old);
 }
 
 #endif