NAP
Public Member Functions | List of all members
ThreadPool Class Referencefinal

#include </opt/build/repo/nap/utility/src/utility/threading.h>

Public Member Functions

 ThreadPool (int numberOfThreads=1, int maxQueueItems=20, bool realTimePriority=false)
 
 ~ThreadPool ()
 
void execute (TaskQueue::Task task)
 
void shutDown ()
 
void resize (int numberOfThreads)
 
int getThreadCount () const
 
int getTaskCount () const
 
bool isStopping () const
 

Description

A pool of threads that can be used to perform multiple tasks at the same time

Constructor & Destructor Documentation

◆ ThreadPool()

ThreadPool ( int  numberOfThreads = 1,
int  maxQueueItems = 20,
bool  realTimePriority = false 
)

◆ ~ThreadPool()

~ThreadPool ( )

Member Function Documentation

◆ execute()

void execute ( TaskQueue::Task  task)

Enqueues a task to be performed on the next idle thread.

◆ getTaskCount()

int getTaskCount ( ) const

Returns an estimate of the total number of tasks currently in the queue. This estimate is only accurate if the queue has completely stabilized before it is called (i.e. all enqueue and dequeue operations have completed and their memory effects are visible on the calling thread, and no further operations start while this method is being called). Thread-safe.

◆ getThreadCount()

int getThreadCount ( ) const

Returns the number of threads in the pool.

◆ isStopping()

bool isStopping ( ) const

Returns whether this thread is shutting down.

◆ resize()

void resize ( int  numberOfThreads)

Resizes the number of threads in the pool, joins and exits all existing threads first!

◆ shutDown()

void shutDown ( )

Sets stopping to true and joins and exits all threads in the pool.