merge GHC HEAD
[ghc-hetmet.git] / includes / stg / SMP.h
index b302f48..52fd6f1 100644 (file)
@@ -293,6 +293,12 @@ load_load_barrier(void) {
 #endif
 }
 
+// Load a pointer from a memory location that might be being modified
+// concurrently.  This prevents the compiler from optimising away
+// multiple loads of the memory location, as it might otherwise do in
+// a busy wait loop for example.
+#define VOLATILE_LOAD(p) (*((StgVolatilePtr)(p)))
+
 /* ---------------------------------------------------------------------- */
 #else /* !THREADED_RTS */
 
@@ -300,6 +306,7 @@ load_load_barrier(void) {
 #define store_load_barrier() /* nothing */
 #define load_load_barrier()  /* nothing */
 
+#if !IN_STG_CODE || IN_STGCRUN
 INLINE_HEADER StgWord
 xchg(StgPtr p, StgWord w)
 {
@@ -308,7 +315,8 @@ xchg(StgPtr p, StgWord w)
     return old;
 }
 
-STATIC_INLINE StgWord
+EXTERN_INLINE StgWord cas(StgVolatilePtr p, StgWord o, StgWord n);
+EXTERN_INLINE StgWord
 cas(StgVolatilePtr p, StgWord o, StgWord n)
 {
     StgWord result;
@@ -330,6 +338,9 @@ atomic_dec(StgVolatilePtr p)
 {
     return --(*p);
 }
+#endif
+
+#define VOLATILE_LOAD(p) ((StgWord)*((StgWord*)(p)))
 
 #endif /* !THREADED_RTS */