Created
August 24, 2015 22:55
-
-
Save rrnewton/a31426da929e86b9fc33 to your computer and use it in GitHub Desktop.
For Omer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE MagicHash #-} | |
-- | | |
module Data.LVar.Future where | |
import Control.DeepSeq | |
import Control.Exception (throw) | |
import qualified Control.LVish.Basics as LV | |
import Control.LVish.DeepFrz.Internal | |
import Control.LVish.Internal (LVar (WrapLVar), | |
Par (WrapPar)) | |
import qualified Control.LVish.Internal as I | |
import qualified Control.LVish.Types as LV | |
import Control.Par.EffectSigs | |
import qualified Data.Foldable as F | |
import Data.IORef | |
import Data.LVar.Generic | |
import Data.LVar.Generic.Internal (unsafeCoerceLVar) | |
import GHC.Prim (unsafeCoerce#) | |
import Internal.Control.LVish.SchedIdempotent (freezeLV, getLV, newLV, | |
putLV) | |
import qualified Internal.Control.LVish.SchedIdempotent as LI | |
import System.IO.Unsafe (unsafeDupablePerformIO, | |
unsafePerformIO) | |
import System.Mem.StableName (hashStableName, | |
makeStableName) | |
import qualified Control.Par.Class as PC | |
import qualified Control.Par.Class.Unsafe as PU | |
-------------------------------------------------------------------------------- | |
data FutStatus a = Empty | |
| Started | |
| Finished a | |
newtype Future s a = Future (LVar s (IORef (FutStatus a)) a) | |
-- instance (IdempotentParMonad (p e)) => ParFuture Par where | |
get :: Future s a -> Par e s a | |
get (IVar (WrapLVar iv)) = WrapPar$ getLV iv globalThresh deltaThresh | |
where globalThresh ref _ = readIORef ref -- past threshold iff Just _ | |
deltaThresh x = return $ Just x -- always past threshold | |
instance PC.ParFuture Par where | |
type Future Par = Future | |
spawn_ m = do ref <- PU.internalLiftIO $ newIORef $ error "Data.LVar.Future - internal error" | |
fork (do res <- m | |
PU.internalLiftIO $ do writeIORef ref | |
-- Mem barrier here | |
) | |
undefined | |
read = undefined |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment