Commit 2b25a589 authored by Facundo Domínguez's avatar Facundo Domínguez Committed by Ben Gamari
Browse files

base: Have the argument of mask restore the state.

The implementation of `mask` and `uninterruptibleMask` assumed so far
that the restore argument would be called in a context with the same
masking state as that set by `mask` or `uninterruptibleMask`.

This patch has the restore argument restore the masking, whatever the
current masking state is.

Test Plan: validate

Reviewers: simonmar, hvr, austin, bgamari

Reviewed By: bgamari

Subscribers: thomie, qnikst

Differential Revision: https://phabricator.haskell.org/D1327

GHC Trac Issues: #10149
parent 7bbb61bc
......@@ -453,7 +453,8 @@ mask io = do
b <- getMaskingState
case b of
Unmasked -> block $ io unblock
_ -> io id
MaskedInterruptible -> io block
MaskedUninterruptible -> io blockUninterruptible
uninterruptibleMask_ io = uninterruptibleMask $ \_ -> io
......@@ -462,7 +463,7 @@ uninterruptibleMask io = do
case b of
Unmasked -> blockUninterruptible $ io unblock
MaskedInterruptible -> blockUninterruptible $ io block
MaskedUninterruptible -> io id
MaskedUninterruptible -> io blockUninterruptible
bracket
:: IO a -- ^ computation to run first (\"acquire resource\")
......
......@@ -2,6 +2,9 @@
## 4.8.2.0 *TBA*
* The restore operation provided by `mask` and `uninterruptibleMask` now
restores the previous masking state whatever the current masking state is.
* Bundled with GHC 7.12.1
* `Alt`, `Dual`, `First`, `Last`, `Product`, and `Sum` now have `Data`,
......
import Control.Concurrent
import Control.Exception
main :: IO ()
main = do
mask $ \unmask -> mask $ \restore ->
unmask $ restore $ getMaskingState >>= print
uninterruptibleMask $ \unmask -> uninterruptibleMask $ \restore ->
unmask $ restore $ getMaskingState >>= print
mv <- newEmptyMVar
mask_ $ -- start with exceptions masked
mask $ \restore -> forkIOWithUnmask $ \unmask -> unmask $
restore $ getMaskingState >>= print >> putMVar mv ()
takeMVar mv
uninterruptibleMask_ $ -- start with exceptions uninterruptibly masked
uninterruptibleMask $ \restore -> forkIOWithUnmask $ \unmask -> unmask $
restore $ getMaskingState >>= print >> putMVar mv ()
takeMVar mv
MaskedInterruptible
MaskedUninterruptible
MaskedInterruptible
MaskedUninterruptible
......@@ -209,3 +209,4 @@ test('T9848',
, only_ways(['normal'])],
compile_and_run,
['-O'])
test('T10149',normal, compile_and_run,[''])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment