Skip to content

Commit ee4dc47

Browse files
committed
io-sim: log EventMask
Log changes to the thread's masking state: * when explicitly changing masking state with `mask`, `uninterruptibleMask` & friends * when a thread continues with 'MaskFrame', i.e. execution continues outside of `mask` / `uninterruptibleMask`. * when mask state is set when we execute a catch frame (see unwindControlStack).
1 parent 5923590 commit ee4dc47

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,7 @@ pattern TraceDeadlock time threads = Trace.Nil (Deadlock time threads)
681681
data SimEventType
682682
= EventSay String
683683
| EventLog Dynamic
684+
| EventMask MaskingState
684685

685686
| EventThrow SomeException
686687
| EventThrowTo SomeException ThreadId -- This thread used ThrowTo
@@ -806,18 +807,20 @@ schedule thread@Thread{
806807
let thread' = thread { threadControl = ThreadControl (k x) ctl'
807808
, threadMasking = maskst' }
808809
-- but if we're now unmasked, check for any pending async exceptions
809-
deschedule Interruptable thread' simstate
810+
trace <- deschedule Interruptable thread' simstate
811+
return (SimTrace time tid tlbl (EventMask maskst') trace)
810812

811813
CatchFrame _handler k ctl' -> do
812814
-- pop the control stack and continue
813815
let thread' = thread { threadControl = ThreadControl (k x) ctl' }
814816
schedule thread' simstate
815817

816818
Throw e -> case unwindControlStack e thread of
817-
Right thread' -> do
819+
Right thread'@Thread { threadMasking = maskst' } -> do
818820
-- We found a suitable exception handler, continue with that
819821
trace <- schedule thread' simstate
820-
return (SimTrace time tid tlbl (EventThrow e) trace)
822+
return (SimTrace time tid tlbl (EventThrow e) $
823+
SimTrace time tid tlbl (EventMask maskst') trace)
821824

822825
Left isMain
823826
-- We unwound and did not find any suitable exception handler, so we
@@ -1050,10 +1053,12 @@ schedule thread@Thread{
10501053
(runIOSim action')
10511054
(MaskFrame k maskst ctl)
10521055
, threadMasking = maskst' }
1053-
case maskst' of
1054-
-- If we're now unmasked then check for any pending async exceptions
1055-
Unmasked -> deschedule Interruptable thread' simstate
1056-
_ -> schedule thread' simstate
1056+
trace <-
1057+
case maskst' of
1058+
-- If we're now unmasked then check for any pending async exceptions
1059+
Unmasked -> deschedule Interruptable thread' simstate
1060+
_ -> schedule thread' simstate
1061+
return (Trace time tid tlbl (EventMask maskst') trace)
10571062

10581063
ThrowTo e tid' _ | tid' == tid -> do
10591064
-- Throw to ourself is equivalent to a synchronous throw,

0 commit comments

Comments
 (0)