long _InterlockedExchangeAdd(long volatile*, long);
long _InterlockedDecrement(long volatile*);
long _InterlockedIncrement(long volatile*);
+void _ReadWriteBarrier(void);
#pragma intrinsic(_InterlockedExchange, _InterlockedCompareExchange)
#pragma intrinsic(_InterlockedExchangeAdd, _InterlockedDecrement)
-#pragma intrinsic(_InterlockedIncrement)
+#pragma intrinsic(_InterlockedIncrement, _ReadWriteBarrier)
#if defined(VM_X86_64)
long _InterlockedAnd(long volatile*, long);
MAKE_ATOMIC_TYPE(Int, 32, int, int, int)
+/* Prevent the compiler from re-ordering memory references. */
+#ifdef __GNUC__
+#define ATOMIC_COMPILER_BARRIER() __asm__ __volatile__ ("": : :"memory")
+#elif defined(_MSC_VER)
+#define ATOMIC_COMPILER_BARRIER() _ReadWriteBarrier()
+#else
+#error No compiler defined for ATOMIC_COMPILER_BARRIER
+#endif
+
+
/*
*-----------------------------------------------------------------------------
*
Atomic_MFence(void)
{
Atomic_uint32 fence;
+ ATOMIC_COMPILER_BARRIER();
Atomic_Xor(&fence, 0x1);
+ ATOMIC_COMPILER_BARRIER();
}
+#ifdef ATOMIC_COMPILER_BARRIER
+#undef ATOMIC_COMPILER_BARRIER
+#endif
+
#endif // ifndef _ATOMIC_H_