PrioritySync.PrioritySync
- data TaskHandle p a
- claim :: (RoomGroup c, ClaimContext c) => ClaimMode -> c -> IO a -> IO a
- dispatch :: (RoomGroup c, ClaimContext c, Prioritized (ClaimHandle c)) => c -> IO a -> IO (TaskHandle (Priority (ClaimHandle c)) a)
- getResult :: TaskHandle p a -> IO a
- tryGetResult :: TaskHandle p a -> IO (Maybe a)
- class Prioritized p
- reprioritize :: TaskHandle p a -> (p -> p) -> IO ()
- data Constrained u = Constrained
- data Unconstrained u = Unconstrained
- newtype MaxThreads = MaxThreads Int
- data Room u
- newRoom :: u -> IO (Room u)
- userData :: Room u -> u
- data ClaimMode
- load :: Ord p => TaskPool p u -> IO Int
- class Occupancy o where
- data Ord a => QueueConfigurationRecord a = QueueConfigurationRecord {
- queue_predicate :: STM ()
- priority_indexed_predicate :: a -> STM ()
- allowed_priority_inversion :: a -> a -> Bool
- allowed_ordering_inversion :: Int
- queue_order :: !QueueOrder
- fair_queue_configuration :: Ord a => QueueConfigurationRecord a
- fast_queue_configuration :: Ord a => QueueConfigurationRecord a
- data QueueOrder
- data TaskPool p u
- schedule :: TaskPool p u -> p -> Schedule p (Constrained (TaskPoolConstraint u), Room (TaskPoolConstraint u))
- newTaskPool :: Ord p => QueueConfigurationRecord p -> Int -> u -> IO (TaskPool p u)
- simpleTaskPool :: Ord p => IO (TaskPool p ())
- startQueue :: TaskPool p a -> IO ()
- stopQueue :: TaskPool p a -> IO ()
- waitUntilFinished :: Ord p => TaskPool p u -> IO ()
Documentation
data TaskHandle p a Source
Instances
| Prioritized (TaskHandle p a) | Change the priority of a task. This will not work if the task has already started. |
claim :: (RoomGroup c, ClaimContext c) => ClaimMode -> c -> IO a -> IO aSource
Temporarily Acquire, and then release, or Release, and then acquire, some Rooms for the duration of a critical section.
A simple example where a room might be used to prevent interleaving of stdout:
room <- newRoom (MaxThreads 1) forkIO $ claim Acquire (Default,room) $ putStrLn "Hello World!" forkIO $ claim Acquire (Default,room) $ putStrLn "Foo! Bar!"
dispatch :: (RoomGroup c, ClaimContext c, Prioritized (ClaimHandle c)) => c -> IO a -> IO (TaskHandle (Priority (ClaimHandle c)) a)Source
Perform a task on another thread. This task can be reprioritized and canceled.
getResult :: TaskHandle p a -> IO aSource
tryGetResult :: TaskHandle p a -> IO (Maybe a)Source
class Prioritized p Source
Reprioritize a task. This has no effect on a target that has already left the queue.
Instances
| Prioritized p => Prioritized (Maybe p) | |
| Ord a => Prioritized (TaskHandle a) | |
| Prioritized (TaskHandle p a) | Change the priority of a task. This will not work if the task has already started. |
reprioritize :: TaskHandle p a -> (p -> p) -> IO ()Source
data Constrained u Source
Require that all RoomConstraints be satisfied when acquiring a Room.
Constructors
| Constrained |
Instances
| RoomConstraint u => ClaimContext (Constrained u) | |
| RoomGroup (Constrained u) |
data Unconstrained u Source
Don't check any RoomConstraints when acquiring a Room.
Constructors
| Unconstrained |
Instances
newtype MaxThreads Source
A maximum limit on the number of threads allowed to claim a room.
Constructors
| MaxThreads Int |
Instances
A resource pool, parameterized against arbitrary user data.
A convenience class to observe the currently running occupants of a Room or TaskPool.
data Ord a => QueueConfigurationRecord a Source
Configuration options for a Queue. A Queue blocks on a number of predicates when dispatching a job. Generally, fair_queue_configuration
should work well.
- A single STM predicate for the entire
Queue. This blocks the entireQueueuntil the predicate is satisfied. - A STM predicate parameterized by priority. This blocks a single priority level, and the
Queuewill skip all tasks at that priority. - Each task is itself an STM transaction, and can block itself.
- Pure constraints on priority and ordering inversion.
If a task is blocked for any reason, the task is skipped and the next task attempted, in priority order.
Constructors
| QueueConfigurationRecord | |
Fields
| |
fair_queue_configuration :: Ord a => QueueConfigurationRecord aSource
A queue tuned for high throughput and fairness when processing moderate to long running tasks.
fast_queue_configuration :: Ord a => QueueConfigurationRecord aSource
A queue tuned for high responsiveness and low priority inversion, but may have poorer long-term throughput and potential to starve some tasks compared to fair_queue_configuration.
data QueueOrder Source
schedule :: TaskPool p u -> p -> Schedule p (Constrained (TaskPoolConstraint u), Room (TaskPoolConstraint u))Source
A prioritized ClaimContext for a task pool.
newTaskPool :: Ord p => QueueConfigurationRecord p -> Int -> u -> IO (TaskPool p u)Source
Create a new TaskPool. TaskPools begin stopped, use startQueue to start.
- A
QueueConfigurationRecordfor the backingQueue. A typical value isfair_queue_configuration. - The allowed number of threads that can access the
TaskPoolsimultaneously. - The user data for the backing
Room. This can be().
Consider using simpleTaskPool if you have no special needs.
simpleTaskPool :: Ord p => IO (TaskPool p ())Source
Just create a new TaskPool. The task pool is constrained by the number of capabilities indicated by numCapabilities.
startQueue :: TaskPool p a -> IO ()Source