{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE RankNTypes #-}
module Context.Concurrent
(
forkIO
, forkFinally
, forkIOWithUnmask
, forkOn
, forkOnWithUnmask
, forkOS
, forkOSWithUnmask
, runInBoundThread
, runInUnboundThread
, ThreadId
, myThreadId
, killThread
, throwTo
, getNumCapabilities
, setNumCapabilities
, threadCapability
, yield
, threadDelay
, threadWaitRead
, threadWaitWrite
, threadWaitReadSTM
, threadWaitWriteSTM
, rtsSupportsBoundThreads
, isCurrentThreadBound
, mkWeakThreadId
, module Control.Concurrent.MVar
, module Control.Concurrent.Chan
, module Control.Concurrent.QSem
, module Control.Concurrent.QSemN
) where
import Control.Concurrent
( ThreadId, getNumCapabilities, isCurrentThreadBound, killThread, mkWeakThreadId, myThreadId
, rtsSupportsBoundThreads, setNumCapabilities, threadCapability, threadDelay, threadWaitRead
, threadWaitReadSTM, threadWaitWrite, threadWaitWriteSTM, throwTo, yield
)
import Control.Concurrent.Chan
import Control.Concurrent.MVar
import Control.Concurrent.QSem
import Control.Concurrent.QSemN
import Control.Exception (SomeException)
import Prelude
import qualified Context.Internal as Internal
import qualified Control.Concurrent as Concurrent
import qualified Control.Exception as Exception
forkIO :: IO () -> IO ThreadId
forkIO :: IO () -> IO ThreadId
forkIO IO ()
action = do
((IO () -> IO ()) -> IO ThreadId) -> IO ThreadId
forall a b. ((IO a -> IO a) -> IO b) -> IO b
Internal.withPropagator (((IO () -> IO ()) -> IO ThreadId) -> IO ThreadId)
-> ((IO () -> IO ()) -> IO ThreadId) -> IO ThreadId
forall a b. (a -> b) -> a -> b
$ \IO () -> IO ()
propagate -> do
IO () -> IO ThreadId
Concurrent.forkIO (IO () -> IO ThreadId) -> IO () -> IO ThreadId
forall a b. (a -> b) -> a -> b
$ IO () -> IO ()
propagate IO ()
action
forkFinally :: IO a -> (Either SomeException a -> IO ()) -> IO ThreadId
forkFinally :: forall a. IO a -> (Either SomeException a -> IO ()) -> IO ThreadId
forkFinally IO a
action Either SomeException a -> IO ()
and_then = do
((IO () -> IO ()) -> IO ThreadId) -> IO ThreadId
forall a b. ((IO a -> IO a) -> IO b) -> IO b
Internal.withPropagator (((IO () -> IO ()) -> IO ThreadId) -> IO ThreadId)
-> ((IO () -> IO ()) -> IO ThreadId) -> IO ThreadId
forall a b. (a -> b) -> a -> b
$ \IO () -> IO ()
propagate -> do
((forall a. IO a -> IO a) -> IO ThreadId) -> IO ThreadId
forall b. ((forall a. IO a -> IO a) -> IO b) -> IO b
Exception.mask (((forall a. IO a -> IO a) -> IO ThreadId) -> IO ThreadId)
-> ((forall a. IO a -> IO a) -> IO ThreadId) -> IO ThreadId
forall a b. (a -> b) -> a -> b
$ \forall a. IO a -> IO a
restore -> do
IO () -> IO ThreadId
Concurrent.forkIO (IO () -> IO ThreadId) -> IO () -> IO ThreadId
forall a b. (a -> b) -> a -> b
$ IO () -> IO ()
propagate (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ do
IO a -> IO (Either SomeException a)
forall e a. Exception e => IO a -> IO (Either e a)
Exception.try (IO a -> IO a
forall a. IO a -> IO a
restore IO a
action) IO (Either SomeException a)
-> (Either SomeException a -> IO ()) -> IO ()
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Either SomeException a -> IO ()
and_then
forkIOWithUnmask :: ((forall a. IO a -> IO a) -> IO ()) -> IO ThreadId
forkIOWithUnmask :: ((forall a. IO a -> IO a) -> IO ()) -> IO ThreadId
forkIOWithUnmask (forall a. IO a -> IO a) -> IO ()
io = do
((IO () -> IO ()) -> IO ThreadId) -> IO ThreadId
forall a b. ((IO a -> IO a) -> IO b) -> IO b
Internal.withPropagator (((IO () -> IO ()) -> IO ThreadId) -> IO ThreadId)
-> ((IO () -> IO ()) -> IO ThreadId) -> IO ThreadId
forall a b. (a -> b) -> a -> b
$ \IO () -> IO ()
propagate -> do
((forall a. IO a -> IO a) -> IO ()) -> IO ThreadId
Concurrent.forkIOWithUnmask (((forall a. IO a -> IO a) -> IO ()) -> IO ThreadId)
-> ((forall a. IO a -> IO a) -> IO ()) -> IO ThreadId
forall a b. (a -> b) -> a -> b
$ \forall a. IO a -> IO a
restore -> do
IO () -> IO ()
propagate (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ (forall a. IO a -> IO a) -> IO ()
io IO a -> IO a
forall a. IO a -> IO a
restore
forkOn :: Int -> IO () -> IO ThreadId
forkOn :: Int -> IO () -> IO ThreadId
forkOn Int
cpu IO ()
action = do
((IO () -> IO ()) -> IO ThreadId) -> IO ThreadId
forall a b. ((IO a -> IO a) -> IO b) -> IO b
Internal.withPropagator (((IO () -> IO ()) -> IO ThreadId) -> IO ThreadId)
-> ((IO () -> IO ()) -> IO ThreadId) -> IO ThreadId
forall a b. (a -> b) -> a -> b
$ \IO () -> IO ()
propagate -> do
Int -> IO () -> IO ThreadId
Concurrent.forkOn Int
cpu (IO () -> IO ThreadId) -> IO () -> IO ThreadId
forall a b. (a -> b) -> a -> b
$ IO () -> IO ()
propagate IO ()
action
forkOnWithUnmask :: Int -> ((forall a. IO a -> IO a) -> IO ()) -> IO ThreadId
forkOnWithUnmask :: Int -> ((forall a. IO a -> IO a) -> IO ()) -> IO ThreadId
forkOnWithUnmask Int
cpu (forall a. IO a -> IO a) -> IO ()
io = do
((IO () -> IO ()) -> IO ThreadId) -> IO ThreadId
forall a b. ((IO a -> IO a) -> IO b) -> IO b
Internal.withPropagator (((IO () -> IO ()) -> IO ThreadId) -> IO ThreadId)
-> ((IO () -> IO ()) -> IO ThreadId) -> IO ThreadId
forall a b. (a -> b) -> a -> b
$ \IO () -> IO ()
propagate -> do
Int -> ((forall a. IO a -> IO a) -> IO ()) -> IO ThreadId
Concurrent.forkOnWithUnmask Int
cpu (((forall a. IO a -> IO a) -> IO ()) -> IO ThreadId)
-> ((forall a. IO a -> IO a) -> IO ()) -> IO ThreadId
forall a b. (a -> b) -> a -> b
$ \forall a. IO a -> IO a
restore -> do
IO () -> IO ()
propagate (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ (forall a. IO a -> IO a) -> IO ()
io IO a -> IO a
forall a. IO a -> IO a
restore
forkOS :: IO () -> IO ThreadId
forkOS :: IO () -> IO ThreadId
forkOS IO ()
action = do
((IO () -> IO ()) -> IO ThreadId) -> IO ThreadId
forall a b. ((IO a -> IO a) -> IO b) -> IO b
Internal.withPropagator (((IO () -> IO ()) -> IO ThreadId) -> IO ThreadId)
-> ((IO () -> IO ()) -> IO ThreadId) -> IO ThreadId
forall a b. (a -> b) -> a -> b
$ \IO () -> IO ()
propagate -> do
IO () -> IO ThreadId
Concurrent.forkOS (IO () -> IO ThreadId) -> IO () -> IO ThreadId
forall a b. (a -> b) -> a -> b
$ IO () -> IO ()
propagate IO ()
action
forkOSWithUnmask :: ((forall a. IO a -> IO a) -> IO ()) -> IO ThreadId
forkOSWithUnmask :: ((forall a. IO a -> IO a) -> IO ()) -> IO ThreadId
forkOSWithUnmask (forall a. IO a -> IO a) -> IO ()
io = do
((IO () -> IO ()) -> IO ThreadId) -> IO ThreadId
forall a b. ((IO a -> IO a) -> IO b) -> IO b
Internal.withPropagator (((IO () -> IO ()) -> IO ThreadId) -> IO ThreadId)
-> ((IO () -> IO ()) -> IO ThreadId) -> IO ThreadId
forall a b. (a -> b) -> a -> b
$ \IO () -> IO ()
propagate -> do
((forall a. IO a -> IO a) -> IO ()) -> IO ThreadId
Concurrent.forkOSWithUnmask (((forall a. IO a -> IO a) -> IO ()) -> IO ThreadId)
-> ((forall a. IO a -> IO a) -> IO ()) -> IO ThreadId
forall a b. (a -> b) -> a -> b
$ \forall a. IO a -> IO a
restore -> do
IO () -> IO ()
propagate (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ (forall a. IO a -> IO a) -> IO ()
io IO a -> IO a
forall a. IO a -> IO a
restore
runInBoundThread :: IO a -> IO a
runInBoundThread :: forall a. IO a -> IO a
runInBoundThread IO a
action =
((IO a -> IO a) -> IO a) -> IO a
forall a b. ((IO a -> IO a) -> IO b) -> IO b
Internal.withPropagator (((IO a -> IO a) -> IO a) -> IO a)
-> ((IO a -> IO a) -> IO a) -> IO a
forall a b. (a -> b) -> a -> b
$ \IO a -> IO a
propagate -> do
IO a -> IO a
forall a. IO a -> IO a
Concurrent.runInBoundThread (IO a -> IO a) -> IO a -> IO a
forall a b. (a -> b) -> a -> b
$ IO a -> IO a
propagate IO a
action
runInUnboundThread :: IO a -> IO a
runInUnboundThread :: forall a. IO a -> IO a
runInUnboundThread IO a
action =
((IO a -> IO a) -> IO a) -> IO a
forall a b. ((IO a -> IO a) -> IO b) -> IO b
Internal.withPropagator (((IO a -> IO a) -> IO a) -> IO a)
-> ((IO a -> IO a) -> IO a) -> IO a
forall a b. (a -> b) -> a -> b
$ \IO a -> IO a
propagate -> do
IO a -> IO a
forall a. IO a -> IO a
Concurrent.runInUnboundThread (IO a -> IO a) -> IO a -> IO a
forall a b. (a -> b) -> a -> b
$ IO a -> IO a
propagate IO a
action