Mesa (gallium-embedded): gallium: Use MSVC atomic intrinsics directly instead of the Windows header wrappers .

Jose Fonseca jrfonseca at kemper.freedesktop.org
Mon Feb 1 16:13:23 UTC 2010


Module: Mesa
Branch: gallium-embedded
Commit: 57839d11ff806d172506e4a5104c1ae3d286df1c
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=57839d11ff806d172506e4a5104c1ae3d286df1c

Author: José Fonseca <jfonseca at vmware.com>
Date:   Mon Feb  1 16:12:44 2010 +0000

gallium: Use MSVC atomic intrinsics directly instead of the Windows header wrappers.

---

 src/gallium/include/pipe/p_atomic.h |   26 +++++++++++++++-----------
 1 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/src/gallium/include/pipe/p_atomic.h b/src/gallium/include/pipe/p_atomic.h
index d505266..a4b769d 100644
--- a/src/gallium/include/pipe/p_atomic.h
+++ b/src/gallium/include/pipe/p_atomic.h
@@ -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




More information about the mesa-commit mailing list