Beatmup
Beatmup::ThreadPool::TaskThreadImpl Class Reference
Inheritance diagram for Beatmup::ThreadPool::TaskThreadImpl:
Beatmup::TaskThread

Public Member Functions

 TaskThreadImpl (ThreadIndex index, ThreadPool &pool)
 
virtual ~TaskThreadImpl ()
 
ThreadIndex numThreads () const
 
bool isTaskAborted () const
 Returns true if the task is asked to stop from outside. More...
 
void synchronize ()
 Blocks until all the other threads running the same task reach the same point. More...
 
- Public Member Functions inherited from Beatmup::TaskThread
ThreadIndex currentThread () const
 
bool isManaging () const
 

Public Attributes

ThreadPoolpool
 
ThreadIndex index
 current thread index More...
 
bool isRunning
 if not, the thread sleeps More...
 
bool isTerminating
 if true, the thread is requested to terminate More...
 
std::thread internalThread
 worker thread More...
 

Private Member Functions

void threadFunc ()
 

Additional Inherited Members

- Protected Member Functions inherited from Beatmup::TaskThread
 TaskThread (ThreadIndex index)
 
- Protected Attributes inherited from Beatmup::TaskThread
ThreadIndex index
 current thread index More...
 

Detailed Description

Definition at line 38 of file thread_pool.hpp.

Constructor & Destructor Documentation

◆ TaskThreadImpl()

Beatmup::ThreadPool::TaskThreadImpl::TaskThreadImpl ( ThreadIndex  index,
ThreadPool pool 
)
inline

Definition at line 45 of file thread_pool.hpp.

45  :
47  pool(pool), index(index), isRunning(false), isTerminating(false),
49  {}
TaskThread(const TaskThread &)=delete
bool isTerminating
if true, the thread is requested to terminate
Definition: thread_pool.hpp:69
bool isRunning
if not, the thread sleeps
Definition: thread_pool.hpp:68
ThreadIndex index
current thread index
Definition: thread_pool.hpp:67
std::thread internalThread
worker thread
Definition: thread_pool.hpp:70

◆ ~TaskThreadImpl()

virtual Beatmup::ThreadPool::TaskThreadImpl::~TaskThreadImpl ( )
inlinevirtual

Definition at line 51 of file thread_pool.hpp.

51 {}

Member Function Documentation

◆ threadFunc()

void Beatmup::ThreadPool::TaskThreadImpl::threadFunc ( )
inlineprivate

Definition at line 40 of file thread_pool.hpp.

40  {
41  index == 0 ? pool.managingThreadFunc(*this) : pool.workerThreadFunc(*this);
42  }
void managingThreadFunc(TaskThreadImpl &thread)
Managing (#0) worker thread function.
void workerThreadFunc(TaskThreadImpl &thread)
Ordinary worker thread function.

◆ numThreads()

ThreadIndex Beatmup::ThreadPool::TaskThreadImpl::numThreads ( ) const
inlinevirtual
Returns
overall number of threads working on the current task.

Implements Beatmup::TaskThread.

Definition at line 53 of file thread_pool.hpp.

53  {
54  return pool.currentWorkerCount;
55  }
ThreadIndex currentWorkerCount

◆ isTaskAborted()

bool Beatmup::ThreadPool::TaskThreadImpl::isTaskAborted ( ) const
inlinevirtual

Returns true if the task is asked to stop from outside.

Implements Beatmup::TaskThread.

Definition at line 57 of file thread_pool.hpp.

57  {
58  return pool.abortExternally;
59  }
bool abortExternally
if true, the task is aborted externally

◆ synchronize()

void Beatmup::ThreadPool::TaskThreadImpl::synchronize ( )
inlinevirtual

Blocks until all the other threads running the same task reach the same point.

"The same point" is the same number of calls to synchronize(). This function does not throw any exception to be caught in the task code. However, if a thread running the task has failed, this function throws an exception the thread pool takes care of. This ensures a valid thread pool state and avoids dead locks when a task fails to proceed.

Implements Beatmup::TaskThread.

Definition at line 61 of file thread_pool.hpp.

61  {
62  if (numThreads() > 1)
63  pool.synchronizeThread(*this);
64  }
void synchronizeThread(TaskThreadImpl &thread)

Member Data Documentation

◆ pool

ThreadPool& Beatmup::ThreadPool::TaskThreadImpl::pool

Definition at line 66 of file thread_pool.hpp.

◆ index

ThreadIndex Beatmup::ThreadPool::TaskThreadImpl::index

current thread index

Definition at line 67 of file thread_pool.hpp.

◆ isRunning

bool Beatmup::ThreadPool::TaskThreadImpl::isRunning

if not, the thread sleeps

Definition at line 68 of file thread_pool.hpp.

◆ isTerminating

bool Beatmup::ThreadPool::TaskThreadImpl::isTerminating

if true, the thread is requested to terminate

Definition at line 69 of file thread_pool.hpp.

◆ internalThread

std::thread Beatmup::ThreadPool::TaskThreadImpl::internalThread

worker thread

Definition at line 70 of file thread_pool.hpp.


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