Beatmup
|
A pool of threads running tasks ThreadPool runs AbstractTasks, possibly in multiple threads. More...
#include <thread_pool.hpp>
Classes | |
class | AnotherThreadFailed |
class | EventListener |
Event listener class. More... | |
struct | JobContext |
class | TaskThreadImpl |
Public Types | |
enum class | TaskExecutionMode { NORMAL , PERSISTENT } |
Way how to the task should be run in the pool. More... | |
Public Member Functions | |
ThreadPool (const PoolIndex index, const ThreadIndex limitThreadCount, EventListener &listener) | |
~ThreadPool () | |
void | check () |
Checks if the thread pool is doing great. More... | |
void | resize (ThreadIndex newThreadCount) |
Resizes the pool. More... | |
Job | submitTask (AbstractTask &task, const TaskExecutionMode mode) |
Adds a new task to the jobs queue. More... | |
Job | repeatTask (AbstractTask &task, bool abortCurrent) |
Ensures a given task executed at least once. More... | |
void | waitForJob (Job job) |
Blocks until a given job finishes if not yet. More... | |
bool | abortJob (Job job) |
Aborts a given submitted job. More... | |
void | wait () |
Blocks until all the submitted jobs are executed. More... | |
bool | busy () |
Checks whether the pool has jobs. More... | |
bool | isGpuQueried () const |
bool | isGpuReady () const |
bool | isManagingThread () const |
ThreadIndex | getThreadCount () const |
Static Public Member Functions | |
static ThreadIndex | hardwareConcurrency () |
Returns optimal number of threads depending on the hardware capabilities. More... | |
Public Attributes | |
const PoolIndex | myIndex |
the index of the current pool More... | |
Private Member Functions | |
ThreadPool (const ThreadPool &)=delete | |
void | managingThreadFunc (TaskThreadImpl &thread) |
Managing (#0) worker thread function. More... | |
void | workerThreadFunc (TaskThreadImpl &thread) |
Ordinary worker thread function. More... | |
void | synchronizeThread (TaskThreadImpl &thread) |
Private Attributes | |
TaskThreadImpl ** | workers |
workers instances More... | |
GraphicPipeline * | gpu |
THE graphic pipeline to run tasks on GPU. More... | |
std::deque< JobContext > | jobs |
jobs queue More... | |
std::deque< std::exception_ptr > | exceptions |
exceptions thrown in this pool More... | |
JobContext | currentJob |
job being run at the moment More... | |
Job | jobCounter |
ThreadIndex | threadCount |
actual number of workers More... | |
ThreadIndex | currentWorkerCount |
ThreadIndex | remainingWorkers |
number of workers performing the current task right now More... | |
std::condition_variable | synchroCvar |
gets notified about workers synchronization More... | |
std::condition_variable | jobsCvar |
gets notified about the jobs queue updates More... | |
std::condition_variable | workersCvar |
gets notified about workers lifecycle updates More... | |
std::mutex | synchro |
workers synchronization control within the current task More... | |
std::mutex | workersAccess |
workers lifecycle access control More... | |
std::mutex | jobsAccess |
jobs queue access control More... | |
std::mutex | exceptionsAccess |
exceptions queue access control More... | |
int | syncHitsCount |
number of times synchronization is hit so far by all workers together More... | |
int | syncHitsBound |
last sync hits count when all the workers were synchronized More... | |
bool | isGpuTested |
if true , there was an attempt to warm up the GPU More... | |
bool | abortExternally |
if true , the task is aborted externally More... | |
bool | abortInternally |
if true , the task aborts itself: beforeProcessing(), process() or processOnGPU() returned false More... | |
bool | failFlag |
communicates to all the threads that the current task is to skip because of a problem More... | |
bool | repeatFlag |
if true , the current task is asked to be repeated More... | |
EventListener & | eventListener |
A pool of threads running tasks ThreadPool runs AbstractTasks, possibly in multiple threads.
Every time a task is submitted to the thread pool, it is scheduled for execution and gets attributed a corresponding Job number. Jobs are used to cancel the scheduled runs and track whether they have been conducted or not. Exceptions thrown during the tasks execution in different threads are rethrown in the caller threads.
Definition at line 36 of file thread_pool.hpp.
|
strong |
Way how to the task should be run in the pool.
Enumerator | |
---|---|
NORMAL | normal task, should be run it once |
PERSISTENT | persistent task, run process() until it returns |
Definition at line 78 of file thread_pool.hpp.
|
privatedelete |
|
inline |
Definition at line 454 of file thread_pool.hpp.
|
inline |
Definition at line 474 of file thread_pool.hpp.
|
inlineprivate |
Managing (#0) worker thread function.
Definition at line 141 of file thread_pool.hpp.
|
inlineprivate |
Ordinary worker thread function.
Definition at line 317 of file thread_pool.hpp.
|
inlineprivate |
Definition at line 377 of file thread_pool.hpp.
|
inline |
Checks if the thread pool is doing great.
If not, i.e., if there was an exception, rethrows the exception. There might be multiple exceptions in the queue. They are thrown one by one every time this function is called.
Definition at line 499 of file thread_pool.hpp.
|
inline |
Resizes the pool.
Blocking if there is a task running.
newThreadCount | The new number of worker threads |
Definition at line 514 of file thread_pool.hpp.
|
inline |
|
inline |
Ensures a given task executed at least once.
task | The task |
abortCurrent | if true and the task is currently running, abort signal is sent. |
Definition at line 579 of file thread_pool.hpp.
|
inline |
Blocks until a given job finishes if not yet.
Definition at line 614 of file thread_pool.hpp.
|
inline |
Aborts a given submitted job.
true
if the job was interrupted while running. Definition at line 648 of file thread_pool.hpp.
|
inline |
|
inline |
Checks whether the pool has jobs.
Definition at line 682 of file thread_pool.hpp.
|
inlinestatic |
Returns optimal number of threads depending on the hardware capabilities.
Definition at line 691 of file thread_pool.hpp.
|
inline |
true
if GPU was queried. Definition at line 701 of file thread_pool.hpp.
|
inline |
true
if GPU is ready to use. Definition at line 709 of file thread_pool.hpp.
|
inline |
|
inline |
Definition at line 722 of file thread_pool.hpp.
|
private |
workers instances
Definition at line 410 of file thread_pool.hpp.
|
private |
THE graphic pipeline to run tasks on GPU.
Definition at line 412 of file thread_pool.hpp.
|
private |
jobs queue
Definition at line 414 of file thread_pool.hpp.
|
private |
exceptions thrown in this pool
Definition at line 416 of file thread_pool.hpp.
|
private |
job being run at the moment
Definition at line 418 of file thread_pool.hpp.
|
private |
Definition at line 419 of file thread_pool.hpp.
|
private |
actual number of workers
Definition at line 421 of file thread_pool.hpp.
|
private |
Definition at line 424 of file thread_pool.hpp.
|
private |
number of workers performing the current task right now
Definition at line 425 of file thread_pool.hpp.
|
private |
gets notified about workers synchronization
Definition at line 428 of file thread_pool.hpp.
|
private |
gets notified about the jobs queue updates
Definition at line 429 of file thread_pool.hpp.
|
private |
gets notified about workers lifecycle updates
Definition at line 430 of file thread_pool.hpp.
|
private |
workers synchronization control within the current task
Definition at line 433 of file thread_pool.hpp.
|
private |
workers lifecycle access control
Definition at line 434 of file thread_pool.hpp.
|
private |
jobs queue access control
Definition at line 435 of file thread_pool.hpp.
|
private |
exceptions queue access control
Definition at line 436 of file thread_pool.hpp.
|
private |
number of times synchronization is hit so far by all workers together
Definition at line 439 of file thread_pool.hpp.
|
private |
last sync hits count when all the workers were synchronized
Definition at line 440 of file thread_pool.hpp.
|
private |
if true
, there was an attempt to warm up the GPU
Definition at line 443 of file thread_pool.hpp.
|
private |
if true
, the task is aborted externally
Definition at line 444 of file thread_pool.hpp.
|
private |
if true
, the task aborts itself: beforeProcessing(), process() or processOnGPU() returned false
Definition at line 445 of file thread_pool.hpp.
|
private |
communicates to all the threads that the current task is to skip because of a problem
Definition at line 446 of file thread_pool.hpp.
|
private |
if true
, the current task is asked to be repeated
Definition at line 447 of file thread_pool.hpp.
|
private |
Definition at line 449 of file thread_pool.hpp.
const PoolIndex Beatmup::ThreadPool::myIndex |
the index of the current pool
Definition at line 452 of file thread_pool.hpp.