diff options
author | Simon Marlow <marlowsd@gmail.com> | 2009-02-06 13:01:15 +0000 |
---|---|---|
committer | Simon Marlow <marlowsd@gmail.com> | 2009-02-06 13:01:15 +0000 |
commit | aee6d6898bdb8294637df4aa0ef824b268c55a01 (patch) | |
tree | 26ec5bd9015bc851438dab044e40162e25630793 /includes | |
parent | 829a7d022e91da80295913e6c70179f211e5b966 (diff) | |
download | haskell-aee6d6898bdb8294637df4aa0ef824b268c55a01.tar.gz |
add a store/load memory barrier
Diffstat (limited to 'includes')
-rw-r--r-- | includes/SMP.h | 25 |
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) { |