{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeFamilies #-}
module Control.Monad.Conc.Class
( MonadConc(..)
, fork
, forkOn
, forkOS
, forkFinally
, spawn
, killThread
, rtsSupportsBoundThreads
, runInBoundThread
, runInUnboundThread
, forkN
, forkOnN
, forkOSN
, throw
, catch
, mask
, Ca.mask_
, uninterruptibleMask
, Ca.uninterruptibleMask_
, interruptible
, newMVar
, newMVarN
, cas
, peekTicket
, IsConc
, toIsConc
, fromIsConc
, liftedF
, liftedFork
) where
import Control.Exception (AsyncException(ThreadKilled),
Exception, MaskingState(..),
SomeException)
import Control.Monad.Catch (MonadCatch, MonadMask,
MonadThrow)
import qualified Control.Monad.Catch as Ca
import Control.Monad.Fail (MonadFail(..))
import Control.Monad.STM.Class (IsSTM, MonadSTM, TVar, fromIsSTM,
newTVar, readTVar)
import Control.Monad.Trans.Control (MonadTransControl, StT, liftWith)
import Data.Kind (Type)
import Data.Proxy (Proxy(..))
import qualified Control.Concurrent as IO
import qualified Control.Concurrent.STM.TVar as IO
import qualified Control.Exception as IO
import qualified Control.Monad.STM as IO
import qualified Data.Atomics as IO
import qualified Data.IORef as IO
import qualified GHC.Conc as IO
import qualified GHC.IO as IO
import Control.Monad.Reader (ReaderT)
import qualified Control.Monad.RWS.Lazy as RL
import qualified Control.Monad.RWS.Strict as RS
import qualified Control.Monad.State.Lazy as SL
import qualified Control.Monad.State.Strict as SS
import Control.Monad.Trans (lift)
import Control.Monad.Trans.Identity (IdentityT)
import qualified Control.Monad.Writer.Lazy as WL
import qualified Control.Monad.Writer.Strict as WS
class ( Monad m
, MonadCatch m, MonadThrow m, MonadMask m
, MonadSTM (STM m)
, Ord (ThreadId m), Show (ThreadId m)) => MonadConc m where
{-# MINIMAL
(forkWithUnmask | forkWithUnmaskN)
, (forkOnWithUnmask | forkOnWithUnmaskN)
, (forkOSWithUnmask | forkOSWithUnmaskN)
, supportsBoundThreads
, isCurrentThreadBound
, getNumCapabilities
, setNumCapabilities
, myThreadId
, yield
, (newEmptyMVar | newEmptyMVarN)
, putMVar
, tryPutMVar
, readMVar
, tryReadMVar
, takeMVar
, tryTakeMVar
, (newIORef | newIORefN)
, atomicModifyIORef
, writeIORef
, readForCAS
, peekTicket'
, casIORef
, modifyIORefCAS
, atomically
, throwTo
, getMaskingState
, unsafeUnmask
#-}
type STM m :: Type -> Type
type MVar m :: Type -> Type
type IORef m :: Type -> Type
type Ticket m :: Type -> Type
type ThreadId m :: Type
forkWithUnmask :: ((forall a. m a -> m a) -> m ()) -> m (ThreadId m)
forkWithUnmask = forall (m :: * -> *).
MonadConc m =>
String -> ((forall a. m a -> m a) -> m ()) -> m (ThreadId m)
forkWithUnmaskN String
""
forkWithUnmaskN :: String -> ((forall a. m a -> m a) -> m ()) -> m (ThreadId m)
forkWithUnmaskN String
_ = forall (m :: * -> *).
MonadConc m =>
((forall a. m a -> m a) -> m ()) -> m (ThreadId m)
forkWithUnmask
forkOnWithUnmask :: Int -> ((forall a. m a -> m a) -> m ()) -> m (ThreadId m)
forkOnWithUnmask = forall (m :: * -> *).
MonadConc m =>
String -> Int -> ((forall a. m a -> m a) -> m ()) -> m (ThreadId m)
forkOnWithUnmaskN String
""
forkOnWithUnmaskN :: String -> Int -> ((forall a. m a -> m a) -> m ()) -> m (ThreadId m)
forkOnWithUnmaskN String
_ = forall (m :: * -> *).
MonadConc m =>
Int -> ((forall a. m a -> m a) -> m ()) -> m (ThreadId m)
forkOnWithUnmask
forkOSWithUnmask :: ((forall a. m a -> m a) -> m ()) -> m (ThreadId m)
forkOSWithUnmask = forall (m :: * -> *).
MonadConc m =>
String -> ((forall a. m a -> m a) -> m ()) -> m (ThreadId m)
forkOSWithUnmaskN String
""
forkOSWithUnmaskN :: String -> ((forall a. m a -> m a) -> m ()) -> m (ThreadId m)
forkOSWithUnmaskN String
_ = forall (m :: * -> *).
MonadConc m =>
((forall a. m a -> m a) -> m ()) -> m (ThreadId m)
forkOSWithUnmask
supportsBoundThreads :: m Bool
isCurrentThreadBound :: m Bool
getNumCapabilities :: m Int
setNumCapabilities :: Int -> m ()
myThreadId :: m (ThreadId m)
yield :: m ()
threadDelay :: Int -> m ()
threadDelay Int
_ = forall (m :: * -> *). MonadConc m => m ()
yield
newEmptyMVar :: m (MVar m a)
newEmptyMVar = forall (m :: * -> *) a. MonadConc m => String -> m (MVar m a)
newEmptyMVarN String
""
newEmptyMVarN :: String -> m (MVar m a)
newEmptyMVarN String
_ = forall (m :: * -> *) a. MonadConc m => m (MVar m a)
newEmptyMVar
putMVar :: MVar m a -> a -> m ()
tryPutMVar :: MVar m a -> a -> m Bool
readMVar :: MVar m a -> m a
tryReadMVar :: MVar m a -> m (Maybe a)
takeMVar :: MVar m a -> m a
tryTakeMVar :: MVar m a -> m (Maybe a)
newIORef :: a -> m (IORef m a)
newIORef = forall (m :: * -> *) a. MonadConc m => String -> a -> m (IORef m a)
newIORefN String
""
newIORefN :: String -> a -> m (IORef m a)
newIORefN String
_ = forall (m :: * -> *) a. MonadConc m => a -> m (IORef m a)
newIORef
readIORef :: IORef m a -> m a
readIORef IORef m a
ioref = forall (m :: * -> *) a. MonadConc m => IORef m a -> m (Ticket m a)
readForCAS IORef m a
ioref forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a. MonadConc m => Ticket m a -> m a
peekTicket
atomicModifyIORef :: IORef m a -> (a -> (a, b)) -> m b
writeIORef :: IORef m a -> a -> m ()
atomicWriteIORef :: IORef m a -> a -> m ()
atomicWriteIORef IORef m a
r a
a = forall (m :: * -> *) a b.
MonadConc m =>
IORef m a -> (a -> (a, b)) -> m b
atomicModifyIORef IORef m a
r forall a b. (a -> b) -> a -> b
$ forall a b. a -> b -> a
const (a
a, ())
readForCAS :: IORef m a -> m (Ticket m a)
peekTicket' :: Proxy m -> Ticket m a -> a
casIORef :: IORef m a -> Ticket m a -> a -> m (Bool, Ticket m a)
modifyIORefCAS :: IORef m a -> (a -> (a, b)) -> m b
modifyIORefCAS_ :: IORef m a -> (a -> a) -> m ()
modifyIORefCAS_ IORef m a
ioref a -> a
f = forall (m :: * -> *) a b.
MonadConc m =>
IORef m a -> (a -> (a, b)) -> m b
modifyIORefCAS IORef m a
ioref (\a
a -> (a -> a
f a
a, ()))
atomically :: STM m a -> m a
newTVarConc :: a -> m (TVar (STM m) a)
newTVarConc = forall (m :: * -> *) a. MonadConc m => STM m a -> m a
atomically forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (stm :: * -> *) a. MonadSTM stm => a -> stm (TVar stm a)
newTVar
readTVarConc :: TVar (STM m) a -> m a
readTVarConc = forall (m :: * -> *) a. MonadConc m => STM m a -> m a
atomically forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (stm :: * -> *) a. MonadSTM stm => TVar stm a -> stm a
readTVar
throwTo :: Exception e => ThreadId m -> e -> m ()
getMaskingState :: m MaskingState
unsafeUnmask :: m a -> m a
fork :: MonadConc m => m () -> m (ThreadId m)
fork :: forall (m :: * -> *). MonadConc m => m () -> m (ThreadId m)
fork m ()
ma = forall (m :: * -> *).
MonadConc m =>
((forall a. m a -> m a) -> m ()) -> m (ThreadId m)
forkWithUnmask (\forall a. m a -> m a
_ -> m ()
ma)
forkOn :: MonadConc m => Int -> m () -> m (ThreadId m)
forkOn :: forall (m :: * -> *). MonadConc m => Int -> m () -> m (ThreadId m)
forkOn Int
c m ()
ma = forall (m :: * -> *).
MonadConc m =>
Int -> ((forall a. m a -> m a) -> m ()) -> m (ThreadId m)
forkOnWithUnmask Int
c (\forall a. m a -> m a
_ -> m ()
ma)
forkOS :: MonadConc m => m () -> m (ThreadId m)
forkOS :: forall (m :: * -> *). MonadConc m => m () -> m (ThreadId m)
forkOS m ()
ma = forall (m :: * -> *).
MonadConc m =>
((forall a. m a -> m a) -> m ()) -> m (ThreadId m)
forkOSWithUnmask (\forall a. m a -> m a
_ -> m ()
ma)
forkFinally :: MonadConc m => m a -> (Either SomeException a -> m ()) -> m (ThreadId m)
forkFinally :: forall (m :: * -> *) a.
MonadConc m =>
m a -> (Either SomeException a -> m ()) -> m (ThreadId m)
forkFinally m a
action Either SomeException a -> m ()
and_then =
forall (m :: * -> *) b.
MonadConc m =>
((forall a. m a -> m a) -> m b) -> m b
mask forall a b. (a -> b) -> a -> b
$ \forall a. m a -> m a
restore ->
forall (m :: * -> *). MonadConc m => m () -> m (ThreadId m)
fork forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) e a.
(MonadCatch m, Exception e) =>
m a -> m (Either e a)
Ca.try (forall a. m a -> m a
restore m a
action) forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Either SomeException a -> m ()
and_then
spawn :: MonadConc m => m a -> m (MVar m a)
spawn :: forall (m :: * -> *) a. MonadConc m => m a -> m (MVar m a)
spawn m a
ma = do
MVar m a
cvar <- forall (m :: * -> *) a. MonadConc m => m (MVar m a)
newEmptyMVar
ThreadId m
_ <- forall (m :: * -> *). MonadConc m => m () -> m (ThreadId m)
fork forall a b. (a -> b) -> a -> b
$ m a
ma forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a. MonadConc m => MVar m a -> a -> m ()
putMVar MVar m a
cvar
forall (f :: * -> *) a. Applicative f => a -> f a
pure MVar m a
cvar
killThread :: MonadConc m => ThreadId m -> m ()
killThread :: forall (m :: * -> *). MonadConc m => ThreadId m -> m ()
killThread ThreadId m
tid = forall (m :: * -> *) e.
(MonadConc m, Exception e) =>
ThreadId m -> e -> m ()
throwTo ThreadId m
tid AsyncException
ThreadKilled
forkN :: MonadConc m => String -> m () -> m (ThreadId m)
forkN :: forall (m :: * -> *).
MonadConc m =>
String -> m () -> m (ThreadId m)
forkN String
name m ()
ma = forall (m :: * -> *).
MonadConc m =>
String -> ((forall a. m a -> m a) -> m ()) -> m (ThreadId m)
forkWithUnmaskN String
name (\forall a. m a -> m a
_ -> m ()
ma)
forkOnN :: MonadConc m => String -> Int -> m () -> m (ThreadId m)
forkOnN :: forall (m :: * -> *).
MonadConc m =>
String -> Int -> m () -> m (ThreadId m)
forkOnN String
name Int
i m ()
ma = forall (m :: * -> *).
MonadConc m =>
String -> Int -> ((forall a. m a -> m a) -> m ()) -> m (ThreadId m)
forkOnWithUnmaskN String
name Int
i (\forall a. m a -> m a
_ -> m ()
ma)
forkOSN :: MonadConc m => String -> m () -> m (ThreadId m)
forkOSN :: forall (m :: * -> *).
MonadConc m =>
String -> m () -> m (ThreadId m)
forkOSN String
name m ()
ma = forall (m :: * -> *).
MonadConc m =>
String -> ((forall a. m a -> m a) -> m ()) -> m (ThreadId m)
forkOSWithUnmaskN String
name (\forall a. m a -> m a
_ -> m ()
ma)
{-# DEPRECATED rtsSupportsBoundThreads "Use 'supportsBoundThreads' instead" #-}
rtsSupportsBoundThreads :: Bool
rtsSupportsBoundThreads :: Bool
rtsSupportsBoundThreads = Bool
IO.rtsSupportsBoundThreads
runInBoundThread :: MonadConc m => m a -> m a
runInBoundThread :: forall (m :: * -> *) a. MonadConc m => m a -> m a
runInBoundThread =
forall (m :: * -> *) a.
MonadConc m =>
m Bool -> (m () -> m (ThreadId m)) -> m a -> m a
runInThread (Bool -> Bool
not forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). MonadConc m => m Bool
isCurrentThreadBound) (forall (m :: * -> *).
MonadConc m =>
String -> m () -> m (ThreadId m)
forkOSN String
"runInBoundThread")
runInUnboundThread :: MonadConc m => m a -> m a
runInUnboundThread :: forall (m :: * -> *) a. MonadConc m => m a -> m a
runInUnboundThread =
forall (m :: * -> *) a.
MonadConc m =>
m Bool -> (m () -> m (ThreadId m)) -> m a -> m a
runInThread forall (m :: * -> *). MonadConc m => m Bool
isCurrentThreadBound (forall (m :: * -> *).
MonadConc m =>
String -> m () -> m (ThreadId m)
forkN String
"runInUnboundThread")
runInThread :: MonadConc m => m Bool -> (m () -> m (ThreadId m)) -> m a -> m a
runInThread :: forall (m :: * -> *) a.
MonadConc m =>
m Bool -> (m () -> m (ThreadId m)) -> m a -> m a
runInThread m Bool
check m () -> m (ThreadId m)
dofork m a
action = do
Bool
flag <- m Bool
check
if Bool
flag
then do
MVar m (Either SomeException a)
mv <- forall (m :: * -> *) a. MonadConc m => m (MVar m a)
newEmptyMVar
forall (m :: * -> *) b.
MonadConc m =>
((forall a. m a -> m a) -> m b) -> m b
mask forall a b. (a -> b) -> a -> b
$ \forall a. m a -> m a
restore -> do
ThreadId m
tid <- m () -> m (ThreadId m)
dofork forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) e a.
(MonadCatch m, Exception e) =>
m a -> m (Either e a)
Ca.try (forall a. m a -> m a
restore m a
action) forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a. MonadConc m => MVar m a -> a -> m ()
putMVar MVar m (Either SomeException a)
mv
let wait :: m (Either SomeException a)
wait = forall (m :: * -> *) a. MonadConc m => MVar m a -> m a
takeMVar MVar m (Either SomeException a)
mv forall (m :: * -> *) e a.
(MonadConc m, Exception e) =>
m a -> (e -> m a) -> m a
`catch` \(SomeException
e :: SomeException) -> forall (m :: * -> *) e.
(MonadConc m, Exception e) =>
ThreadId m -> e -> m ()
throwTo ThreadId m
tid SomeException
e forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> m (Either SomeException a)
wait
m (Either SomeException a)
wait forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (\(SomeException
e :: SomeException) -> forall (m :: * -> *) e a. (MonadConc m, Exception e) => e -> m a
throw SomeException
e) forall (f :: * -> *) a. Applicative f => a -> f a
pure
else m a
action
throw :: (MonadConc m, Exception e) => e -> m a
throw :: forall (m :: * -> *) e a. (MonadConc m, Exception e) => e -> m a
throw = forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
Ca.throwM
catch :: (MonadConc m, Exception e) => m a -> (e -> m a) -> m a
catch :: forall (m :: * -> *) e a.
(MonadConc m, Exception e) =>
m a -> (e -> m a) -> m a
catch = forall (m :: * -> *) e a.
(MonadCatch m, Exception e) =>
m a -> (e -> m a) -> m a
Ca.catch
mask :: MonadConc m => ((forall a. m a -> m a) -> m b) -> m b
mask :: forall (m :: * -> *) b.
MonadConc m =>
((forall a. m a -> m a) -> m b) -> m b
mask = forall (m :: * -> *) b.
MonadMask m =>
((forall a. m a -> m a) -> m b) -> m b
Ca.mask
uninterruptibleMask :: MonadConc m => ((forall a. m a -> m a) -> m b) -> m b
uninterruptibleMask :: forall (m :: * -> *) b.
MonadConc m =>
((forall a. m a -> m a) -> m b) -> m b
uninterruptibleMask = forall (m :: * -> *) b.
MonadMask m =>
((forall a. m a -> m a) -> m b) -> m b
Ca.uninterruptibleMask
interruptible :: MonadConc m => m a -> m a
interruptible :: forall (m :: * -> *) a. MonadConc m => m a -> m a
interruptible m a
act = do
MaskingState
st <- forall (m :: * -> *). MonadConc m => m MaskingState
getMaskingState
case MaskingState
st of
MaskingState
Unmasked -> m a
act
MaskingState
MaskedInterruptible -> forall (m :: * -> *) a. MonadConc m => m a -> m a
unsafeUnmask m a
act
MaskingState
MaskedUninterruptible -> m a
act
newMVar :: MonadConc m => a -> m (MVar m a)
newMVar :: forall (m :: * -> *) a. MonadConc m => a -> m (MVar m a)
newMVar a
a = do
MVar m a
cvar <- forall (m :: * -> *) a. MonadConc m => m (MVar m a)
newEmptyMVar
forall (m :: * -> *) a. MonadConc m => MVar m a -> a -> m ()
putMVar MVar m a
cvar a
a
forall (f :: * -> *) a. Applicative f => a -> f a
pure MVar m a
cvar
newMVarN :: MonadConc m => String -> a -> m (MVar m a)
newMVarN :: forall (m :: * -> *) a. MonadConc m => String -> a -> m (MVar m a)
newMVarN String
n a
a = do
MVar m a
cvar <- forall (m :: * -> *) a. MonadConc m => String -> m (MVar m a)
newEmptyMVarN String
n
forall (m :: * -> *) a. MonadConc m => MVar m a -> a -> m ()
putMVar MVar m a
cvar a
a
forall (f :: * -> *) a. Applicative f => a -> f a
pure MVar m a
cvar
peekTicket :: forall m a. MonadConc m => Ticket m a -> m a
peekTicket :: forall (m :: * -> *) a. MonadConc m => Ticket m a -> m a
peekTicket Ticket m a
t = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadConc m => Proxy m -> Ticket m a -> a
peekTicket' (forall {k} (t :: k). Proxy t
Proxy :: Proxy m) (Ticket m a
t :: Ticket m a)
cas :: MonadConc m => IORef m a -> a -> m (Bool, a)
cas :: forall (m :: * -> *) a.
MonadConc m =>
IORef m a -> a -> m (Bool, a)
cas IORef m a
ioref a
a = do
Ticket m a
tick <- forall (m :: * -> *) a. MonadConc m => IORef m a -> m (Ticket m a)
readForCAS IORef m a
ioref
(Bool
suc, Ticket m a
tick') <- forall (m :: * -> *) a.
MonadConc m =>
IORef m a -> Ticket m a -> a -> m (Bool, Ticket m a)
casIORef IORef m a
ioref Ticket m a
tick a
a
a
a' <- forall (m :: * -> *) a. MonadConc m => Ticket m a -> m a
peekTicket Ticket m a
tick'
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Bool
suc, a
a')
instance MonadConc IO where
type STM IO = IO.STM
type MVar IO = IO.MVar
type IORef IO = IO.IORef
type Ticket IO = IO.Ticket
type ThreadId IO = IO.ThreadId
forkWithUnmask :: ((forall a. IO a -> IO a) -> IO ()) -> IO (ThreadId IO)
forkWithUnmask = ((forall a. IO a -> IO a) -> IO ()) -> IO ThreadId
IO.forkIOWithUnmask
forkOnWithUnmask :: Int -> ((forall a. IO a -> IO a) -> IO ()) -> IO (ThreadId IO)
forkOnWithUnmask = Int -> ((forall a. IO a -> IO a) -> IO ()) -> IO ThreadId
IO.forkOnWithUnmask
forkOSWithUnmask :: ((forall a. IO a -> IO a) -> IO ()) -> IO (ThreadId IO)
forkOSWithUnmask = ((forall a. IO a -> IO a) -> IO ()) -> IO ThreadId
IO.forkOSWithUnmask
forkWithUnmaskN :: String -> ((forall a. IO a -> IO a) -> IO ()) -> IO (ThreadId IO)
forkWithUnmaskN String
n (forall a. IO a -> IO a) -> IO ()
ma = forall (m :: * -> *).
MonadConc m =>
((forall a. m a -> m a) -> m ()) -> m (ThreadId m)
forkWithUnmask forall a b. (a -> b) -> a -> b
$ \forall a. IO a -> IO a
umask -> do
String -> IO ()
labelMe String
n
(forall a. IO a -> IO a) -> IO ()
ma forall a. IO a -> IO a
umask
forkOnWithUnmaskN :: String
-> Int -> ((forall a. IO a -> IO a) -> IO ()) -> IO (ThreadId IO)
forkOnWithUnmaskN String
n Int
i (forall a. IO a -> IO a) -> IO ()
ma = forall (m :: * -> *).
MonadConc m =>
Int -> ((forall a. m a -> m a) -> m ()) -> m (ThreadId m)
forkOnWithUnmask Int
i forall a b. (a -> b) -> a -> b
$ \forall a. IO a -> IO a
umask -> do
String -> IO ()
labelMe String
n
(forall a. IO a -> IO a) -> IO ()
ma forall a. IO a -> IO a
umask
forkOSWithUnmaskN :: String -> ((forall a. IO a -> IO a) -> IO ()) -> IO (ThreadId IO)
forkOSWithUnmaskN String
n (forall a. IO a -> IO a) -> IO ()
ma = forall (m :: * -> *).
MonadConc m =>
((forall a. m a -> m a) -> m ()) -> m (ThreadId m)
forkOSWithUnmask forall a b. (a -> b) -> a -> b
$ \forall a. IO a -> IO a
umask -> do
String -> IO ()
labelMe String
n
(forall a. IO a -> IO a) -> IO ()
ma forall a. IO a -> IO a
umask
supportsBoundThreads :: IO Bool
supportsBoundThreads = forall (f :: * -> *) a. Applicative f => a -> f a
pure Bool
IO.rtsSupportsBoundThreads
isCurrentThreadBound :: IO Bool
isCurrentThreadBound = IO Bool
IO.isCurrentThreadBound
getNumCapabilities :: IO Int
getNumCapabilities = IO Int
IO.getNumCapabilities
setNumCapabilities :: Int -> IO ()
setNumCapabilities = Int -> IO ()
IO.setNumCapabilities
readMVar :: forall a. MVar IO a -> IO a
readMVar = forall a. MVar a -> IO a
IO.readMVar
tryReadMVar :: forall a. MVar IO a -> IO (Maybe a)
tryReadMVar = forall a. MVar a -> IO (Maybe a)
IO.tryReadMVar
myThreadId :: IO (ThreadId IO)
myThreadId = IO ThreadId
IO.myThreadId
yield :: IO ()
yield = IO ()
IO.yield
threadDelay :: Int -> IO ()
threadDelay = Int -> IO ()
IO.threadDelay
throwTo :: forall e. Exception e => ThreadId IO -> e -> IO ()
throwTo = forall e. Exception e => ThreadId -> e -> IO ()
IO.throwTo
newEmptyMVar :: forall a. IO (MVar IO a)
newEmptyMVar = forall a. IO (MVar a)
IO.newEmptyMVar
putMVar :: forall a. MVar IO a -> a -> IO ()
putMVar = forall a. MVar a -> a -> IO ()
IO.putMVar
tryPutMVar :: forall a. MVar IO a -> a -> IO Bool
tryPutMVar = forall a. MVar a -> a -> IO Bool
IO.tryPutMVar
takeMVar :: forall a. MVar IO a -> IO a
takeMVar = forall a. MVar a -> IO a
IO.takeMVar
tryTakeMVar :: forall a. MVar IO a -> IO (Maybe a)
tryTakeMVar = forall a. MVar a -> IO (Maybe a)
IO.tryTakeMVar
newIORef :: forall a. a -> IO (IORef IO a)
newIORef = forall a. a -> IO (IORef a)
IO.newIORef
readIORef :: forall a. IORef IO a -> IO a
readIORef = forall a. IORef a -> IO a
IO.readIORef
atomicModifyIORef :: forall a b. IORef IO a -> (a -> (a, b)) -> IO b
atomicModifyIORef = forall a b. IORef a -> (a -> (a, b)) -> IO b
IO.atomicModifyIORef
writeIORef :: forall a. IORef IO a -> a -> IO ()
writeIORef = forall a. IORef a -> a -> IO ()
IO.writeIORef
atomicWriteIORef :: forall a. IORef IO a -> a -> IO ()
atomicWriteIORef = forall a. IORef a -> a -> IO ()
IO.atomicWriteIORef
readForCAS :: forall a. IORef IO a -> IO (Ticket IO a)
readForCAS = forall a. IORef a -> IO (Ticket a)
IO.readForCAS
peekTicket' :: forall a. Proxy IO -> Ticket IO a -> a
peekTicket' Proxy IO
_ = forall a. Ticket a -> a
IO.peekTicket
casIORef :: forall a. IORef IO a -> Ticket IO a -> a -> IO (Bool, Ticket IO a)
casIORef = forall a. IORef a -> Ticket a -> a -> IO (Bool, Ticket a)
IO.casIORef
modifyIORefCAS :: forall a b. IORef IO a -> (a -> (a, b)) -> IO b
modifyIORefCAS = forall a b. IORef a -> (a -> (a, b)) -> IO b
IO.atomicModifyIORefCAS
atomically :: forall a. STM IO a -> IO a
atomically = forall a. STM a -> IO a
IO.atomically
newTVarConc :: forall a. a -> IO (TVar (STM IO) a)
newTVarConc = forall a. a -> IO (TVar a)
IO.newTVarIO
readTVarConc :: forall a. TVar (STM IO) a -> IO a
readTVarConc = forall a. TVar a -> IO a
IO.readTVarIO
getMaskingState :: IO MaskingState
getMaskingState = IO MaskingState
IO.getMaskingState
unsafeUnmask :: forall a. IO a -> IO a
unsafeUnmask = forall a. IO a -> IO a
IO.unsafeUnmask
labelMe :: String -> IO ()
labelMe :: String -> IO ()
labelMe String
"" = forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
labelMe String
n = do
ThreadId
tid <- forall (m :: * -> *). MonadConc m => m (ThreadId m)
myThreadId
ThreadId -> String -> IO ()
IO.labelThread ThreadId
tid String
n
newtype IsConc m a = IsConc { forall {k} (m :: k -> *) (a :: k). IsConc m a -> m a
unIsConc :: m a }
deriving (forall a b. a -> IsConc m b -> IsConc m a
forall a b. (a -> b) -> IsConc m a -> IsConc m b
forall (m :: * -> *) a b.
Functor m =>
a -> IsConc m b -> IsConc m a
forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> IsConc m a -> IsConc m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> IsConc m b -> IsConc m a
$c<$ :: forall (m :: * -> *) a b.
Functor m =>
a -> IsConc m b -> IsConc m a
fmap :: forall a b. (a -> b) -> IsConc m a -> IsConc m b
$cfmap :: forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> IsConc m a -> IsConc m b
Functor, forall a. a -> IsConc m a
forall a b. IsConc m a -> IsConc m b -> IsConc m a
forall a b. IsConc m a -> IsConc m b -> IsConc m b
forall a b. IsConc m (a -> b) -> IsConc m a -> IsConc m b
forall a b c.
(a -> b -> c) -> IsConc m a -> IsConc m b -> IsConc m c
forall (f :: * -> *).
Functor f
-> (forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
forall {m :: * -> *}. Applicative m => Functor (IsConc m)
forall (m :: * -> *) a. Applicative m => a -> IsConc m a
forall (m :: * -> *) a b.
Applicative m =>
IsConc m a -> IsConc m b -> IsConc m a
forall (m :: * -> *) a b.
Applicative m =>
IsConc m a -> IsConc m b -> IsConc m b
forall (m :: * -> *) a b.
Applicative m =>
IsConc m (a -> b) -> IsConc m a -> IsConc m b
forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c) -> IsConc m a -> IsConc m b -> IsConc m c
<* :: forall a b. IsConc m a -> IsConc m b -> IsConc m a
$c<* :: forall (m :: * -> *) a b.
Applicative m =>
IsConc m a -> IsConc m b -> IsConc m a
*> :: forall a b. IsConc m a -> IsConc m b -> IsConc m b
$c*> :: forall (m :: * -> *) a b.
Applicative m =>
IsConc m a -> IsConc m b -> IsConc m b
liftA2 :: forall a b c.
(a -> b -> c) -> IsConc m a -> IsConc m b -> IsConc m c
$cliftA2 :: forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c) -> IsConc m a -> IsConc m b -> IsConc m c
<*> :: forall a b. IsConc m (a -> b) -> IsConc m a -> IsConc m b
$c<*> :: forall (m :: * -> *) a b.
Applicative m =>
IsConc m (a -> b) -> IsConc m a -> IsConc m b
pure :: forall a. a -> IsConc m a
$cpure :: forall (m :: * -> *) a. Applicative m => a -> IsConc m a
Applicative, forall a. a -> IsConc m a
forall a b. IsConc m a -> IsConc m b -> IsConc m b
forall a b. IsConc m a -> (a -> IsConc m b) -> IsConc m b
forall {m :: * -> *}. Monad m => Applicative (IsConc m)
forall (m :: * -> *) a. Monad m => a -> IsConc m a
forall (m :: * -> *) a b.
Monad m =>
IsConc m a -> IsConc m b -> IsConc m b
forall (m :: * -> *) a b.
Monad m =>
IsConc m a -> (a -> IsConc m b) -> IsConc m b
forall (m :: * -> *).
Applicative m
-> (forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
return :: forall a. a -> IsConc m a
$creturn :: forall (m :: * -> *) a. Monad m => a -> IsConc m a
>> :: forall a b. IsConc m a -> IsConc m b -> IsConc m b
$c>> :: forall (m :: * -> *) a b.
Monad m =>
IsConc m a -> IsConc m b -> IsConc m b
>>= :: forall a b. IsConc m a -> (a -> IsConc m b) -> IsConc m b
$c>>= :: forall (m :: * -> *) a b.
Monad m =>
IsConc m a -> (a -> IsConc m b) -> IsConc m b
Monad, forall e a. Exception e => e -> IsConc m a
forall (m :: * -> *).
Monad m -> (forall e a. Exception e => e -> m a) -> MonadThrow m
forall {m :: * -> *}. MonadThrow m => Monad (IsConc m)
forall (m :: * -> *) e a.
(MonadThrow m, Exception e) =>
e -> IsConc m a
throwM :: forall e a. Exception e => e -> IsConc m a
$cthrowM :: forall (m :: * -> *) e a.
(MonadThrow m, Exception e) =>
e -> IsConc m a
MonadThrow, forall e a.
Exception e =>
IsConc m a -> (e -> IsConc m a) -> IsConc m a
forall (m :: * -> *).
MonadThrow m
-> (forall e a. Exception e => m a -> (e -> m a) -> m a)
-> MonadCatch m
forall {m :: * -> *}. MonadCatch m => MonadThrow (IsConc m)
forall (m :: * -> *) e a.
(MonadCatch m, Exception e) =>
IsConc m a -> (e -> IsConc m a) -> IsConc m a
catch :: forall e a.
Exception e =>
IsConc m a -> (e -> IsConc m a) -> IsConc m a
$ccatch :: forall (m :: * -> *) e a.
(MonadCatch m, Exception e) =>
IsConc m a -> (e -> IsConc m a) -> IsConc m a
MonadCatch, forall b.
((forall a. IsConc m a -> IsConc m a) -> IsConc m b) -> IsConc m b
forall a b c.
IsConc m a
-> (a -> ExitCase b -> IsConc m c)
-> (a -> IsConc m b)
-> IsConc m (b, c)
forall {m :: * -> *}. MonadMask m => MonadCatch (IsConc m)
forall (m :: * -> *) b.
MonadMask m =>
((forall a. IsConc m a -> IsConc m a) -> IsConc m b) -> IsConc m b
forall (m :: * -> *) a b c.
MonadMask m =>
IsConc m a
-> (a -> ExitCase b -> IsConc m c)
-> (a -> IsConc m b)
-> IsConc m (b, c)
forall (m :: * -> *).
MonadCatch m
-> (forall b. ((forall a. m a -> m a) -> m b) -> m b)
-> (forall b. ((forall a. m a -> m a) -> m b) -> m b)
-> (forall a b c.
m a -> (a -> ExitCase b -> m c) -> (a -> m b) -> m (b, c))
-> MonadMask m
generalBracket :: forall a b c.
IsConc m a
-> (a -> ExitCase b -> IsConc m c)
-> (a -> IsConc m b)
-> IsConc m (b, c)
$cgeneralBracket :: forall (m :: * -> *) a b c.
MonadMask m =>
IsConc m a
-> (a -> ExitCase b -> IsConc m c)
-> (a -> IsConc m b)
-> IsConc m (b, c)
uninterruptibleMask :: forall b.
((forall a. IsConc m a -> IsConc m a) -> IsConc m b) -> IsConc m b
$cuninterruptibleMask :: forall (m :: * -> *) b.
MonadMask m =>
((forall a. IsConc m a -> IsConc m a) -> IsConc m b) -> IsConc m b
mask :: forall b.
((forall a. IsConc m a -> IsConc m a) -> IsConc m b) -> IsConc m b
$cmask :: forall (m :: * -> *) b.
MonadMask m =>
((forall a. IsConc m a -> IsConc m a) -> IsConc m b) -> IsConc m b
MonadMask)
deriving instance MonadFail m => MonadFail (IsConc m)
toIsConc :: MonadConc m => m a -> IsConc m a
toIsConc :: forall (m :: * -> *) a. MonadConc m => m a -> IsConc m a
toIsConc = forall {k} (m :: k -> *) (a :: k). m a -> IsConc m a
IsConc
fromIsConc :: MonadConc m => IsConc m a -> m a
fromIsConc :: forall (m :: * -> *) a. MonadConc m => IsConc m a -> m a
fromIsConc = forall {k} (m :: k -> *) (a :: k). IsConc m a -> m a
unIsConc
instance MonadConc m => MonadConc (IsConc m) where
type STM (IsConc m) = IsSTM (STM m)
type MVar (IsConc m) = MVar m
type IORef (IsConc m) = IORef m
type Ticket (IsConc m) = Ticket m
type ThreadId (IsConc m) = ThreadId m
forkWithUnmask :: ((forall a. IsConc m a -> IsConc m a) -> IsConc m ())
-> IsConc m (ThreadId (IsConc m))
forkWithUnmask (forall a. IsConc m a -> IsConc m a) -> IsConc m ()
ma = forall (m :: * -> *) a. MonadConc m => m a -> IsConc m a
toIsConc (forall (m :: * -> *).
MonadConc m =>
((forall a. m a -> m a) -> m ()) -> m (ThreadId m)
forkWithUnmask (\forall a. m a -> m a
umask -> forall {k} (m :: k -> *) (a :: k). IsConc m a -> m a
unIsConc forall a b. (a -> b) -> a -> b
$ (forall a. IsConc m a -> IsConc m a) -> IsConc m ()
ma (\IsConc m a
mx -> forall (m :: * -> *) a. MonadConc m => m a -> IsConc m a
toIsConc (forall a. m a -> m a
umask forall a b. (a -> b) -> a -> b
$ forall {k} (m :: k -> *) (a :: k). IsConc m a -> m a
unIsConc IsConc m a
mx))))
forkWithUnmaskN :: String
-> ((forall a. IsConc m a -> IsConc m a) -> IsConc m ())
-> IsConc m (ThreadId (IsConc m))
forkWithUnmaskN String
n (forall a. IsConc m a -> IsConc m a) -> IsConc m ()
ma = forall (m :: * -> *) a. MonadConc m => m a -> IsConc m a
toIsConc (forall (m :: * -> *).
MonadConc m =>
String -> ((forall a. m a -> m a) -> m ()) -> m (ThreadId m)
forkWithUnmaskN String
n (\forall a. m a -> m a
umask -> forall {k} (m :: k -> *) (a :: k). IsConc m a -> m a
unIsConc forall a b. (a -> b) -> a -> b
$ (forall a. IsConc m a -> IsConc m a) -> IsConc m ()
ma (\IsConc m a
mx -> forall (m :: * -> *) a. MonadConc m => m a -> IsConc m a
toIsConc (forall a. m a -> m a
umask forall a b. (a -> b) -> a -> b
$ forall {k} (m :: k -> *) (a :: k). IsConc m a -> m a
unIsConc IsConc m a
mx))))
forkOnWithUnmask :: Int
-> ((forall a. IsConc m a -> IsConc m a) -> IsConc m ())
-> IsConc m (ThreadId (IsConc m))
forkOnWithUnmask Int
i (forall a. IsConc m a -> IsConc m a) -> IsConc m ()
ma = forall (m :: * -> *) a. MonadConc m => m a -> IsConc m a
toIsConc (forall (m :: * -> *).
MonadConc m =>
Int -> ((forall a. m a -> m a) -> m ()) -> m (ThreadId m)
forkOnWithUnmask Int
i (\forall a. m a -> m a
umask -> forall {k} (m :: k -> *) (a :: k). IsConc m a -> m a
unIsConc forall a b. (a -> b) -> a -> b
$ (forall a. IsConc m a -> IsConc m a) -> IsConc m ()
ma (\IsConc m a
mx -> forall (m :: * -> *) a. MonadConc m => m a -> IsConc m a
toIsConc (forall a. m a -> m a
umask forall a b. (a -> b) -> a -> b
$ forall {k} (m :: k -> *) (a :: k). IsConc m a -> m a
unIsConc IsConc m a
mx))))
forkOnWithUnmaskN :: String
-> Int
-> ((forall a. IsConc m a -> IsConc m a) -> IsConc m ())
-> IsConc m (ThreadId (IsConc m))
forkOnWithUnmaskN String
n Int
i (forall a. IsConc m a -> IsConc m a) -> IsConc m ()
ma = forall (m :: * -> *) a. MonadConc m => m a -> IsConc m a
toIsConc (forall (m :: * -> *).
MonadConc m =>
String -> Int -> ((forall a. m a -> m a) -> m ()) -> m (ThreadId m)
forkOnWithUnmaskN String
n Int
i (\forall a. m a -> m a
umask -> forall {k} (m :: k -> *) (a :: k). IsConc m a -> m a
unIsConc forall a b. (a -> b) -> a -> b
$ (forall a. IsConc m a -> IsConc m a) -> IsConc m ()
ma (\IsConc m a
mx -> forall (m :: * -> *) a. MonadConc m => m a -> IsConc m a
toIsConc (forall a. m a -> m a
umask forall a b. (a -> b) -> a -> b
$ forall {k} (m :: k -> *) (a :: k). IsConc m a -> m a
unIsConc IsConc m a
mx))))
forkOSWithUnmask :: ((forall a. IsConc m a -> IsConc m a) -> IsConc m ())
-> IsConc m (ThreadId (IsConc m))
forkOSWithUnmask (forall a. IsConc m a -> IsConc m a) -> IsConc m ()
ma = forall (m :: * -> *) a. MonadConc m => m a -> IsConc m a
toIsConc (forall (m :: * -> *).
MonadConc m =>
((forall a. m a -> m a) -> m ()) -> m (ThreadId m)
forkOSWithUnmask (\forall a. m a -> m a
umask -> forall {k} (m :: k -> *) (a :: k). IsConc m a -> m a
unIsConc forall a b. (a -> b) -> a -> b
$ (forall a. IsConc m a -> IsConc m a) -> IsConc m ()
ma (\IsConc m a
mx -> forall (m :: * -> *) a. MonadConc m => m a -> IsConc m a
toIsConc (forall a. m a -> m a
umask forall a b. (a -> b) -> a -> b
$ forall {k} (m :: k -> *) (a :: k). IsConc m a -> m a
unIsConc IsConc m a
mx))))
forkOSWithUnmaskN :: String
-> ((forall a. IsConc m a -> IsConc m a) -> IsConc m ())
-> IsConc m (ThreadId (IsConc m))
forkOSWithUnmaskN String
n (forall a. IsConc m a -> IsConc m a) -> IsConc m ()
ma = forall (m :: * -> *) a. MonadConc m => m a -> IsConc m a
toIsConc (forall (m :: * -> *).
MonadConc m =>
String -> ((forall a. m a -> m a) -> m ()) -> m (ThreadId m)
forkOSWithUnmaskN String
n (\forall a. m a -> m a
umask -> forall {k} (m :: k -> *) (a :: k). IsConc m a -> m a
unIsConc forall a b. (a -> b) -> a -> b
$ (forall a. IsConc m a -> IsConc m a) -> IsConc m ()
ma (\IsConc m a
mx -> forall (m :: * -> *) a. MonadConc m => m a -> IsConc m a
toIsConc (forall a. m a -> m a
umask forall a b. (a -> b) -> a -> b
$ forall {k} (m :: k -> *) (a :: k). IsConc m a -> m a
unIsConc IsConc m a
mx))))
unsafeUnmask :: forall a. IsConc m a -> IsConc m a
unsafeUnmask IsConc m a
ma = forall (m :: * -> *) a. MonadConc m => m a -> IsConc m a
toIsConc (forall (m :: * -> *) a. MonadConc m => m a -> m a
unsafeUnmask (forall {k} (m :: k -> *) (a :: k). IsConc m a -> m a
unIsConc IsConc m a
ma))
supportsBoundThreads :: IsConc m Bool
supportsBoundThreads = forall (m :: * -> *) a. MonadConc m => m a -> IsConc m a
toIsConc forall (m :: * -> *). MonadConc m => m Bool
supportsBoundThreads
isCurrentThreadBound :: IsConc m Bool
isCurrentThreadBound = forall (m :: * -> *) a. MonadConc m => m a -> IsConc m a
toIsConc forall (m :: * -> *). MonadConc m => m Bool
isCurrentThreadBound
getNumCapabilities :: IsConc m Int
getNumCapabilities = forall (m :: * -> *) a. MonadConc m => m a -> IsConc m a
toIsConc forall (m :: * -> *). MonadConc m => m Int
getNumCapabilities
setNumCapabilities :: Int -> IsConc m ()
setNumCapabilities = forall (m :: * -> *) a. MonadConc m => m a -> IsConc m a
toIsConc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *). MonadConc m => Int -> m ()
setNumCapabilities
myThreadId :: IsConc m (ThreadId (IsConc m))
myThreadId = forall (m :: * -> *) a. MonadConc m => m a -> IsConc m a
toIsConc forall (m :: * -> *). MonadConc m => m (ThreadId m)
myThreadId
yield :: IsConc m ()
yield = forall (m :: * -> *) a. MonadConc m => m a -> IsConc m a
toIsConc forall (m :: * -> *). MonadConc m => m ()
yield
threadDelay :: Int -> IsConc m ()
threadDelay = forall (m :: * -> *) a. MonadConc m => m a -> IsConc m a
toIsConc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *). MonadConc m => Int -> m ()
threadDelay
throwTo :: forall e. Exception e => ThreadId (IsConc m) -> e -> IsConc m ()
throwTo ThreadId (IsConc m)
t = forall (m :: * -> *) a. MonadConc m => m a -> IsConc m a
toIsConc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) e.
(MonadConc m, Exception e) =>
ThreadId m -> e -> m ()
throwTo ThreadId (IsConc m)
t
newEmptyMVar :: forall a. IsConc m (MVar (IsConc m) a)
newEmptyMVar = forall (m :: * -> *) a. MonadConc m => m a -> IsConc m a
toIsConc forall (m :: * -> *) a. MonadConc m => m (MVar m a)
newEmptyMVar
newEmptyMVarN :: forall a. String -> IsConc m (MVar (IsConc m) a)
newEmptyMVarN = forall (m :: * -> *) a. MonadConc m => m a -> IsConc m a
toIsConc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadConc m => String -> m (MVar m a)
newEmptyMVarN
readMVar :: forall a. MVar (IsConc m) a -> IsConc m a
readMVar = forall (m :: * -> *) a. MonadConc m => m a -> IsConc m a
toIsConc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadConc m => MVar m a -> m a
readMVar
tryReadMVar :: forall a. MVar (IsConc m) a -> IsConc m (Maybe a)
tryReadMVar = forall (m :: * -> *) a. MonadConc m => m a -> IsConc m a
toIsConc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadConc m => MVar m a -> m (Maybe a)
tryReadMVar
putMVar :: forall a. MVar (IsConc m) a -> a -> IsConc m ()
putMVar MVar (IsConc m) a
v = forall (m :: * -> *) a. MonadConc m => m a -> IsConc m a
toIsConc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadConc m => MVar m a -> a -> m ()
putMVar MVar (IsConc m) a
v
tryPutMVar :: forall a. MVar (IsConc m) a -> a -> IsConc m Bool
tryPutMVar MVar (IsConc m) a
v = forall (m :: * -> *) a. MonadConc m => m a -> IsConc m a
toIsConc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadConc m => MVar m a -> a -> m Bool
tryPutMVar MVar (IsConc m) a
v
takeMVar :: forall a. MVar (IsConc m) a -> IsConc m a
takeMVar = forall (m :: * -> *) a. MonadConc m => m a -> IsConc m a
toIsConc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadConc m => MVar m a -> m a
takeMVar
tryTakeMVar :: forall a. MVar (IsConc m) a -> IsConc m (Maybe a)
tryTakeMVar = forall (m :: * -> *) a. MonadConc m => m a -> IsConc m a
toIsConc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadConc m => MVar m a -> m (Maybe a)
tryTakeMVar
newIORef :: forall a. a -> IsConc m (IORef (IsConc m) a)
newIORef = forall (m :: * -> *) a. MonadConc m => m a -> IsConc m a
toIsConc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadConc m => a -> m (IORef m a)
newIORef
newIORefN :: forall a. String -> a -> IsConc m (IORef (IsConc m) a)
newIORefN String
n = forall (m :: * -> *) a. MonadConc m => m a -> IsConc m a
toIsConc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadConc m => String -> a -> m (IORef m a)
newIORefN String
n
readIORef :: forall a. IORef (IsConc m) a -> IsConc m a
readIORef = forall (m :: * -> *) a. MonadConc m => m a -> IsConc m a
toIsConc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadConc m => IORef m a -> m a
readIORef
atomicModifyIORef :: forall a b. IORef (IsConc m) a -> (a -> (a, b)) -> IsConc m b
atomicModifyIORef IORef (IsConc m) a
r = forall (m :: * -> *) a. MonadConc m => m a -> IsConc m a
toIsConc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a b.
MonadConc m =>
IORef m a -> (a -> (a, b)) -> m b
atomicModifyIORef IORef (IsConc m) a
r
writeIORef :: forall a. IORef (IsConc m) a -> a -> IsConc m ()
writeIORef IORef (IsConc m) a
r = forall (m :: * -> *) a. MonadConc m => m a -> IsConc m a
toIsConc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadConc m => IORef m a -> a -> m ()
writeIORef IORef (IsConc m) a
r
atomicWriteIORef :: forall a. IORef (IsConc m) a -> a -> IsConc m ()
atomicWriteIORef IORef (IsConc m) a
r = forall (m :: * -> *) a. MonadConc m => m a -> IsConc m a
toIsConc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadConc m => IORef m a -> a -> m ()
atomicWriteIORef IORef (IsConc m) a
r
readForCAS :: forall a. IORef (IsConc m) a -> IsConc m (Ticket (IsConc m) a)
readForCAS = forall (m :: * -> *) a. MonadConc m => m a -> IsConc m a
toIsConc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadConc m => IORef m a -> m (Ticket m a)
readForCAS
peekTicket' :: forall a. Proxy (IsConc m) -> Ticket (IsConc m) a -> a
peekTicket' Proxy (IsConc m)
_ = forall (m :: * -> *) a. MonadConc m => Proxy m -> Ticket m a -> a
peekTicket' (forall {k} (t :: k). Proxy t
Proxy :: Proxy m)
casIORef :: forall a.
IORef (IsConc m) a
-> Ticket (IsConc m) a -> a -> IsConc m (Bool, Ticket (IsConc m) a)
casIORef IORef (IsConc m) a
r Ticket (IsConc m) a
t = forall (m :: * -> *) a. MonadConc m => m a -> IsConc m a
toIsConc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a.
MonadConc m =>
IORef m a -> Ticket m a -> a -> m (Bool, Ticket m a)
casIORef IORef (IsConc m) a
r Ticket (IsConc m) a
t
modifyIORefCAS :: forall a b. IORef (IsConc m) a -> (a -> (a, b)) -> IsConc m b
modifyIORefCAS IORef (IsConc m) a
r = forall (m :: * -> *) a. MonadConc m => m a -> IsConc m a
toIsConc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a b.
MonadConc m =>
IORef m a -> (a -> (a, b)) -> m b
modifyIORefCAS IORef (IsConc m) a
r
modifyIORefCAS_ :: forall a. IORef (IsConc m) a -> (a -> a) -> IsConc m ()
modifyIORefCAS_ IORef (IsConc m) a
r = forall (m :: * -> *) a. MonadConc m => m a -> IsConc m a
toIsConc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a.
MonadConc m =>
IORef m a -> (a -> a) -> m ()
modifyIORefCAS_ IORef (IsConc m) a
r
atomically :: forall a. STM (IsConc m) a -> IsConc m a
atomically = forall (m :: * -> *) a. MonadConc m => m a -> IsConc m a
toIsConc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadConc m => STM m a -> m a
atomically forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadSTM m => IsSTM m a -> m a
fromIsSTM
newTVarConc :: forall a. a -> IsConc m (TVar (STM (IsConc m)) a)
newTVarConc = forall (m :: * -> *) a. MonadConc m => m a -> IsConc m a
toIsConc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadConc m => a -> m (TVar (STM m) a)
newTVarConc
readTVarConc :: forall a. TVar (STM (IsConc m)) a -> IsConc m a
readTVarConc = forall (m :: * -> *) a. MonadConc m => m a -> IsConc m a
toIsConc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadConc m => TVar (STM m) a -> m a
readTVarConc
getMaskingState :: IsConc m MaskingState
getMaskingState = forall (m :: * -> *) a. MonadConc m => m a -> IsConc m a
toIsConc forall (m :: * -> *). MonadConc m => m MaskingState
getMaskingState
#define INSTANCE(T,C,F) \
instance C => MonadConc (T m) where { \
type STM (T m) = STM m ; \
type MVar (T m) = MVar m ; \
type IORef (T m) = IORef m ; \
type Ticket (T m) = Ticket m ; \
type ThreadId (T m) = ThreadId m ; \
\
forkWithUnmask = liftedFork F forkWithUnmask ; \
forkWithUnmaskN n = liftedFork F (forkWithUnmaskN n ) ; \
forkOnWithUnmask i = liftedFork F (forkOnWithUnmask i) ; \
forkOnWithUnmaskN n i = liftedFork F (forkOnWithUnmaskN n i) ; \
forkOSWithUnmask = liftedFork F forkOSWithUnmask ; \
forkOSWithUnmaskN n = liftedFork F (forkOSWithUnmaskN n ) ; \
\
supportsBoundThreads = lift supportsBoundThreads ; \
isCurrentThreadBound = lift isCurrentThreadBound ; \
\
getNumCapabilities = lift getNumCapabilities ; \
setNumCapabilities = lift . setNumCapabilities ; \
myThreadId = lift myThreadId ; \
yield = lift yield ; \
threadDelay = lift . threadDelay ; \
throwTo t = lift . throwTo t ; \
newEmptyMVar = lift newEmptyMVar ; \
newEmptyMVarN = lift . newEmptyMVarN ; \
readMVar = lift . readMVar ; \
tryReadMVar = lift . tryReadMVar ; \
putMVar v = lift . putMVar v ; \
tryPutMVar v = lift . tryPutMVar v ; \
takeMVar = lift . takeMVar ; \
tryTakeMVar = lift . tryTakeMVar ; \
newIORef = lift . newIORef ; \
newIORefN n = lift . newIORefN n ; \
readIORef = lift . readIORef ; \
atomicModifyIORef r = lift . atomicModifyIORef r ; \
writeIORef r = lift . writeIORef r ; \
atomicWriteIORef r = lift . atomicWriteIORef r ; \
readForCAS = lift . readForCAS ; \
peekTicket' _ = peekTicket' (Proxy :: Proxy m) ; \
casIORef r t = lift . casIORef r t ; \
modifyIORefCAS r = lift . modifyIORefCAS r ; \
modifyIORefCAS_ r = lift . modifyIORefCAS_ r ; \
atomically = lift . atomically ; \
newTVarConc = lift . newTVarConc ; \
readTVarConc = lift . readTVarConc ; \
getMaskingState = lift getMaskingState ; \
unsafeUnmask = liftedF F unsafeUnmask }
INSTANCE(ReaderT r, MonadConc m, id)
INSTANCE(IdentityT, MonadConc m, id)
INSTANCE(WL.WriterT w, (MonadConc m, Monoid w), fst)
INSTANCE(WS.WriterT w, (MonadConc m, Monoid w), fst)
INSTANCE(SL.StateT s, MonadConc m, fst)
INSTANCE(SS.StateT s, MonadConc m, fst)
INSTANCE(RL.RWST r w s, (MonadConc m, Monoid w), (\(a,_,_) -> a))
INSTANCE(RS.RWST r w s, (MonadConc m, Monoid w), (\(a,_,_) -> a))
#undef INSTANCE
liftedF :: (MonadTransControl t, MonadConc m)
=> (forall x. StT t x -> x)
-> (m a -> m b)
-> t m a
-> t m b
liftedF :: forall (t :: (* -> *) -> * -> *) (m :: * -> *) a b.
(MonadTransControl t, MonadConc m) =>
(forall x. StT t x -> x) -> (m a -> m b) -> t m a -> t m b
liftedF forall x. StT t x -> x
unst m a -> m b
f t m a
ma = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTransControl t, Monad m) =>
(Run t -> m a) -> t m a
liftWith forall a b. (a -> b) -> a -> b
$ \Run t
run -> m a -> m b
f (forall x. StT t x -> x
unst forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Run t
run t m a
ma)
liftedFork :: (MonadTransControl t, MonadConc m)
=> (forall x. StT t x -> x)
-> (((forall x. m x -> m x) -> m a) -> m b)
-> ((forall x. t m x -> t m x) -> t m a)
-> t m b
liftedFork :: forall (t :: (* -> *) -> * -> *) (m :: * -> *) a b.
(MonadTransControl t, MonadConc m) =>
(forall x. StT t x -> x)
-> (((forall x. m x -> m x) -> m a) -> m b)
-> ((forall x. t m x -> t m x) -> t m a)
-> t m b
liftedFork forall x. StT t x -> x
unst ((forall x. m x -> m x) -> m a) -> m b
f (forall x. t m x -> t m x) -> t m a
ma = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTransControl t, Monad m) =>
(Run t -> m a) -> t m a
liftWith forall a b. (a -> b) -> a -> b
$ \Run t
run ->
((forall x. m x -> m x) -> m a) -> m b
f (\forall x. m x -> m x
unmask -> forall x. StT t x -> x
unst forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Run t
run ((forall x. t m x -> t m x) -> t m a
ma forall a b. (a -> b) -> a -> b
$ forall (t :: (* -> *) -> * -> *) (m :: * -> *) a b.
(MonadTransControl t, MonadConc m) =>
(forall x. StT t x -> x) -> (m a -> m b) -> t m a -> t m b
liftedF forall x. StT t x -> x
unst forall x. m x -> m x
unmask))