X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=includes%2Fstg%2FSMP.h;h=ad8c0baef93ac47501300afa5bab3ba5cd3482bc;hb=34c8d0312071f7d0f4d221a997d3408c653ef9e5;hp=5d9d80169b97fcb2e468756c1c7a744c34363d5e;hpb=a2a67cd520b9841114d69a87a423dabcb3b4368e;p=ghc-hetmet.git diff --git a/includes/stg/SMP.h b/includes/stg/SMP.h index 5d9d801..ad8c0ba 100644 --- a/includes/stg/SMP.h +++ b/includes/stg/SMP.h @@ -1,9 +1,14 @@ /* ---------------------------------------------------------------------------- * - * (c) The GHC Team, 2005-2008 + * (c) The GHC Team, 2005-2009 * * Macros for multi-CPU support * + * 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 SMP_H @@ -59,6 +64,13 @@ EXTERN_INLINE StgWord atomic_inc(StgVolatilePtr p); */ EXTERN_INLINE StgWord atomic_dec(StgVolatilePtr p); +/* + * Busy-wait nop: this is a hint to the CPU that we are currently in a + * busy-wait loop waiting for another CPU to change something. On a + * hypertreaded CPU it should yield to another thread, for example. + */ +EXTERN_INLINE void busy_wait_nop(void); + #endif // !IN_STG_CODE /* @@ -211,6 +223,17 @@ atomic_dec(StgVolatilePtr p) #endif } +EXTERN_INLINE void +busy_wait_nop(void) +{ +#if defined(i386_HOST_ARCH) || defined(x86_64_HOST_ARCH) + __asm__ __volatile__ ("rep; nop"); + // +#else + // nothing +#endif +} + #endif // !IN_STG_CODE /* @@ -270,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 */ @@ -308,6 +337,8 @@ atomic_dec(StgVolatilePtr p) return --(*p); } +#define VOLATILE_LOAD(p) ((StgWord)*((StgWord*)(p))) + #endif /* !THREADED_RTS */ #endif /* SMP_H */