libhatchet
Loading...
Searching...
No Matches
hxtask_queue Class Reference

#include <hxtask_queue.hpp>

Classes

class  record_t

Public Member Functions

 hxtask_queue (int32_t task_queue_size_, int32_t thread_pool_size_) noexcept
 ~hxtask_queue (void)
template<typename callable_t_>
bool all_of (callable_t_ &&callable_) const noexcept
template<typename callable_t_>
bool any_of (callable_t_ &&callable_) const noexcept
bool cancel (hxtask *task_) noexcept
void clear (void) noexcept
bool empty (void) const
void enqueue (hxtask *task_, int priority_=0) noexcept
template<typename callable_t_>
hxsize_t erase_if (callable_t_ &&callable_) noexcept
template<typename callable_t_>
void for_each (callable_t_ &&callable_) const noexcept
template<typename callable_t_>
void for_each (callable_t_ &&callable_) noexcept
bool full (void) const
hxsize_t max_size (void) const
hxsize_t size (void) const
void wait_for_all (void) noexcept

Detailed Description

hxtask_queue - Provides a priority queue of tasks and a worker thread pool.

Implements single-threaded task queuing when HX_USE_THREADS=0. For DAG dependency tracking see <hx/hxtask_dag_node.hpp>.

Constructor & Destructor Documentation

◆ hxtask_queue()

hxtask_queue::hxtask_queue ( int32_t task_queue_size_,
int32_t thread_pool_size_ )
explicitnoexcept

Creates a new task queue.

task_queue_size reserves storage for enqueued tasks. thread_pool_size determines the size of the worker thread pool. A thread_pool_size of 0 does not use threads.

◆ ~hxtask_queue()

hxtask_queue::~hxtask_queue ( void )

Waits for all queued and executing tasks to complete before destruction.

Member Function Documentation

◆ all_of()

template<typename callable_t_>
bool hxtask_queue::all_of ( callable_t_ && callable_) const
noexcept

Locks the queue and calls callable on each task.

Returns true if the predicate returns true for every element and false otherwise. Will stop iterating when the predicate returns false. Use for_each to modify priorities.

  • callable : A callable returning boolean. !all_of(x) -> any_not(x).

◆ any_of()

template<typename callable_t_>
bool hxtask_queue::any_of ( callable_t_ && callable_) const
noexcept

Locks the queue and calls callable on each task.

Returns true if the predicate returns true for any element and false otherwise. Will stop iterating when the predicate returns true. Use for_each to modify priorities.

  • callable : A callable returning boolean. !any_of(x) -> none_of(x).

◆ cancel()

bool hxtask_queue::cancel ( hxtask * task_)
noexcept

Returns true if the task was found and removed.

Calls on_cancel on the task if found. Thread-safe. Returns false if the task is already executing or was not queued.

  • task : Non-null pointer to the task to cancel.

◆ clear()

void hxtask_queue::clear ( void )
noexcept

Removes all queued tasks without executing them.

Does not call on_cancel on each. Does not affect tasks that are already executing. Subtasks enqueued by executing tasks after a call to clear will remain in the queue.

◆ empty()

bool hxtask_queue::empty ( void ) const

Returns true when no tasks are queued. Thread-safe.

◆ enqueue()

void hxtask_queue::enqueue ( hxtask * task_,
int priority_ = 0 )
noexcept

Queues a task for later execution.

Does not delete the task after execution. Thread-safe only when HX_USE_THREADS is enabled and the thread pool size is greater than zero.

  • task : Non-null pointer to the task to be enqueued for execution.
  • priority : Optional priority for scheduling. Higher values run sooner.

◆ erase_if()

template<typename callable_t_>
hxsize_t hxtask_queue::erase_if ( callable_t_ && callable_)
noexcept

Locks the queue and calls callable on each task.

Removes queued tasks for which callable evaluates true. Does not call on_cancel on each. Returns the number of records removed. The record_t& passed to erase_if may be modified and the tasks will be re-prioritized according to their new priorities.

  • callable : Predicate accepting a record_t&.

◆ for_each() [1/2]

template<typename callable_t_>
void hxtask_queue::for_each ( callable_t_ && callable_) const
noexcept

Locks the queue and calls callable on each task record.

  • callable : callable accepting a const record_t&.

◆ for_each() [2/2]

template<typename callable_t_>
void hxtask_queue::for_each ( callable_t_ && callable_)
noexcept

Non-const version of for_each.

This version will perform make_heap on the queue after calling callable on each task record. The record_t& passed to for_each may be modified and the tasks will be re-prioritized according to their new priorities.

◆ full()

bool hxtask_queue::full ( void ) const

Returns true if the queue capacity has been reached.

◆ max_size()

hxsize_t hxtask_queue::max_size ( void ) const

Returns the maximum number of tasks that can be queued.

This value is fixed at construction and does not require locking.

◆ size()

hxsize_t hxtask_queue::size ( void ) const

Returns the number of queued tasks. Thread-safe.

◆ wait_for_all()

void hxtask_queue::wait_for_all ( void )
noexcept

Execute remaining tasks.

The thread calling wait_for_all executes tasks as well. Intended to be called by the thread that owns the queue and must not be called from hxtask::execute. Tasks may safely call enqueue during execute to schedule additional work before wait_for_all returns. WARNING: Calling wait_for_all from inside hxtask::execute deadlocks permanently.


The documentation for this class was generated from the following file: