Skip to content

Commit 10b9966

Browse files
committed
MonadMaskingState: added interruptible and allowInterrupt
Fixes IntersectMBO/ouroboros-network#3436
1 parent cdc8795 commit 10b9966

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

io-classes/src/Control/Monad/Class/MonadThrow.hs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,14 @@ class MonadCatch m => MonadMask m where
186186

187187

188188
class MonadMask m => MonadMaskingState m where
189+
{-# MINIMAL getMaskingState, interruptible #-}
189190
getMaskingState :: m MaskingState
191+
interruptible :: m a -> m a
192+
allowInterrupt :: m ()
193+
194+
allowInterrupt = interruptible (return ())
195+
196+
190197

191198
-- | Monads which can 'evaluate'.
192199
--
@@ -230,6 +237,8 @@ instance MonadMask IO where
230237

231238
instance MonadMaskingState IO where
232239
getMaskingState = IO.getMaskingState
240+
interruptible = IO.interruptible
241+
allowInterrupt = IO.allowInterrupt
233242

234243
instance MonadEvaluate IO where
235244
evaluate = IO.evaluate

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,12 @@ instance MonadMask (IOSim s) where
339339

340340
instance MonadMaskingState (IOSim s) where
341341
getMaskingState = getMaskingStateImpl
342+
interruptible action = do
343+
b <- getMaskingStateImpl
344+
case b of
345+
Unmasked -> action
346+
MaskedInterruptible -> unblock action
347+
MaskedUninterruptible -> action
342348

343349
instance Exceptions.MonadMask (IOSim s) where
344350
mask = MonadThrow.mask

0 commit comments

Comments
 (0)