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)
16import Control.Applicative ((<$>))
17import Control.Monad ((>=>))
18import Control.Exception (evaluate)
19import qualified Control.Concurrent.MVar as MVar
30import GHC.MVar (MVar(MVar))
32import GHC.Prim (mkWeak#)
33import GHC.Weak (Weak(Weak))
35newtype StrictMVar a = StrictMVar (MVar.MVar a)
37newEmptyMVar :: IO (StrictMVar a)
38newEmptyMVar = StrictMVar <$> MVar.newEmptyMVar
40newMVar :: a -> IO (StrictMVar a)
41newMVar x = evaluate x >> StrictMVar <$> MVar.newMVar x
43takeMVar :: StrictMVar a -> IO a
44takeMVar (StrictMVar v) = MVar.takeMVar v
46putMVar :: StrictMVar a -> a -> IO ()
47putMVar (StrictMVar v) x = evaluate x >> MVar.putMVar v x
49readMVar :: StrictMVar a -> IO a
50readMVar (StrictMVar v) = MVar.readMVar v
52withMVar :: StrictMVar a -> (a -> IO b) -> IO b
53withMVar (StrictMVar v) = MVar.withMVar v
55modifyMVar_ :: StrictMVar a -> (a -> IO a) -> IO ()
56modifyMVar_ (StrictMVar v) f = MVar.modifyMVar_ v (f >=> evaluate)
58modifyMVar :: StrictMVar a -> (a -> IO (a, b)) -> IO b
59modifyMVar (StrictMVar v) f = MVar.modifyMVar v (f >=> evaluateFst)
61 evaluateFst :: (a, b) -> IO (a, b)
62 evaluateFst (x, y) = evaluate x >> return (x, y)
64mkWeakMVar :: StrictMVar a -> IO () -> IO (Weak (StrictMVar a))
65mkWeakMVar m@(StrictMVar (MVar m#)) f = IO $ \s ->
66 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