Class CTaskScheduler#

Nested Relationships#

Nested Types#

Class Documentation#

class CTaskScheduler#

Job scheduler that uses a dynamic threadpool to schedule the task.

Public Types

enum class EScheduleFlags#

Schedule flags to influence the scheduling.

Values:

enumerator normal#

If thread level threshold has been reached, queue the call at the end of the queue.

enumerator priority#

If thread level threshold has been reached, insert the call at the begin of the queue.

enumerator no_queue#

If thread level threshold has been reached, fail the schedule call.

Public Functions

CTaskScheduler(size_t nMinIdle = 4, size_t nMaxBusy = 32)#

Constructor.

Parameters:
  • nMinIdle[in] The amount of idle threads that should stay present if there is nothing to process at the moment.

  • nMaxBusy[in] The maximum amount of threads that is used for processing.

~CTaskScheduler()#

Destructor.

bool Schedule(std::function<void()> fnTask, hlpr::flags<EScheduleFlags> flags = EScheduleFlags::normal)#

Schedule the asynchronous execution of the task.

If an idle thread is available, the thread will execute the task. If no thread is available and the maximum thread level hasn’t been reached, a new thread will be started that schedules the task. If the maximum thread level has been exceeded the task will be placed in the task list based on its priority and allowance. If queue is not allowed (set by the no_queue flag), the scheduling will fail.

Parameters:
  • fnTask[in] The task to schedule.

  • flags[in] Zero or more flags to use for scheduling the task.

Returns:

Returns whether the scheduling was successful or not.

void WaitForExecution()#

Wait until the execution of all threads has been finalized. This will also remove all idle threads.

Attention

Do not call from a task function - that will cause a deadlock.

size_t GetThreadCount() const#

Get the current amount of threads (idle + processing).

Returns:

The amount of threads.

size_t GetMaxThreadCount() const#

Get the maximum amount of threads that were processing at one time.

Returns:

The amount of threads.

size_t GetBusyThreadCount() const#

Get the current amount of processing threads.

Returns:

The amount of threads.

size_t GetIdleThreadCount() const#

Get the current amount of idle threads.

Returns:

The amount of threads.