Skip to content
Snippets Groups Projects
Commit 6900306e authored by Ben Gamari's avatar Ben Gamari
Browse files

base: Move PrimMVar to GHC.Internal.MVar

parent 3d6aae7c
No related branches found
No related tags found
No related merge requests found
......@@ -125,12 +125,9 @@ import GHC.Internal.MVar
import GHC.Internal.Ptr
import GHC.Internal.Real ( fromIntegral )
import GHC.Internal.Show ( Show(..), showParen, showString )
import GHC.Internal.Stable ( StablePtr(..) )
import GHC.Internal.Weak
import GHC.Internal.Word
import GHC.Internal.Unsafe.Coerce ( unsafeCoerce# )
infixr 0 `par`, `pseq`
-----------------------------------------------------------------------------
......@@ -671,20 +668,6 @@ mkWeakThreadId t@(ThreadId t#) = IO $ \s ->
(# s1, w #) -> (# s1, Weak w #)
data PrimMVar
-- | Make a 'StablePtr' that can be passed to the C function
-- @hs_try_putmvar()@. The RTS wants a 'StablePtr' to the
-- underlying 'MVar#', but a 'StablePtr#' can only refer to
-- lifted types, so we have to cheat by coercing.
newStablePtrPrimMVar :: MVar a -> IO (StablePtr PrimMVar)
newStablePtrPrimMVar (MVar m) = IO $ \s0 ->
case makeStablePtr# (unsafeCoerce# m :: PrimMVar) s0 of
-- Coerce unlifted m :: MVar# RealWorld a
-- to lifted PrimMVar
-- apparently because mkStablePtr is not representation-polymorphic
(# s1, sp #) -> (# s1, StablePtr sp #)
-----------------------------------------------------------------------------
-- Transactional heap operations
-----------------------------------------------------------------------------
......
......@@ -30,9 +30,15 @@ module GHC.Internal.MVar (
, tryReadMVar
, isEmptyMVar
, addMVarFinalizer
-- * PrimMVar
, PrimMVar
, newStablePtrPrimMVar
) where
import GHC.Internal.Base
import GHC.Internal.Stable ( StablePtr(..) )
import GHC.Internal.Unsafe.Coerce ( unsafeCoerce# )
data MVar a = MVar (MVar# RealWorld a)
{- ^
......@@ -183,3 +189,17 @@ addMVarFinalizer :: MVar a -> IO () -> IO ()
addMVarFinalizer (MVar m) (IO finalizer) =
IO $ \s -> case mkWeak# m () finalizer s of { (# s1, _ #) -> (# s1, () #) }
data PrimMVar
-- | Make a 'StablePtr' that can be passed to the C function
-- @hs_try_putmvar()@. The RTS wants a 'StablePtr' to the
-- underlying 'MVar#', but a 'StablePtr#' can only refer to
-- lifted types, so we have to cheat by coercing.
newStablePtrPrimMVar :: MVar a -> IO (StablePtr PrimMVar)
newStablePtrPrimMVar (MVar m) = IO $ \s0 ->
case makeStablePtr# (unsafeCoerce# m :: PrimMVar) s0 of
-- Coerce unlifted m :: MVar# RealWorld a
-- to lifted PrimMVar
-- apparently because mkStablePtr is not representation-polymorphic
(# s1, sp #) -> (# s1, StablePtr sp #)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment