Refactor cross-plattform process spawning from ghc-inplace into shell-tools.c
[ghc-hetmet.git] / includes / SMP.h
index b410c6e..a91e5d5 100644 (file)
  *      Unregisterised builds are ok, but only 1 CPU supported.
  */
 
+#ifdef CMINUSMINUS
+
+#define unlockClosure(ptr,info)                 \
+    prim %write_barrier() [];                   \
+    StgHeader_info(ptr) = info;    
+
+#else
+
 #if defined(THREADED_RTS)
 
 #if  defined(TICKY_TICKY)
@@ -75,7 +83,7 @@ xchg(StgPtr p, StgWord w)
         "1:     lwarx     %0, 0, %2\n"
         "       stwcx.    %1, 0, %2\n"
         "       bne-      1b"
-        :"=r" (result)
+        :"=&r" (result)
         :"r" (w), "r" (p)
     );
 #elif sparc_HOST_ARCH
@@ -103,7 +111,7 @@ cas(StgVolatilePtr p, StgWord o, StgWord n)
 {
 #if i386_HOST_ARCH || x86_64_HOST_ARCH
     __asm__ __volatile__ (
-         "lock/cmpxchg %3,%1"
+         "lock\ncmpxchg %3,%1"
           :"=a"(o), "=m" (*(volatile unsigned int *)p) 
           :"0" (o), "r" (n));
     return o;
@@ -175,7 +183,15 @@ write_barrier(void) {
 
 #define SPIN_COUNT 4000
 
-INLINE_HEADER StgInfoTable *
+#ifdef KEEP_LOCKCLOSURE
+// We want a callable copy of lockClosure() so that we can refer to it
+// from .cmm files compiled using the native codegen.
+extern StgInfoTable *lockClosure(StgClosure *p);
+INLINE_ME
+#else
+INLINE_HEADER
+#endif
+StgInfoTable *
 lockClosure(StgClosure *p)
 {
     StgWord info;
@@ -190,7 +206,7 @@ lockClosure(StgClosure *p)
 }
 
 INLINE_HEADER void
-unlockClosure(StgClosure *p, StgInfoTable *info)
+unlockClosure(StgClosure *p, const StgInfoTable *info)
 {
     // This is a strictly ordered write, so we need a write_barrier():
     write_barrier();
@@ -303,7 +319,7 @@ lockClosure(StgClosure *p)
 { return (StgInfoTable *)p->header.info; }
 
 INLINE_HEADER void
-unlockClosure(StgClosure *p STG_UNUSED, StgInfoTable *info STG_UNUSED)
+unlockClosure(StgClosure *p STG_UNUSED, const StgInfoTable *info STG_UNUSED)
 { /* nothing */ }
 
 // Using macros here means we don't have to ensure the argument is in scope
@@ -320,6 +336,8 @@ INLINE_HEADER void lockTSO(StgTSO *tso)
 { lockClosure((StgClosure *)tso); }
 
 INLINE_HEADER void unlockTSO(StgTSO *tso)
-{ unlockClosure((StgClosure*)tso, (StgInfoTable*)&stg_TSO_info); }
+{ unlockClosure((StgClosure*)tso, (const StgInfoTable *)&stg_TSO_info); }
 
 #endif /* SMP_H */
+
+#endif /* CMINUSMINUS */