X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=includes%2Fstg%2FSMP.h;h=f1b04220094a146371cffdac4989c9fc9cff5d55;hb=6cec61d14a324285dbb8ce73d4c7215f1f8d6766;hp=8297f5711c32e1f09ff3151f438da7f4ff72a43c;hpb=d20d32d788e2d6c088e6b03776c428df5bb004d3;p=ghc-hetmet.git diff --git a/includes/stg/SMP.h b/includes/stg/SMP.h index 8297f57..f1b0422 100644 --- a/includes/stg/SMP.h +++ b/includes/stg/SMP.h @@ -64,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 /* @@ -216,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 /* @@ -275,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 */ @@ -290,7 +314,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; @@ -313,6 +338,8 @@ atomic_dec(StgVolatilePtr p) return --(*p); } +#define VOLATILE_LOAD(p) ((StgWord)*((StgWord*)(p))) + #endif /* !THREADED_RTS */ #endif /* SMP_H */