{-# LANGUAGE RankNTypes #-}
module UnliftIO.Concurrent
(
ThreadId,
myThreadId, forkIO, forkWithUnmask, forkIOWithUnmask, forkFinally, killThread, throwTo,
forkOn, forkOnWithUnmask, getNumCapabilities, setNumCapabilities,
threadCapability,
yield,
threadDelay, threadWaitRead, threadWaitWrite,
module UnliftIO.MVar, module UnliftIO.Chan,
C.rtsSupportsBoundThreads, forkOS, isCurrentThreadBound, runInBoundThread,
runInUnboundThread,
mkWeakThreadId
) where
import Control.Monad.IO.Class (MonadIO, liftIO)
import System.Posix.Types (Fd)
import System.Mem.Weak (Weak)
import Control.Concurrent (ThreadId)
import qualified Control.Concurrent as C
import Control.Monad.IO.Unlift
import UnliftIO.MVar
import UnliftIO.Chan
import UnliftIO.Exception (throwTo, SomeException)
myThreadId :: MonadIO m => m ThreadId
myThreadId :: forall (m :: * -> *). MonadIO m => m ThreadId
myThreadId = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO ThreadId
C.myThreadId
{-# INLINABLE myThreadId #-}
forkIO :: MonadUnliftIO m => m () -> m ThreadId
forkIO :: forall (m :: * -> *). MonadUnliftIO m => m () -> m ThreadId
forkIO m ()
m = forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO forall a b. (a -> b) -> a -> b
$ \forall a. m a -> IO a
run -> IO () -> IO ThreadId
C.forkIO forall a b. (a -> b) -> a -> b
$ forall a. m a -> IO a
run m ()
m
{-# INLINABLE forkIO #-}
forkIOWithUnmask :: MonadUnliftIO m => ((forall a. m a -> m a) -> m ()) -> m ThreadId
forkIOWithUnmask :: forall (m :: * -> *).
MonadUnliftIO m =>
((forall a. m a -> m a) -> m ()) -> m ThreadId
forkIOWithUnmask (forall a. m a -> m a) -> m ()
m =
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO forall a b. (a -> b) -> a -> b
$ \forall a. m a -> IO a
run -> ((forall a. IO a -> IO a) -> IO ()) -> IO ThreadId
C.forkIOWithUnmask forall a b. (a -> b) -> a -> b
$ \forall a. IO a -> IO a
unmask -> forall a. m a -> IO a
run forall a b. (a -> b) -> a -> b
$ (forall a. m a -> m a) -> m ()
m forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. IO a -> IO a
unmask forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. m a -> IO a
run
{-# INLINABLE forkIOWithUnmask #-}
forkWithUnmask :: MonadUnliftIO m => ((forall a. m a -> m a) -> m ()) -> m ThreadId
forkWithUnmask :: forall (m :: * -> *).
MonadUnliftIO m =>
((forall a. m a -> m a) -> m ()) -> m ThreadId
forkWithUnmask = forall (m :: * -> *).
MonadUnliftIO m =>
((forall a. m a -> m a) -> m ()) -> m ThreadId
forkIOWithUnmask
{-# INLINABLE forkWithUnmask #-}
{-# DEPRECATED forkWithUnmask "forkWithUnmask has been renamed to forkIOWithUnmask" #-}
forkFinally :: MonadUnliftIO m => m a -> (Either SomeException a -> m ()) -> m ThreadId
forkFinally :: forall (m :: * -> *) a.
MonadUnliftIO m =>
m a -> (Either SomeException a -> m ()) -> m ThreadId
forkFinally m a
m1 Either SomeException a -> m ()
m2 = forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO forall a b. (a -> b) -> a -> b
$ \forall a. m a -> IO a
run -> forall a. IO a -> (Either SomeException a -> IO ()) -> IO ThreadId
C.forkFinally (forall a. m a -> IO a
run m a
m1) forall a b. (a -> b) -> a -> b
$ forall a. m a -> IO a
run forall b c a. (b -> c) -> (a -> b) -> a -> c
. Either SomeException a -> m ()
m2
{-# INLINABLE forkFinally #-}
killThread :: MonadIO m => ThreadId -> m ()
killThread :: forall (m :: * -> *). MonadIO m => ThreadId -> m ()
killThread = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. ThreadId -> IO ()
C.killThread
{-# INLINABLE killThread #-}
forkOn :: MonadUnliftIO m => Int -> m () -> m ThreadId
forkOn :: forall (m :: * -> *). MonadUnliftIO m => Int -> m () -> m ThreadId
forkOn Int
i m ()
m = forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO forall a b. (a -> b) -> a -> b
$ \forall a. m a -> IO a
run -> Int -> IO () -> IO ThreadId
C.forkOn Int
i forall a b. (a -> b) -> a -> b
$ forall a. m a -> IO a
run m ()
m
{-# INLINABLE forkOn #-}
forkOnWithUnmask :: MonadUnliftIO m => Int -> ((forall a. m a -> m a) -> m ()) -> m ThreadId
forkOnWithUnmask :: forall (m :: * -> *).
MonadUnliftIO m =>
Int -> ((forall a. m a -> m a) -> m ()) -> m ThreadId
forkOnWithUnmask Int
i (forall a. m a -> m a) -> m ()
m =
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO forall a b. (a -> b) -> a -> b
$ \forall a. m a -> IO a
run -> Int -> ((forall a. IO a -> IO a) -> IO ()) -> IO ThreadId
C.forkOnWithUnmask Int
i forall a b. (a -> b) -> a -> b
$ \forall a. IO a -> IO a
unmask -> forall a. m a -> IO a
run forall a b. (a -> b) -> a -> b
$ (forall a. m a -> m a) -> m ()
m forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. IO a -> IO a
unmask forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. m a -> IO a
run
{-# INLINABLE forkOnWithUnmask #-}
getNumCapabilities :: MonadIO m => m Int
getNumCapabilities :: forall (m :: * -> *). MonadIO m => m Int
getNumCapabilities = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO Int
C.getNumCapabilities
{-# INLINABLE getNumCapabilities #-}
setNumCapabilities :: MonadIO m => Int -> m ()
setNumCapabilities :: forall (m :: * -> *). MonadIO m => Int -> m ()
setNumCapabilities = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> IO ()
C.setNumCapabilities
{-# INLINABLE setNumCapabilities #-}
threadCapability :: MonadIO m => ThreadId -> m (Int, Bool)
threadCapability :: forall (m :: * -> *). MonadIO m => ThreadId -> m (Int, Bool)
threadCapability = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. ThreadId -> IO (Int, Bool)
C.threadCapability
{-# INLINABLE threadCapability #-}
yield :: MonadIO m => m ()
yield :: forall (m :: * -> *). MonadIO m => m ()
yield = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO ()
C.yield
{-# INLINABLE yield #-}
threadDelay :: MonadIO m => Int -> m ()
threadDelay :: forall (m :: * -> *). MonadIO m => Int -> m ()
threadDelay = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> IO ()
C.threadDelay
{-# INLINABLE threadDelay #-}
threadWaitRead :: MonadIO m => Fd -> m ()
threadWaitRead :: forall (m :: * -> *). MonadIO m => Fd -> m ()
threadWaitRead = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. Fd -> IO ()
C.threadWaitRead
{-# INLINABLE threadWaitRead #-}
threadWaitWrite :: MonadIO m => Fd -> m ()
threadWaitWrite :: forall (m :: * -> *). MonadIO m => Fd -> m ()
threadWaitWrite = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. Fd -> IO ()
C.threadWaitWrite
{-# INLINABLE threadWaitWrite #-}
forkOS :: MonadUnliftIO m => m () -> m ThreadId
forkOS :: forall (m :: * -> *). MonadUnliftIO m => m () -> m ThreadId
forkOS m ()
m = forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO forall a b. (a -> b) -> a -> b
$ \forall a. m a -> IO a
run -> IO () -> IO ThreadId
C.forkOS forall a b. (a -> b) -> a -> b
$ forall a. m a -> IO a
run m ()
m
{-# INLINABLE forkOS #-}
isCurrentThreadBound :: MonadIO m => m Bool
isCurrentThreadBound :: forall (m :: * -> *). MonadIO m => m Bool
isCurrentThreadBound = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO Bool
C.isCurrentThreadBound
{-# INLINABLE isCurrentThreadBound #-}
runInBoundThread :: MonadUnliftIO m => m a -> m a
runInBoundThread :: forall (m :: * -> *) a. MonadUnliftIO m => m a -> m a
runInBoundThread m a
m = forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO forall a b. (a -> b) -> a -> b
$ \forall a. m a -> IO a
run -> forall a. IO a -> IO a
C.runInBoundThread forall a b. (a -> b) -> a -> b
$ forall a. m a -> IO a
run m a
m
{-# INLINABLE runInBoundThread #-}
runInUnboundThread :: MonadUnliftIO m => m a -> m a
runInUnboundThread :: forall (m :: * -> *) a. MonadUnliftIO m => m a -> m a
runInUnboundThread m a
m = forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO forall a b. (a -> b) -> a -> b
$ \forall a. m a -> IO a
run -> forall a. IO a -> IO a
C.runInUnboundThread forall a b. (a -> b) -> a -> b
$ forall a. m a -> IO a
run m a
m
{-# INLINABLE runInUnboundThread #-}
mkWeakThreadId :: MonadIO m => ThreadId -> m (Weak ThreadId)
mkWeakThreadId :: forall (m :: * -> *). MonadIO m => ThreadId -> m (Weak ThreadId)
mkWeakThreadId = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. ThreadId -> IO (Weak ThreadId)
C.mkWeakThreadId
{-# INLINABLE mkWeakThreadId #-}