1-- | Like Control.Concurrent.MVar.Strict but reduce to HNF, not NF
2{-# LANGUAGE MagicHash, UnboxedTuples #-}
3module Control.Distributed.Process.Internal.StrictMVar
4 ( StrictMVar(StrictMVar)
15import Control.Applicative ((<$>))
16import Control.Monad ((>=>))
17import Control.Exception (evaluate)
18import qualified Control.Concurrent.MVar as MVar
28import GHC.MVar (MVar(MVar))
30import GHC.Prim (mkWeak#)
31import GHC.Weak (Weak(Weak))
33newtype StrictMVar a = StrictMVar (MVar.MVar a)
35newEmptyMVar :: IO (StrictMVar a)
36newEmptyMVar = StrictMVar <$> MVar.newEmptyMVar
38newMVar :: a -> IO (StrictMVar a)
39newMVar x = evaluate x >> StrictMVar <$> MVar.newMVar x
41takeMVar :: StrictMVar a -> IO a
42takeMVar (StrictMVar v) = MVar.takeMVar v
44putMVar :: StrictMVar a -> a -> IO ()
45putMVar (StrictMVar v) x = evaluate x >> MVar.putMVar v x
47withMVar :: StrictMVar a -> (a -> IO b) -> IO b
48withMVar (StrictMVar v) = MVar.withMVar v
50modifyMVar_ :: StrictMVar a -> (a -> IO a) -> IO ()
51modifyMVar_ (StrictMVar v) f = MVar.modifyMVar_ v (f >=> evaluate)
53modifyMVar :: StrictMVar a -> (a -> IO (a, b)) -> IO b
54modifyMVar (StrictMVar v) f = MVar.modifyMVar v (f >=> evaluateFst)
56 evaluateFst :: (a, b) -> IO (a, b)
57 evaluateFst (x, y) = evaluate x >> return (x, y)
59mkWeakMVar :: StrictMVar a -> IO () -> IO (Weak (StrictMVar a))
60mkWeakMVar m@(StrictMVar (MVar m#)) f = IO $ \s ->
61 case mkWeak# m# m f s of (# s1, w #) -> (# s1, Weak w #)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list