Commit d3ad3eec authored by Herbert Valerio Riedel's avatar Herbert Valerio Riedel 🕺
Browse files

Add `withMVarMasked` (re #8818)



Like `withMVar`, but the @IO@ action in the second argument is executed
with asynchronous exceptions masked. This completes the `MVar` API,
which already contained `modifyMVarMasked` and `modifyMVarMasked_`.
Signed-off-by: Herbert Valerio Riedel's avatarHerbert Valerio Riedel <hvr@gnu.org>
parent 4f4f798c
......@@ -139,6 +139,7 @@ module Control.Concurrent.MVar
, tryPutMVar
, isEmptyMVar
, withMVar
, withMVarMasked
, modifyMVar_
, modifyMVar
, modifyMVarMasked_
......@@ -188,6 +189,21 @@ withMVar m io =
putMVar m a
return b
{-|
Like 'withMVar', but the @IO@ action in the second argument is executed
with asynchronous exceptions masked.
/Since: 4.7.0.0/
-}
{-# INLINE withMVarMasked #-}
withMVarMasked :: MVar a -> (a -> IO b) -> IO b
withMVarMasked m io =
mask_ $ do
a <- takeMVar m
b <- io a `onException` putMVar m a
putMVar m a
return b
{-|
An exception-safe wrapper for modifying the contents of an 'MVar'.
Like 'withMVar', 'modifyMVar' will replace the original contents of
......
......@@ -51,6 +51,10 @@
`putMVar`. There is also a new `tryReadMVar` which is a
non-blocking version.
* New `Control.Concurrent.MVar.withMVarMasked` which executes
`IO` action with asynchronous exceptions masked in the same style
as the existing `modifyMVarMasked` and `modifyMVarMasked_`.
* New `threadWait{Read,Write}STM :: Fd -> IO (STM (), IO ())`
functions added to `Control.Concurrent` for waiting on FD
readiness with STM actions.
......
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