Queue of immediate and delayed tasks executed by worker threads.
More...
#include <src/task_pool.h>
|
|
typedef std::unique_ptr< _ImplBase > | __task |
| | Type-erased task owned by the task pool.
|
| |
|
typedef std::chrono::steady_clock::time_point | __time_point |
| | Steady-clock timestamp used to schedule delayed tasks.
|
| |
|
typedef _ImplBase * | task_id_t |
| | Stable pointer used to identify a queued task.
|
| |
|
| bool | cancel (task_id_t task_id) |
| | Cancel a queued or delayed task before it runs.
|
| |
| template<class X , class Y > |
| void | delay (task_id_t task_id, std::chrono::duration< X, Y > duration) |
| |
| std::optional< __time_point > | next () |
| | Return the next timer task ready for execution.
|
| |
| TaskPool & | operator= (TaskPool &&other) noexcept |
| | Assign state from another instance while preserving ownership semantics.
|
| |
| std::optional< __task > | pop () |
| | Remove and return the next queued item, waiting when requested.
|
| |
| std::optional< std::pair< __time_point, __task > > | pop (task_id_t task_id) |
| | Remove and return the next queued item, waiting when requested.
|
| |
| template<class Function , class... Args> |
| auto | push (Function &&newTask, Args &&...args) |
| | Queue work for asynchronous execution.
|
| |
| template<class Function , class X , class Y , class... Args> |
| auto | pushDelayed (Function &&newTask, std::chrono::duration< X, Y > duration, Args &&...args) |
| |
| void | pushDelayed (std::pair< __time_point, __task > &&task) |
| | Queue a task that becomes runnable after a delay.
|
| |
| bool | ready () |
| | Check whether the task pool has active workers.
|
| |
| | TaskPool (TaskPool &&other) noexcept |
| | Move queued tasks and timers from another task pool.
|
| |
|
|
std::mutex | _task_mutex |
| | Mutex protecting task queues and worker wakeups.
|
| |
|
std::deque< __task > | _tasks |
| | Immediate tasks waiting for worker execution.
|
| |
|
std::vector< std::pair< __time_point, __task > > | _timer_tasks |
| | Delayed tasks sorted by their due time.
|
| |
Queue of immediate and delayed tasks executed by worker threads.
◆ TaskPool()
| task_pool_util::TaskPool::TaskPool |
( |
TaskPool && | other | ) |
|
|
inlinenoexcept |
Move queued tasks and timers from another task pool.
- Parameters
-
| other | Pool whose queues and worker state are moved into this pool. |
◆ cancel()
| bool task_pool_util::TaskPool::cancel |
( |
task_id_t | task_id | ) |
|
|
inline |
Cancel a queued or delayed task before it runs.
- Parameters
-
| task_id | Identifier returned when the task was queued. |
- Returns
- True when the task was found and cancelled.
◆ delay()
template<class X , class Y >
| void task_pool_util::TaskPool::delay |
( |
task_id_t | task_id, |
|
|
std::chrono::duration< X, Y > | duration ) |
|
inline |
- Parameters
-
| task_id | The id of the task to delay. |
| duration | The delay before executing the task. |
◆ next()
| std::optional< __time_point > task_pool_util::TaskPool::next |
( |
| ) |
|
|
inline |
Return the next timer task ready for execution.
- Returns
- Time point for the next queued timer task, or std::nullopt when none exist.
◆ operator=()
Assign state from another instance while preserving ownership semantics.
- Parameters
-
| other | Source object whose state is copied or moved into this object. |
- Returns
- Reference or value produced by the operator.
◆ pop() [1/2]
| std::optional< __task > task_pool_util::TaskPool::pop |
( |
| ) |
|
|
inline |
Remove and return the next queued item, waiting when requested.
- Returns
- Removed queue item, or empty result when the queue is stopped or empty.
◆ pop() [2/2]
Remove and return the next queued item, waiting when requested.
- Parameters
-
| task_id | Identifier returned when the task was queued. |
- Returns
- Removed queue item, or empty result when the queue is stopped or empty.
◆ push()
template<class Function , class... Args>
| auto task_pool_util::TaskPool::push |
( |
Function && | newTask, |
|
|
Args &&... | args ) |
|
inline |
Queue work for asynchronous execution.
- Parameters
-
| newTask | New task. |
| args | Arguments forwarded to the callable or parser. |
- Returns
- Identifier assigned to the queued task.
◆ pushDelayed() [1/2]
template<class Function , class X , class Y , class... Args>
| auto task_pool_util::TaskPool::pushDelayed |
( |
Function && | newTask, |
|
|
std::chrono::duration< X, Y > | duration, |
|
|
Args &&... | args ) |
|
inline |
- Returns
- An id to potentially delay the task.
- Parameters
-
| newTask | New task. |
| duration | Delay before the timed task should run. |
| args | Arguments forwarded to the callable or parser. |
◆ pushDelayed() [2/2]
Queue a task that becomes runnable after a delay.
- Parameters
-
| task | Task object to enqueue or execute. |
◆ ready()
| bool task_pool_util::TaskPool::ready |
( |
| ) |
|
|
inline |
Check whether the task pool has active workers.
- Returns
- True when the task was found and cancelled.
The documentation for this class was generated from the following file: