@@ -376,14 +376,16 @@ schedule thread@Thread{
376
376
(Right thread0@ Thread { threadMasking = maskst' }, timers'') -> do
377
377
-- We found a suitable exception handler, continue with that
378
378
-- We record a step, in case there is no exception handler on replay.
379
- let thread' = stepThread thread0
380
- control' = advanceControl (threadStepId thread0) control
381
- races' = updateRacesInSimState thread0 simstate
379
+ let ( thread', eff) = stepThread thread0
380
+ control' = advanceControl (threadStepId thread0) control
381
+ races' = updateRacesInSimState thread0 simstate
382
382
trace <- schedule thread' simstate{ races = races',
383
383
control = control',
384
384
timers = timers'' }
385
385
return (SimPORTrace time tid tstep tlbl (EventThrow e) $
386
- SimPORTrace time tid tstep tlbl (EventMask maskst') trace)
386
+ SimPORTrace time tid tstep tlbl (EventMask maskst') $
387
+ SimPORTrace time tid tstep tlbl (EventEffect vClock eff)
388
+ trace)
387
389
388
390
(Left isMain, timers'')
389
391
-- We unwound and did not find any suitable exception handler, so we
@@ -809,16 +811,24 @@ threadInterruptible thread =
809
811
810
812
deschedule :: Deschedule -> Thread s a -> SimState s a -> ST s (SimTrace a )
811
813
812
- deschedule Yield thread@ Thread { threadId = tid }
813
- simstate@ SimState {runqueue, threads, control} =
814
+ deschedule Yield thread@ Thread { threadId = tid,
815
+ threadStep = tstep,
816
+ threadLabel = tlbl,
817
+ threadVClock = vClock }
818
+ simstate@ SimState {runqueue,
819
+ threads,
820
+ curTime = time,
821
+ control } =
814
822
815
823
-- We don't interrupt runnable threads anywhere else.
816
824
-- We do it here by inserting the current thread into the runqueue in priority order.
817
825
818
- let thread' = stepThread thread
819
- runqueue' = insertThread thread' runqueue
820
- threads' = Map. insert tid thread' threads
821
- control' = advanceControl (threadStepId thread) control in
826
+ let (thread', eff) = stepThread thread
827
+ runqueue' = insertThread thread' runqueue
828
+ threads' = Map. insert tid thread' threads
829
+ control' = advanceControl (threadStepId thread) control in
830
+
831
+ SimPORTrace time tid tstep tlbl (EventEffect vClock eff) <$>
822
832
reschedule simstate { runqueue = runqueue',
823
833
threads = threads',
824
834
races = updateRacesInSimState thread simstate,
@@ -856,11 +866,18 @@ deschedule Interruptable thread@Thread {
856
866
, let tlbl'' = lookupThreadLabel tid'' threads ]
857
867
trace
858
868
859
- deschedule Interruptable thread@ Thread {threadId = tid } simstate@ SimState { control } =
869
+ deschedule Interruptable thread@ Thread {threadId = tid,
870
+ threadStep = tstep,
871
+ threadLabel = tlbl,
872
+ threadVClock = vClock}
873
+ simstate@ SimState { control,
874
+ curTime = time } =
860
875
-- Either masked or unmasked but no pending async exceptions.
861
876
-- Either way, just carry on.
862
877
-- Record a step, though, in case on replay there is an async exception.
863
- let thread' = stepThread thread in
878
+ let (thread', eff) = stepThread thread in
879
+
880
+ SimPORTrace time tid tstep tlbl (EventEffect vClock eff) <$>
864
881
schedule thread'
865
882
simstate{ races = updateRacesInSimState thread simstate,
866
883
control = advanceControl (threadStepId thread) control }
@@ -876,21 +893,29 @@ deschedule (Blocked _blockedReason) thread@Thread { threadId = tid
876
893
-- thread if possible.
877
894
deschedule Interruptable thread { threadMasking = Unmasked } simstate
878
895
879
- deschedule (Blocked blockedReason) thread@ Thread { threadId = tid, threadEffect = effect } simstate@ SimState {threads, control} =
880
- let thread1 = thread { threadStatus = ThreadBlocked blockedReason }
881
- thread' = stepThread thread1
882
- threads' = Map. insert (threadId thread') thread' threads in
896
+ deschedule (Blocked blockedReason) thread@ Thread { threadId = tid,
897
+ threadStep = tstep,
898
+ threadLabel = tlbl,
899
+ threadVClock = vClock}
900
+ simstate@ SimState { threads,
901
+ curTime = time,
902
+ control } =
903
+ let thread1 = thread { threadStatus = ThreadBlocked blockedReason }
904
+ (thread', eff) = stepThread thread1
905
+ threads' = Map. insert (threadId thread') thread' threads in
906
+
907
+ SimPORTrace time tid tstep tlbl (EventEffect vClock eff) <$>
883
908
reschedule simstate { threads = threads',
884
909
races = updateRacesInSimState thread1 simstate,
885
910
control = advanceControl (threadStepId thread1) control }
886
911
887
- deschedule Terminated thread@ Thread { threadId = tid, threadVClock = vClock, threadEffect = effect }
912
+ deschedule Terminated thread@ Thread { threadId = tid, threadLabel = tlbl, threadVClock = vClock, threadEffect = effect }
888
913
simstate@ SimState { curTime = time, control } = do
889
914
-- This thread is done. If there are other threads blocked in a
890
915
-- ThrowTo targeted at this thread then we can wake them up now.
891
- let thread1 = thread
892
- thread' = stepThread $ thread { threadStatus = ThreadDone }
893
- wakeup = map (\ (_,tid',_) -> l_labelled tid') (reverse (threadThrowTo thread))
916
+ let thread1 = thread
917
+ ( thread', eff) = stepThread $ thread { threadStatus = ThreadDone }
918
+ wakeup = map (\ (_,tid',_) -> l_labelled tid') (reverse (threadThrowTo thread))
894
919
(unblocked,
895
920
simstate'@ SimState {threads}) =
896
921
unblockThreads False vClock wakeup simstate
@@ -906,7 +931,8 @@ deschedule Terminated thread@Thread { threadId = tid, threadVClock = vClock, thr
906
931
[ (time, tid', (- 1 ), tlbl', EventThrowToWakeup )
907
932
| tid' <- unblocked
908
933
, let tlbl' = lookupThreadLabel tid' threads ]
909
- trace
934
+ $ SimPORTrace time tid (threadStep thread) tlbl (EventEffect vClock eff)
935
+ trace
910
936
911
937
deschedule Sleep thread@ Thread { threadId = tid , threadEffect = effect }
912
938
simstate@ SimState {runqueue, threads} =
@@ -1672,14 +1698,19 @@ currentStep Thread { threadId = stepThreadId,
1672
1698
threadVClock = stepVClock
1673
1699
} = Step {.. }
1674
1700
1675
- stepThread :: Thread s a -> Thread s a
1701
+ -- | Step a thread and return the previous `StepId` and its `Effect`.
1702
+ --
1703
+ stepThread :: Thread s a -> (Thread s a , Effect )
1676
1704
stepThread thread@ Thread { threadId = tid,
1677
1705
threadStep = tstep,
1678
1706
threadVClock = vClock } =
1679
- thread { threadStep = tstep+ 1 ,
1680
- threadEffect = mempty ,
1681
- threadVClock = insertVClock tid (tstep+ 1 ) vClock
1682
- }
1707
+ ( thread { threadStep = tstep+ 1 ,
1708
+ threadEffect = mempty ,
1709
+ threadVClock = insertVClock tid (tstep+ 1 ) vClock
1710
+ },
1711
+ threadEffect thread
1712
+ )
1713
+
1683
1714
1684
1715
-- As we run a simulation, we collect info about each previous step
1685
1716
data StepInfo = StepInfo {
0 commit comments