Skip to content

Commit ceb048a

Browse files
committed
io-sim-por: backport CancelTimeout handling
Adjust the fix from the commit f460d2f34 to `IOSimPOR`.
1 parent 8830b00 commit ceb048a

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -449,11 +449,27 @@ schedule thread@Thread{
449449
let thread' = thread { threadControl = ThreadControl k ctl }
450450
schedule thread' simstate
451451

452-
CancelTimeout (Timeout _tvar _tvar' tmid) k -> do
452+
CancelTimeout (Timeout tvar _tvar' tmid) k -> do
453453
let timers' = PSQ.delete tmid timers
454-
thread' = thread { threadControl = ThreadControl k ctl }
455-
trace <- schedule thread' simstate { timers = timers' }
456-
return (SimTrace time tid tlbl (EventTimerCancelled tmid) trace)
454+
written <- execAtomically' (runSTM $ writeTVar tvar TimeoutCancelled)
455+
(wakeup, wokeby) <- threadsUnblockedByWrites written
456+
mapM_ (\(SomeTVar var) -> unblockAllThreadsFromTVar var) written
457+
let effect' = effect
458+
<> writeEffects written
459+
<> wakeupEffects wakeup
460+
thread' = thread { threadControl = ThreadControl k ctl
461+
, threadEffect = effect'
462+
}
463+
(unblocked,
464+
simstate') = unblockThreads vClock wakeup simstate
465+
trace <- deschedule Yield thread' simstate' { timers = timers' }
466+
return $ SimTrace time tid tlbl (EventTimerCancelled tmid)
467+
$ traceMany
468+
[ (time, tid', tlbl', EventTxWakeup vids)
469+
| tid' <- unblocked
470+
, let tlbl' = lookupThreadLabel tid' threads
471+
, let Just vids = Set.toList <$> Map.lookup tid' wokeby ]
472+
$ trace
457473

458474
-- cancelling a negative timer is a no-op
459475
CancelTimeout (NegativeTimeout _tmid) k -> do

0 commit comments

Comments
 (0)