summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorSimon Marlow <marlowsd@gmail.com>2009-02-06 13:01:15 +0000
committerSimon Marlow <marlowsd@gmail.com>2009-02-06 13:01:15 +0000
commitaee6d6898bdb8294637df4aa0ef824b268c55a01 (patch)
tree26ec5bd9015bc851438dab044e40162e25630793 /includes
parent829a7d022e91da80295913e6c70179f211e5b966 (diff)
downloadhaskell-aee6d6898bdb8294637df4aa0ef824b268c55a01.tar.gz
add a store/load memory barrier
Diffstat (limited to 'includes')
-rw-r--r--includes/SMP.h25
1 files changed, 25 insertions, 0 deletions
diff --git a/includes/SMP.h b/includes/SMP.h
index bf23e08260..5d74667f86 100644
--- a/includes/SMP.h
+++ b/includes/SMP.h
@@ -60,6 +60,11 @@ EXTERN_INLINE StgWord cas(StgVolatilePtr p, StgWord o, StgWord n);
*/
EXTERN_INLINE void write_barrier(void);
+/*
+ * Prevents loads from moving before earlier stores.
+ */
+EXTERN_INLINE void store_load_barrier(void);
+
/* ----------------------------------------------------------------------------
Implementations
------------------------------------------------------------------------- */
@@ -180,11 +185,31 @@ write_barrier(void) {
#endif
}
+EXTERN_INLINE void
+store_load_barrier(void) {
+#if i386_HOST_ARCH
+ __asm__ __volatile__ ("lock; addl $0,0(%%esp)" : : : "memory");
+#elif x86_64_HOST_ARCH
+ __asm__ __volatile__ ("lock; addq $0,0(%%rsp)" : : : "memory");
+#elif powerpc_HOST_ARCH
+ __asm__ __volatile__ ("msync" : : : "memory");
+#elif sparc_HOST_ARCH
+ /* Sparc in TSO mode does not require write/write barriers. */
+ __asm__ __volatile__ ("membar" : : : "memory");
+#elif !defined(WITHSMP)
+ return;
+#else
+#error memory barriers unimplemented on this architecture
+#endif
+}
+
/* ---------------------------------------------------------------------- */
#else /* !THREADED_RTS */
#define write_barrier() /* nothing */
+#define store_load_barrier() /* nothing */
+
INLINE_HEADER StgWord
xchg(StgPtr p, StgWord w)
{