EntityComponentMetaSystem
An implementation of an EntityComponent System with template meta-programming.
Loading...
Searching...
No Matches
Public Member Functions | List of all members
EC::ThreadPool< MAXSIZE > Class Template Reference

Implementation of a Thread Pool. More...

#include <ThreadPool.hpp>

Public Member Functions

void queueFn (std::function< void(void *)> &&fn, void *ud=nullptr)
 Queues a function to be called (doesn't start calling yet). More...
 
Internal::PointersT startThreads ()
 Creates MAXSIZE threads that will process queueFn() functions. More...
 
bool isQueueEmpty ()
 Returns true if the function queue is empty.
 
constexpr unsigned int getMaxThreadCount ()
 Returns the MAXSIZE count that this class was created with.
 
void easyStartAndWait ()
 Calls startThreads() and waits until all threads have finished. More...
 
bool isNotRunning ()
 Checks if any threads are currently running, returning true if there are no threads running.
 

Detailed Description

template<unsigned int MAXSIZE>
class EC::ThreadPool< MAXSIZE >

Implementation of a Thread Pool.

Note that MAXSIZE template parameter determines how many threads are created each time that startThreads() (or easyStartAndWait()) is called.

Member Function Documentation

◆ easyStartAndWait()

template<unsigned int MAXSIZE>
void EC::ThreadPool< MAXSIZE >::easyStartAndWait ( )
inline

Calls startThreads() and waits until all threads have finished.

Regardless of the value set to MAXSIZE, this function will block until all previously queued functions have been executed.

◆ queueFn()

template<unsigned int MAXSIZE>
void EC::ThreadPool< MAXSIZE >::queueFn ( std::function< void(void *)> &&  fn,
void *  ud = nullptr 
)
inline

Queues a function to be called (doesn't start calling yet).

To run the queued functions, startThreads() must be called to wake the waiting threads which will start pulling functions from the queue to be called.

Note that the easyStartAndWait() calls startThreads() and waits until the threads have finished execution.

◆ startThreads()

template<unsigned int MAXSIZE>
Internal::PointersT EC::ThreadPool< MAXSIZE >::startThreads ( )
inline

Creates MAXSIZE threads that will process queueFn() functions.

Note that if MAXSIZE < 2, then this function will synchronously execute the queued functions and block until the functions have been executed. Otherwise, this function may return before the queued functions have been executed.


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