X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=rts%2FSTM.c;h=01155b1107acf49191f15cd6df3926271bee127f;hb=73566e25d75588185b0581722406da5c48965c51;hp=424796265aafbd4b585db031ae944c2f709e9944;hpb=a9e6c4411ab70eb2d16aba32c96ee963d86ebdae;p=ghc-hetmet.git diff --git a/rts/STM.c b/rts/STM.c index 4247962..01155b1 100644 --- a/rts/STM.c +++ b/rts/STM.c @@ -90,6 +90,7 @@ #include "SMP.h" #include "STM.h" #include "Storage.h" +#include "Trace.h" #include #include @@ -113,16 +114,7 @@ // If SHAKE is defined then validation will sometime spuriously fail. They helps test // unusualy code paths if genuine contention is rare -#if defined(DEBUG) -#define SHAKE -#if defined(THREADED_RTS) -#define TRACE(_x...) IF_DEBUG(stm, debugBelch("STM (task %p): ", (void *)(unsigned long)(unsigned int)osThreadId()); debugBelch ( _x )) -#else -#define TRACE(_x...) IF_DEBUG(stm, debugBelch ( _x )) -#endif -#else -#define TRACE(_x...) /*Nothing*/ -#endif +#define TRACE(_x...) debugTrace(DEBUG_stm, "STM: " _x) #ifdef SHAKE static const int do_shake = TRUE; @@ -336,15 +328,21 @@ static void park_tso(StgTSO *tso) { } static void unpark_tso(Capability *cap, StgTSO *tso) { - // We will continue unparking threads while they remain on one of the wait - // queues: it's up to the thread itself to remove it from the wait queues - // if it decides to do so when it is scheduled. - if (tso -> why_blocked == BlockedOnSTM) { - TRACE("unpark_tso on tso=%p\n", tso); - unblockOne(cap,tso); - } else { - TRACE("spurious unpark_tso on tso=%p\n", tso); - } + // We will continue unparking threads while they remain on one of the wait + // queues: it's up to the thread itself to remove it from the wait queues + // if it decides to do so when it is scheduled. + + // Unblocking a TSO from BlockedOnSTM is done under the TSO lock, + // to avoid multiple CPUs unblocking the same TSO, and also to + // synchronise with throwTo(). + lockTSO(tso); + if (tso -> why_blocked == BlockedOnSTM) { + TRACE("unpark_tso on tso=%p\n", tso); + unblockOne(cap,tso); + } else { + TRACE("spurious unpark_tso on tso=%p\n", tso); + } + unlockTSO(tso); } static void unpark_waiters_on(Capability *cap, StgTVar *s) {