Use "rep; nop" inside a spin-lock loop on x86/x86-64
[ghc-hetmet.git] / includes / rts / SpinLock.h
index ea992a3..3d0b56c 100644 (file)
@@ -1,6 +1,6 @@
 /* ----------------------------------------------------------------------------
  *
- * (c) The GHC Team, 2006-2008
+ * (c) The GHC Team, 2006-2009
  *
  * Spin locks
  *
  * TODO: measure whether we really need these, or whether Mutexes
  * would do (and be a bit safer if a CPU becomes loaded).
  *
+ * Do not #include this file directly: #include "Rts.h" instead.
+ *
+ * To understand the structure of the RTS headers, see the wiki:
+ *   http://hackage.haskell.org/trac/ghc/wiki/Commentary/SourceTree/Includes
+ *
  * -------------------------------------------------------------------------- */
 
 #ifndef RTS_SPINLOCK_H
@@ -44,6 +49,7 @@ spin:
     r = cas((StgVolatilePtr)&(p->lock), 1, 0);
     if (r == 0) {
         p->spin++;
+        busy_wait_nop();
         goto spin;
     }
 }
@@ -71,6 +77,7 @@ INLINE_HEADER void ACQUIRE_SPIN_LOCK(SpinLock * p)
     StgWord32 r = 0;
     do {
         r = cas((StgVolatilePtr)p, 1, 0);
+        busy_wait_nop();
     } while(r == 0);
 }