ORIGINAL
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Attributes | List of all members
original::taskDelegator Class Reference

Thread pool for managing and executing prioritized tasks. More...

#include <tasks.h>

Collaboration diagram for original::taskDelegator:
Collaboration graph

Public Types

enum class  priority : u_integer {
  IMMEDIATE = 0 , HIGH = 1 , NORMAL = 2 , LOW = 3 ,
  DEFERRED = 4
}
 Task priority levels for execution scheduling. More...
 
enum class  stopMode { DISCARD_DEFERRED , KEEP_DEFERRED , RUN_DEFERRED }
 Stop behavior for deferred tasks. More...
 

Public Member Functions

 taskDelegator (const taskDelegator &)=delete
 Disable copy constructor.
 
taskDelegatoroperator= (const taskDelegator &)=delete
 Disable copy assignment.
 
 taskDelegator (taskDelegator &&)=delete
 Disable move constructor.
 
taskDelegatoroperator= (taskDelegator &&)=delete
 Disable move assignment.
 
 taskDelegator (u_integer thread_cnt=8)
 Constructs a task delegator with a given number of threads.
 
template<typename Callback , typename... Args>
auto submit (Callback &&c, Args &&... args)
 Submits a task with normal priority.
 
template<typename Callback , typename... Args>
auto submit (priority priority, Callback &&c, Args &&... args)
 Submits a task with specified priority.
 
template<typename Callback , typename... Args>
auto submit (time::duration timeout, Callback &&c, Args &&... args)
 Submits a task with IMMEDIATE priority and a timeout.
 
u_integer waitingCnt () const noexcept
 Returns the number of waiting (non-immediate, non-deferred) tasks.
 
u_integer immediateCnt () const noexcept
 Returns the number of immediate tasks pending execution.
 
void runDeferred ()
 Activates one deferred task.
 
void runAllDeferred ()
 Activates all deferred tasks.
 
u_integer discardDeferred ()
 Discards one deferred task.
 
void discardAllDeferred ()
 Discards all deferred tasks.
 
u_integer deferredCnt () const noexcept
 Returns number of deferred tasks.
 
void stop (stopMode mode=stopMode::KEEP_DEFERRED)
 Stops the task delegator.
 
u_integer activeThreads () const noexcept
 Gets the number of active threads.
 
u_integer idleThreads () const noexcept
 Gets the number of idle threads.
 
 ~taskDelegator ()
 Destructor.
 
template<typename TYPE >
original::async::future< TYPEsubmit (const priority priority, strongPtr< task< TYPE > > &t)
 

Static Public Attributes

static constexpr auto IMMEDIATE = priority::IMMEDIATE
 
static constexpr auto HIGH = priority::HIGH
 
static constexpr auto NORMAL = priority::NORMAL
 
static constexpr auto LOW = priority::LOW
 
static constexpr auto DEFERRED = priority::DEFERRED
 
static constexpr auto DISCARD_DEFERRED = stopMode::DISCARD_DEFERRED
 
static constexpr auto KEEP_DEFERRED = stopMode::KEEP_DEFERRED
 
static constexpr auto RUN_DEFERRED = stopMode::RUN_DEFERRED
 

Detailed Description

Thread pool for managing and executing prioritized tasks.

Provides a managed thread pool that can execute tasks with different priority levels. Supports immediate, high, normal, low, and deferred tasks. Deferred tasks can be manually activated or discarded on shutdown.

Member Enumeration Documentation

◆ priority

Task priority levels for execution scheduling.

Enumerator
IMMEDIATE 

Execute immediately if threads available.

HIGH 

High priority task.

NORMAL 

Normal priority task (default)

LOW 

Low priority task.

DEFERRED 

Deferred execution.

◆ stopMode

Stop behavior for deferred tasks.

Enumerator
DISCARD_DEFERRED 

Discard deferred tasks.

KEEP_DEFERRED 

Keep deferred tasks.

RUN_DEFERRED 

Execute all deferred tasks before stopping.

Constructor & Destructor Documentation

◆ taskDelegator()

original::taskDelegator::taskDelegator ( u_integer  thread_cnt = 8)
inlineexplicit

Constructs a task delegator with a given number of threads.

Parameters
thread_cntNumber of threads (default: 8)

◆ ~taskDelegator()

original::taskDelegator::~taskDelegator ( )
inline

Destructor.

Calls stop(RUN_DEFERRED) and joins all threads

Member Function Documentation

◆ activeThreads()

original::u_integer original::taskDelegator::activeThreads ( ) const
inlinenoexcept

Gets the number of active threads.

Returns
Count of currently active threads

◆ discardDeferred()

original::u_integer original::taskDelegator::discardDeferred ( )
inline

Discards one deferred task.

Returns
Remaining number of deferred tasks after discarding

◆ idleThreads()

original::u_integer original::taskDelegator::idleThreads ( ) const
inlinenoexcept

Gets the number of idle threads.

Returns
Count of currently idle threads

◆ stop()

void original::taskDelegator::stop ( stopMode  mode = stopMode::KEEP_DEFERRED)
inline

Stops the task delegator.

Parameters
modeStop mode (default: KEEP_DEFERRED)
  • DISCARD_DEFERRED: Discard all deferred tasks
  • KEEP_DEFERRED: Keep deferred tasks without executing them
  • RUN_DEFERRED: Activate all deferred tasks before stopping

◆ submit() [1/3]

template<typename Callback , typename ... Args>
auto original::taskDelegator::submit ( Callback &&  c,
Args &&...  args 
)

Submits a task with normal priority.

Template Parameters
CallbackType of the callable
ArgsTypes of the arguments
Parameters
cCallable to execute
argsArguments to forward to the callable
Returns
Future for the task result

◆ submit() [2/3]

template<typename Callback , typename ... Args>
auto original::taskDelegator::submit ( priority  priority,
Callback &&  c,
Args &&...  args 
)

Submits a task with specified priority.

Template Parameters
CallbackType of the callable
ArgsTypes of the arguments
Parameters
priorityTask priority level
cCallable to execute
argsArguments to forward to the callable
Returns
Future for the task result
Exceptions
sysErrorif delegator is stopped or no idle thread is available for IMMEDIATE submission

◆ submit() [3/3]

template<typename Callback , typename ... Args>
auto original::taskDelegator::submit ( time::duration  timeout,
Callback &&  c,
Args &&...  args 
)

Submits a task with IMMEDIATE priority and a timeout.

Template Parameters
CallbackType of the callable
ArgsTypes of the arguments
Parameters
timeoutMaximum duration to wait for an idle thread
cCallable to execute
argsArguments to forward to the callable
Returns
Future for the task result
Exceptions
sysErrorif delegator is stopped
sysErrorif no idle thread becomes available within the timeout
Note
Unlike normal submission, this will not throw immediately if no idle threads are available, but waits up to the given timeout.

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