OpenWalnut  1.5.0dev
Public Types | Public Member Functions | Protected Attributes | List of all members
WThreadedJobs< Input_T, Job_T > Class Template Referenceabstract

A threaded functor base class for producer-consumer-style multithreaded computation. More...

#include <WThreadedJobs.h>

+ Inheritance diagram for WThreadedJobs< Input_T, Job_T >:
+ Collaboration diagram for WThreadedJobs< Input_T, Job_T >:

Public Types

typedef Input_T InputType
 the input type More...
 
typedef Job_T JobType
 the job type More...
 

Public Member Functions

 WThreadedJobs (std::shared_ptr< InputType const > input)
 Constructor. More...
 
virtual ~WThreadedJobs ()
 Destructor. More...
 
void operator() (std::size_t id, std::size_t numThreads, WBoolFlag const &shutdown)
 The threaded function operation. More...
 
virtual bool getJob (JobType &job)=0
 Abstract function for the job aquisition. More...
 
virtual void compute (std::shared_ptr< InputType const > input, JobType const &job)=0
 Abstract function that performs the actual computation per job. More...
 

Protected Attributes

std::shared_ptr< InputType const > m_input
 the input More...
 

Detailed Description

template<class Input_T, class Job_T>
class WThreadedJobs< Input_T, Job_T >

A threaded functor base class for producer-consumer-style multithreaded computation.

A job generator function produces jobs that are then distributed to the threads in a first come first serve manner. The first template parameter is the type of the input data, for example a WDataSetScalar. The second template parameter is the type of object that represents the jobs.

Both the getJob() and the compute() functions need to be implemented.

Definition at line 50 of file WThreadedJobs.h.

Member Typedef Documentation

◆ InputType

template<class Input_T , class Job_T >
typedef Input_T WThreadedJobs< Input_T, Job_T >::InputType

the input type

Definition at line 54 of file WThreadedJobs.h.

◆ JobType

template<class Input_T , class Job_T >
typedef Job_T WThreadedJobs< Input_T, Job_T >::JobType

the job type

Definition at line 57 of file WThreadedJobs.h.

Constructor & Destructor Documentation

◆ WThreadedJobs()

template<class Input_T , class Job_T >
WThreadedJobs< Input_T, Job_T >::WThreadedJobs ( std::shared_ptr< InputType const >  input)

Constructor.

Parameters
inputThe input.

Definition at line 104 of file WThreadedJobs.h.

References WThreadedJobs< Input_T, Job_T >::m_input.

◆ ~WThreadedJobs()

template<class Input_T , class Job_T >
WThreadedJobs< Input_T, Job_T >::~WThreadedJobs
virtual

Destructor.

Definition at line 114 of file WThreadedJobs.h.

Member Function Documentation

◆ compute()

template<class Input_T , class Job_T >
virtual void WThreadedJobs< Input_T, Job_T >::compute ( std::shared_ptr< InputType const >  input,
JobType const &  job 
)
pure virtual

Abstract function that performs the actual computation per job.

Parameters
inputThe input data.
jobThe current job.

◆ getJob()

template<class Input_T , class Job_T >
virtual bool WThreadedJobs< Input_T, Job_T >::getJob ( JobType job)
pure virtual

Abstract function for the job aquisition.

Parameters
jobThe job (output).
Returns
false, iff no more jobs need to be processed.

◆ operator()()

template<class Input_T , class Job_T >
void WThreadedJobs< Input_T, Job_T >::operator() ( std::size_t  id,
std::size_t  numThreads,
WBoolFlag const &  shutdown 
)

The threaded function operation.

Pulls jobs and executes the

See also
compute() function.
Parameters
idThe thread's ID.
numThreadsHow many threads are working on the jobs.
shutdownA shared flag indicating the thread should be stopped.

Definition at line 119 of file WThreadedJobs.h.

Member Data Documentation

◆ m_input

template<class Input_T , class Job_T >
std::shared_ptr< InputType const > WThreadedJobs< Input_T, Job_T >::m_input
protected

the input

Definition at line 99 of file WThreadedJobs.h.

Referenced by WThreadedJobs< Input_T, Job_T >::WThreadedJobs().


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