X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=includes%2FSMP.h;h=af4174fca601b285d1a960ae16f5cacc34f5693f;hp=5974c962add936413d76506066940fe06cf46224;hb=143f4381d242e4a1c3174e8a0732a1e48f00a1aa;hpb=0065d5ab628975892cea1ec7303f968c3338cbe1 diff --git a/includes/SMP.h b/includes/SMP.h index 5974c96..af4174f 100644 --- a/includes/SMP.h +++ b/includes/SMP.h @@ -48,6 +48,16 @@ xchg(StgPtr p, StgWord w) :"=r" (result) :"r" (w), "r" (p) ); +#elif sparc_HOST_ARCH + result = w; + __asm__ __volatile__ ( + "swap %1,%0" + : "+r" (result), "+m" (*p) + : /* no input-only operands */ + ); +#elif !defined(WITHSMP) + result = *p; + *p = w; #else #error xchg() unimplemented on this architecture #endif @@ -76,9 +86,25 @@ cas(StgVolatilePtr p, StgWord o, StgWord n) " stwcx. %2, 0, %3\n" " bne- 1b\n" "2:" - :"=r" (result) + :"=&r" (result) :"r" (o), "r" (n), "r" (p) + :"cc", "memory" + ); + return result; +#elif sparc_HOST_ARCH + __asm__ __volatile__ ( + "cas [%1], %2, %0" + : "+r" (n) + : "r" (p), "r" (o) + : "memory" ); + return n; +#elif !defined(WITHSMP) + StgWord result; + result = *p; + if (result == o) { + *p = n; + } return result; #else #error cas() unimplemented on this architecture @@ -96,11 +122,16 @@ cas(StgVolatilePtr p, StgWord o, StgWord n) * that require it (not x86 or x86_64). */ INLINE_HEADER void -wb(void) { +write_barrier(void) { #if i386_HOST_ARCH || x86_64_HOST_ARCH __asm__ __volatile__ ("" : : : "memory"); #elif powerpc_HOST_ARCH __asm__ __volatile__ ("lwsync" : : : "memory"); +#elif sparc_HOST_ARCH + /* Sparc in TSO mode does not require write/write barriers. */ + __asm__ __volatile__ ("" : : : "memory"); +#elif !defined(WITHSMP) + return; #else #error memory barriers unimplemented on this architecture #endif @@ -116,7 +147,6 @@ wb(void) { INLINE_HEADER StgInfoTable * lockClosure(StgClosure *p) { -#if i386_HOST_ARCH || x86_64_HOST_ARCH || powerpc_HOST_ARCH StgWord info; do { nat i = 0; @@ -126,26 +156,19 @@ lockClosure(StgClosure *p) } while (++i < SPIN_COUNT); yieldThread(); } while (1); -#else - ACQUIRE_SM_LOCK -#endif } INLINE_HEADER void unlockClosure(StgClosure *p, StgInfoTable *info) { -#if i386_HOST_ARCH || x86_64_HOST_ARCH || powerpc_HOST_ARCH // This is a strictly ordered write, so we need a wb(): - wb(); + write_barrier(); p->header.info = info; -#else - RELEASE_SM_LOCK; -#endif } #else /* !THREADED_RTS */ -#define wb() /* nothing */ +#define write_barrier() /* nothing */ INLINE_HEADER StgWord xchg(StgPtr p, StgWord w) @@ -155,6 +178,21 @@ xchg(StgPtr p, StgWord w) return old; } +INLINE_HEADER StgInfoTable * +lockClosure(StgClosure *p) +{ return (StgInfoTable *)p->header.info; } + +INLINE_HEADER void +unlockClosure(StgClosure *p STG_UNUSED, StgInfoTable *info STG_UNUSED) +{ /* nothing */ } + #endif /* !THREADED_RTS */ +// Handy specialised versions of lockClosure()/unlockClosure() +INLINE_HEADER void lockTSO(StgTSO *tso) +{ lockClosure((StgClosure *)tso); } + +INLINE_HEADER void unlockTSO(StgTSO *tso) +{ unlockClosure((StgClosure*)tso, (StgInfoTable*)&stg_TSO_info); } + #endif /* SMP_H */