Skip to content

Commit da74394

Browse files
committed
io-sim: BlockedReason
Added `BlockedOnDelay` and `BlockedOnThrowTo` instead of `BlockedOnOther`.
1 parent 53eb05a commit da74394

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

io-sim/src/Control/Monad/IOSim/CommonTypes.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,6 @@ data ThreadStatus = ThreadRunning
110110
deriving (Eq, Show)
111111

112112
data BlockedReason = BlockedOnSTM
113-
| BlockedOnOther
113+
| BlockedOnDelay
114+
| BlockedOnThrowTo
114115
deriving (Eq, Show)

io-sim/src/Control/Monad/IOSim/Internal.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -834,10 +834,10 @@ unblockThreads !onlySTM !wakeup !simstate@SimState {runqueue, threads} =
834834
!unblocked = [ tid
835835
| tid <- wakeup
836836
, case Map.lookup tid threads of
837-
Just Thread { threadStatus = ThreadBlocked BlockedOnOther }
838-
-> not onlySTM
839837
Just Thread { threadStatus = ThreadBlocked BlockedOnSTM }
840838
-> True
839+
Just Thread { threadStatus = ThreadBlocked _ }
840+
-> not onlySTM
841841
_ -> False
842842
]
843843
-- and in which case we mark them as now running

io-sim/src/Control/Monad/IOSimPOR/Internal.hs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ schedule thread@Thread{
527527
let expiry = d `addTime` time
528528
timers' = PSQ.insert nextTmid expiry (TimerThreadDelay tid nextTmid) timers
529529
thread' = thread { threadControl = ThreadControl (Return ()) (DelayFrame nextTmid k ctl) }
530-
trace <- deschedule (Blocked BlockedOnOther) thread'
530+
trace <- deschedule (Blocked BlockedOnDelay) thread'
531531
simstate { timers = timers',
532532
nextTmid = succ nextTmid }
533533
return (SimPORTrace time tid tstep tlbl (EventThreadDelay nextTmid expiry) trace)
@@ -761,10 +761,10 @@ schedule thread@Thread{
761761
let adjustTarget t =
762762
t { threadThrowTo = (e, Labelled tid tlbl, vClock) : threadThrowTo t }
763763
threads' = Map.adjust adjustTarget tid' threads
764-
trace <- deschedule (Blocked BlockedOnOther) thread' simstate { threads = threads' }
764+
trace <- deschedule (Blocked BlockedOnThrowTo) thread' simstate { threads = threads' }
765765
return $ SimPORTrace time tid tstep tlbl (EventThrowTo e tid')
766766
$ SimPORTrace time tid tstep tlbl EventThrowToBlocked
767-
$ SimPORTrace time tid tstep tlbl (EventDeschedule (Blocked BlockedOnOther))
767+
$ SimPORTrace time tid tstep tlbl (EventDeschedule (Blocked BlockedOnThrowTo))
768768
$ trace
769769
else do
770770
-- The target thread has async exceptions unmasked, or is masked but
@@ -923,10 +923,9 @@ deschedule Sleep thread@Thread { threadId = tid , threadEffect = effect }
923923
reschedule :: SimState s a -> ST s (SimTrace a)
924924

925925
-- If we are following a controlled schedule, just do that.
926-
reschedule simstate@SimState{ runqueue, threads,
927-
control=control@(ControlFollow ((tid,tstep):_) _),
928-
curTime=time
929-
} =
926+
reschedule simstate@SimState { runqueue, threads,
927+
control = control@(ControlFollow ((tid,tstep):_) _),
928+
curTime = time } =
930929
fmap (SimPORTrace time tid tstep Nothing (EventReschedule control)) $
931930
assert (Down tid `PSQ.member` runqueue) $
932931
assert (tid `Map.member` threads) $
@@ -1048,14 +1047,15 @@ unblockThreads !onlySTM vClock wakeup simstate@SimState {runqueue, threads} =
10481047
case Map.lookup tid threads of
10491048
Just Thread { threadStatus = ThreadRunning }
10501049
-> [ ]
1051-
Just t@Thread { threadStatus = ThreadBlocked BlockedOnOther }
1050+
Just t@Thread { threadStatus = ThreadBlocked BlockedOnSTM }
1051+
-> [t]
1052+
Just t@Thread { threadStatus = ThreadBlocked _ }
10521053
| onlySTM
10531054
-> [ ]
10541055
| otherwise
10551056
-> [t]
1056-
Just t@Thread { threadStatus = ThreadBlocked BlockedOnSTM }
1057-
-> [t]
1058-
_ -> [ ]
1057+
Just Thread { threadStatus = ThreadDone } -> [ ]
1058+
Nothing -> [ ]
10591059
]
10601060

10611061
unblockedIds :: [ThreadId]

0 commit comments

Comments
 (0)