#if __GLASGOW_HASKELL__ >= 702
#endif
module Control.Concurrent.Lifted
(
ThreadId
, myThreadId
, fork
#if MIN_VERSION_base(4,4,0)
, forkWithUnmask
#endif
#if MIN_VERSION_base(4,6,0)
, forkFinally
#endif
, killThread
, throwTo
#if MIN_VERSION_base(4,4,0)
, forkOn
, forkOnWithUnmask
, getNumCapabilities
#if MIN_VERSION_base(4,6,0)
, setNumCapabilities
#endif
, threadCapability
#endif
, yield
, threadDelay
, threadWaitRead
, threadWaitWrite
, module Control.Concurrent.MVar.Lifted
, module Control.Concurrent.Chan.Lifted
, module Control.Concurrent.QSem.Lifted
, module Control.Concurrent.QSemN.Lifted
#if !MIN_VERSION_base(4,7,0)
, module Control.Concurrent.SampleVar.Lifted
#endif
#if !MIN_VERSION_base(4,6,0)
, merge
, nmerge
#endif
, C.rtsSupportsBoundThreads
, forkOS
, isCurrentThreadBound
, runInBoundThread
, runInUnboundThread
#if MIN_VERSION_base(4,6,0)
, mkWeakThreadId
#endif
) where
import Prelude ( (.) )
import Data.Bool ( Bool )
import Data.Int ( Int )
import Data.Function ( ($) )
import System.IO ( IO )
import System.Posix.Types ( Fd )
#if MIN_VERSION_base(4,6,0)
import Control.Monad ( (>>=) )
import Data.Either ( Either )
import System.Mem.Weak ( Weak )
#endif
import Control.Concurrent ( ThreadId )
import qualified Control.Concurrent as C
import Control.Monad.Base ( MonadBase, liftBase )
import Control.Monad.Trans.Control ( MonadBaseControl, liftBaseOp_, liftBaseDiscard )
#if MIN_VERSION_base(4,4,0)
import Control.Monad.Trans.Control ( liftBaseWith )
import Control.Monad ( void )
#endif
import Control.Concurrent.MVar.Lifted
import Control.Concurrent.Chan.Lifted
import Control.Concurrent.QSem.Lifted
import Control.Concurrent.QSemN.Lifted
#if !MIN_VERSION_base(4,7,0)
import Control.Concurrent.SampleVar.Lifted
#endif
import Control.Exception.Lifted ( throwTo
#if MIN_VERSION_base(4,6,0)
, SomeException, try, mask
#endif
)
#include "inlinable.h"
myThreadId :: MonadBase IO m => m ThreadId
myThreadId = liftBase C.myThreadId
fork :: MonadBaseControl IO m => m () -> m ThreadId
fork = liftBaseDiscard C.forkIO
#if MIN_VERSION_base(4,4,0)
forkWithUnmask :: MonadBaseControl IO m => ((forall a. m a -> m a) -> m ()) -> m ThreadId
forkWithUnmask f = liftBaseWith $ \runInIO ->
C.forkIOWithUnmask $ \unmask ->
void $ runInIO $ f $ liftBaseOp_ unmask
#endif
#if MIN_VERSION_base(4,6,0)
forkFinally :: MonadBaseControl IO m
=> m a -> (Either SomeException a -> m ()) -> m ThreadId
forkFinally action and_then =
mask $ \restore ->
fork $ try (restore action) >>= and_then
#endif
killThread :: MonadBase IO m => ThreadId -> m ()
killThread = liftBase . C.killThread
#if MIN_VERSION_base(4,4,0)
forkOn :: MonadBaseControl IO m => Int -> m () -> m ThreadId
forkOn = liftBaseDiscard . C.forkOn
forkOnWithUnmask :: MonadBaseControl IO m => Int -> ((forall a. m a -> m a) -> m ()) -> m ThreadId
forkOnWithUnmask cap f = liftBaseWith $ \runInIO ->
C.forkOnWithUnmask cap $ \unmask ->
void $ runInIO $ f $ liftBaseOp_ unmask
getNumCapabilities :: MonadBase IO m => m Int
getNumCapabilities = liftBase C.getNumCapabilities
#if MIN_VERSION_base(4,6,0)
setNumCapabilities :: MonadBase IO m => Int -> m ()
setNumCapabilities = liftBase . C.setNumCapabilities
#endif
threadCapability :: MonadBase IO m => ThreadId -> m (Int, Bool)
threadCapability = liftBase . C.threadCapability
#endif
yield :: MonadBase IO m => m ()
yield = liftBase C.yield
threadDelay :: MonadBase IO m => Int -> m ()
threadDelay = liftBase . C.threadDelay
threadWaitRead :: MonadBase IO m => Fd -> m ()
threadWaitRead = liftBase . C.threadWaitRead
threadWaitWrite :: MonadBase IO m => Fd -> m ()
threadWaitWrite = liftBase . C.threadWaitWrite
#if !MIN_VERSION_base(4,6,0)
merge :: MonadBase IO m => [a] -> [a] -> m [a]
merge xs ys = liftBase $ C.mergeIO xs ys
nmerge :: MonadBase IO m => [[a]] -> m [a]
nmerge = liftBase . C.nmergeIO
#endif
forkOS :: MonadBaseControl IO m => m () -> m ThreadId
forkOS = liftBaseDiscard C.forkOS
isCurrentThreadBound :: MonadBase IO m => m Bool
isCurrentThreadBound = liftBase C.isCurrentThreadBound
runInBoundThread :: MonadBaseControl IO m => m a -> m a
runInBoundThread = liftBaseOp_ C.runInBoundThread
runInUnboundThread :: MonadBaseControl IO m => m a -> m a
runInUnboundThread = liftBaseOp_ C.runInUnboundThread
#if MIN_VERSION_base(4,6,0)
mkWeakThreadId :: MonadBase IO m => ThreadId -> m (Weak ThreadId)
mkWeakThreadId = liftBase . C.mkWeakThreadId
#endif