Skip to content

Pool

class Pool

Pool tasks scheduler class.

The Pool tasks scheduler can pick and run pool tasks on several multiple threads. The number of threads is defined at initialization.

The maximum number of tasks the pool can manage is defined by the AM_MAX_THREAD_POOL_TASKS macro. The default value is 1024

Functions

Name Description
Pool Creates a new pool tasks scheduler instance.
~Pool Destructor.
Init Initializes and run thread pool.
AddTask Add a task to the tasks list.
GetWork Called from worker thread to get a new task.
GetThreadCount Gets the number of threads this pool is using.
IsRunning Indicates that the pool is running.
HasTasks Indicates that has tasks pending.
GetTaskCount Gets the number of tasks in the pool.

Function Details

AddTask

void AddTask(std::shared_ptr<PoolTask> task)

Add a task to the tasks list.

Parameter task
The PoolTask to add. The task is not automatically deleted when the work is done.

GetTaskCount

[[nodiscard]] AmInt32 GetTaskCount() const

Gets the number of tasks in the pool.

Return
The number of tasks in the pool.

GetThreadCount

[[nodiscard]] AmUInt32 GetThreadCount() const

Gets the number of threads this pool is using.

Return
The total number of threads in the pool.

GetWork

std::shared_ptr<PoolTask> GetWork()

Called from worker thread to get a new task.

Warning

This method is called internally, and should not be called in user code.

Return
The next PoolTask to execute, or nullptr if no task is available.

HasTasks

[[nodiscard]] bool HasTasks() const

Indicates that has tasks pending.

Return
true if there are tasks pending, false otherwise.

Init

void Init(AmUInt32 threadCount)

Initializes and run thread pool.

Parameter threadCount
The number of threads in the pool. For thread count 0, work is done at AddTask() call in the calling thread.

IsRunning

[[nodiscard]] bool IsRunning() const

Indicates that the pool is running.

Return
true if the pool is running, false otherwise.

Pool

Pool()

Creates a new pool tasks scheduler instance.

~Pool

~Pool()

Destructor.

It waits for the threads to finish. Work may be unfinished.