CyberEngineMkIII
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
CYB::API::ThreadableTaskset Class Referenceabstract

A mutlithreading interface with a number of jobs in mind. More...

#include <ThreadableTaskset.hpp>

Inheritance diagram for CYB::API::ThreadableTaskset:
Inheritance graph
[legend]
Collaboration diagram for CYB::API::ThreadableTaskset:
Collaboration graph
[legend]

Public Member Functions

void BeginThreadedOperation (void) finaloverride
 Called at the start of a threading operation in a new thread by the internal thread manager. Will call DoTask in the order of 0-(FNumTasks - 1) provided an error does not occur in doing so. On termination the cancel flag will be cleared. More...
 
void CancelThreadedOperation (void) noexceptfinaloverride
 Called by the internal thread manager to request cancellation of a thread. May also be called by the unit. When called no further tasks will be run after the current one completes. More...
 
virtual bool DoTask (const unsigned int ATask)=0
 Called by BeginThreadedOperation FNumTasks times with an incrementing ATask value. Each time it is called task number ATask should be run. More...
 

Protected Member Functions

 ThreadableTaskset (const unsigned int ANumTasks) noexcept
 Construct a ThreadableTaskset. More...
 

Private Attributes

const unsigned int FNumTasks
 The total number of tasks to perform.
 
std::atomic_bool FCancelFlag
 The cancellation flag.
 

Detailed Description

A mutlithreading interface with a number of jobs in mind.

Definition at line 7 of file ThreadableTaskset.hpp.

Constructor & Destructor Documentation

CYB::API::ThreadableTaskset::ThreadableTaskset ( const unsigned int  ANumTasks)
protectednoexcept

Construct a ThreadableTaskset.

Parameters
ANumTasksThe number of tasks to run on this taskset
Thread Safety
This function requires no thread safety

Member Function Documentation

void CYB::API::ThreadableTaskset::BeginThreadedOperation ( void  )
finaloverridevirtual

Called at the start of a threading operation in a new thread by the internal thread manager. Will call DoTask in the order of 0-(FNumTasks - 1) provided an error does not occur in doing so. On termination the cancel flag will be cleared.

Calling Thread
This function will be called by the engine in what should be considered a new thread, however it may be running in the ThreadPool depending on the calling context
Attention
Throwing an exception to this function will cause all remaining tasks to not be run and have the exception propagate to the internal thread manager where they will be logged at the DEV level and then ignored

Implements CYB::API::Threadable.

void CYB::API::ThreadableTaskset::CancelThreadedOperation ( void  )
finaloverridevirtualnoexcept

Called by the internal thread manager to request cancellation of a thread. May also be called by the unit. When called no further tasks will be run after the current one completes.

Calling Thread
This function may be called by the engine in any thread at any time during the object's lifetime

Implements CYB::API::Threadable.

virtual bool CYB::API::ThreadableTaskset::DoTask ( const unsigned int  ATask)
pure virtual

Called by BeginThreadedOperation FNumTasks times with an incrementing ATask value. Each time it is called task number ATask should be run.

Parameters
ATaskThe task number to run
Returns
true to continue task execution, false otherwise
Calling Thread
The function will in the thread that the object's BeginThreadedOperation runs on

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