@@ -97,7 +97,8 @@ import Control.Monad.Class.MonadSay
97
97
import Control.Monad.Class.MonadST
98
98
import Control.Monad.Class.MonadSTM hiding (STM , TVar )
99
99
import qualified Control.Monad.Class.MonadSTM as MonadSTM
100
- import Control.Monad.Class.MonadThrow as MonadThrow
100
+ import Control.Monad.Class.MonadThrow hiding (getMaskingState )
101
+ import qualified Control.Monad.Class.MonadThrow as MonadThrow
101
102
import Control.Monad.Class.MonadTime
102
103
import Control.Monad.Class.MonadTimer
103
104
@@ -174,9 +175,6 @@ type STMSim = STM
174
175
type SimSTM = STM
175
176
{-# DEPRECATED SimSTM "Use STMSim" #-}
176
177
177
- data MaskingState = Unmasked | MaskedInterruptible | MaskedUninterruptible
178
- deriving (Eq , Ord , Show )
179
-
180
178
--
181
179
-- Monad class instances
182
180
--
@@ -300,19 +298,22 @@ instance Exceptions.MonadCatch (IOSim s) where
300
298
301
299
instance MonadMask (IOSim s ) where
302
300
mask action = do
303
- b <- getMaskingState
301
+ b <- getMaskingStateImpl
304
302
case b of
305
303
Unmasked -> block $ action unblock
306
304
MaskedInterruptible -> action block
307
305
MaskedUninterruptible -> action blockUninterruptible
308
306
309
307
uninterruptibleMask action = do
310
- b <- getMaskingState
308
+ b <- getMaskingStateImpl
311
309
case b of
312
310
Unmasked -> blockUninterruptible $ action unblock
313
311
MaskedInterruptible -> blockUninterruptible $ action block
314
312
MaskedUninterruptible -> action blockUninterruptible
315
313
314
+ instance MonadMaskingState (IOSim s ) where
315
+ getMaskingState = getMaskingStateImpl
316
+
316
317
instance Exceptions. MonadMask (IOSim s ) where
317
318
mask = MonadThrow. mask
318
319
uninterruptibleMask = MonadThrow. uninterruptibleMask
@@ -327,10 +328,10 @@ instance Exceptions.MonadMask (IOSim s) where
327
328
return (b, c)
328
329
329
330
330
- getMaskingState :: IOSim s MaskingState
331
+ getMaskingStateImpl :: IOSim s MaskingState
331
332
unblock , block , blockUninterruptible :: IOSim s a -> IOSim s a
332
333
333
- getMaskingState = IOSim GetMaskState
334
+ getMaskingStateImpl = IOSim GetMaskState
334
335
unblock a = IOSim (SetMaskState Unmasked a)
335
336
block a = IOSim (SetMaskState MaskedInterruptible a)
336
337
blockUninterruptible a = IOSim (SetMaskState MaskedUninterruptible a)
@@ -1064,8 +1065,7 @@ schedule thread@Thread{
1064
1065
ThrowTo e tid' _ | tid' == tid -> do
1065
1066
-- Throw to ourself is equivalent to a synchronous throw,
1066
1067
-- and works irrespective of masking state since it does not block.
1067
- let thread' = thread { threadControl = ThreadControl (Throw e) ctl
1068
- , threadMasking = MaskedInterruptible }
1068
+ let thread' = thread { threadControl = ThreadControl (Throw e) ctl }
1069
1069
trace <- schedule thread' simstate
1070
1070
return (SimTrace time tid tlbl (EventThrowTo e tid) trace)
1071
1071
@@ -1096,7 +1096,7 @@ schedule thread@Thread{
1096
1096
let adjustTarget t@ Thread { threadControl = ThreadControl _ ctl' } =
1097
1097
t { threadControl = ThreadControl (Throw e) ctl'
1098
1098
, threadBlocked = False
1099
- , threadMasking = MaskedInterruptible }
1099
+ }
1100
1100
simstate'@ SimState { threads = threads' }
1101
1101
= snd (unblockThreads [tid'] simstate)
1102
1102
threads'' = Map. adjust adjustTarget tid' threads'
@@ -1290,9 +1290,13 @@ unwindControlStack e thread =
1290
1290
-- As per async exception rules, the handler is run masked
1291
1291
threadControl = ThreadControl (handler e')
1292
1292
(MaskFrame k maskst ctl),
1293
- threadMasking = max maskst MaskedInterruptible
1293
+ threadMasking = atLeastInterruptibleMask maskst
1294
1294
}
1295
1295
1296
+ atLeastInterruptibleMask :: MaskingState -> MaskingState
1297
+ atLeastInterruptibleMask Unmasked = MaskedInterruptible
1298
+ atLeastInterruptibleMask ms = ms
1299
+
1296
1300
1297
1301
removeMinimums :: (Ord k , Ord p )
1298
1302
=> OrdPSQ k p a
0 commit comments