MarlinMT  0.1.0
marlinmt::concurrency::Worker< IN, OUT > Class Template Reference

Worker class. More...

#include <ThreadPool.h>

Public Types

using Input = IN
 
using Output = OUT
 
using Pool = ThreadPool< IN, OUT >
 
using Impl = WorkerBase< IN, OUT >
 

Public Member Functions

 Worker ()=delete
 
 Worker (const Worker &)=delete
 
 Worker (Worker &&)=delete
 
Workeroperator= (const Worker &)=delete
 
Workeroperator= (Worker &&)=delete
 
template<typename IMPL , class = typename std::enable_if<std::is_base_of<Impl,IMPL>::value>::type>
 Worker (Pool &pool, std::unique_ptr< IMPL > impl)
 Constructor. More...
 
void start ()
 Start the worker thread. More...
 
void run ()
 The method executing in the worker thread. More...
 
void stop ()
 Switch ON the stop flag, requesting the worker thread to stop. More...
 
bool running () const
 Whether the worker thread is currently running. More...
 
bool waiting () const
 Whether the worker is waiting. More...
 
void join ()
 Join the worker thread. More...
 

Private Attributes

Pool_threadPool
 < The parent thread pool More...
 
std::thread _thread {}
 The stop flag. More...
 
std::atomic< bool > _stopFlag {false}
 Whether the worker thread is waiting for data. More...
 
std::atomic< bool > _waitingFlag {false}
 The worker implementation. More...
 
std::unique_ptr< Impl_impl {nullptr}
 

Detailed Description

template<typename IN, typename OUT>
class marlinmt::concurrency::Worker< IN, OUT >

Worker class.

Definition at line 25 of file ThreadPool.h.

Member Typedef Documentation

◆ Impl

template<typename IN , typename OUT >
using marlinmt::concurrency::Worker< IN, OUT >::Impl = WorkerBase<IN,OUT>

Definition at line 135 of file Worker.h.

◆ Input

template<typename IN , typename OUT >
using marlinmt::concurrency::Worker< IN, OUT >::Input = IN

Definition at line 132 of file Worker.h.

◆ Output

template<typename IN , typename OUT >
using marlinmt::concurrency::Worker< IN, OUT >::Output = OUT

Definition at line 133 of file Worker.h.

◆ Pool

template<typename IN , typename OUT >
using marlinmt::concurrency::Worker< IN, OUT >::Pool = ThreadPool<IN, OUT>

Definition at line 134 of file Worker.h.

Constructor & Destructor Documentation

◆ Worker() [1/4]

template<typename IN , typename OUT >
marlinmt::concurrency::Worker< IN, OUT >::Worker ( )
delete

◆ Worker() [2/4]

template<typename IN , typename OUT >
marlinmt::concurrency::Worker< IN, OUT >::Worker ( const Worker< IN, OUT > &  )
delete

◆ Worker() [3/4]

template<typename IN , typename OUT >
marlinmt::concurrency::Worker< IN, OUT >::Worker ( Worker< IN, OUT > &&  )
delete

◆ Worker() [4/4]

template<typename IN , typename OUT >
template<typename IMPL , class >
marlinmt::concurrency::Worker< IN, OUT >::Worker ( Pool pool,
std::unique_ptr< IMPL >  impl 
)
inline

Constructor.

Parameters
poolthe parent thread pool
implthe worker implementation consuming IN data, producing OUT data

Definition at line 210 of file Worker.h.

Member Function Documentation

◆ join()

template<typename IN , typename OUT >
void marlinmt::concurrency::Worker< IN, OUT >::join ( )
inline

Join the worker thread.

Definition at line 278 of file Worker.h.

References marlinmt::concurrency::Worker< IN, OUT >::_thread.

◆ operator=() [1/2]

template<typename IN , typename OUT >
Worker& marlinmt::concurrency::Worker< IN, OUT >::operator= ( const Worker< IN, OUT > &  )
delete

◆ operator=() [2/2]

template<typename IN , typename OUT >
Worker& marlinmt::concurrency::Worker< IN, OUT >::operator= ( Worker< IN, OUT > &&  )
delete

◆ run()

◆ running()

template<typename IN , typename OUT >
bool marlinmt::concurrency::Worker< IN, OUT >::running ( ) const
inline

Whether the worker thread is currently running.

Definition at line 264 of file Worker.h.

References marlinmt::concurrency::Worker< IN, OUT >::_thread.

◆ start()

template<typename IN , typename OUT >
void marlinmt::concurrency::Worker< IN, OUT >::start ( )
inline

Start the worker thread.

Definition at line 219 of file Worker.h.

References marlinmt::concurrency::Worker< IN, OUT >::_thread, and marlinmt::concurrency::Worker< IN, OUT >::run().

◆ stop()

template<typename IN , typename OUT >
void marlinmt::concurrency::Worker< IN, OUT >::stop ( )
inline

Switch ON the stop flag, requesting the worker thread to stop.

No join operation is done here. See join() method

Definition at line 257 of file Worker.h.

References marlinmt::concurrency::Worker< IN, OUT >::_stopFlag.

◆ waiting()

template<typename IN , typename OUT >
bool marlinmt::concurrency::Worker< IN, OUT >::waiting ( ) const
inline

Whether the worker is waiting.

Definition at line 271 of file Worker.h.

References marlinmt::concurrency::Worker< IN, OUT >::_waitingFlag.

Member Data Documentation

◆ _impl

template<typename IN , typename OUT >
std::unique_ptr<Impl> marlinmt::concurrency::Worker< IN, OUT >::_impl {nullptr}
private

Definition at line 194 of file Worker.h.

Referenced by marlinmt::concurrency::Worker< IN, OUT >::run().

◆ _stopFlag

template<typename IN , typename OUT >
std::atomic<bool> marlinmt::concurrency::Worker< IN, OUT >::_stopFlag {false}
private

Whether the worker thread is waiting for data.

Definition at line 190 of file Worker.h.

Referenced by marlinmt::concurrency::Worker< IN, OUT >::run(), and marlinmt::concurrency::Worker< IN, OUT >::stop().

◆ _thread

template<typename IN , typename OUT >
std::thread marlinmt::concurrency::Worker< IN, OUT >::_thread {}
private

◆ _threadPool

template<typename IN , typename OUT >
Pool& marlinmt::concurrency::Worker< IN, OUT >::_threadPool
private

< The parent thread pool

The worker thread

Definition at line 186 of file Worker.h.

Referenced by marlinmt::concurrency::Worker< IN, OUT >::run().

◆ _waitingFlag

template<typename IN , typename OUT >
std::atomic<bool> marlinmt::concurrency::Worker< IN, OUT >::_waitingFlag {false}
private

The worker implementation.

Definition at line 192 of file Worker.h.

Referenced by marlinmt::concurrency::Worker< IN, OUT >::run(), and marlinmt::concurrency::Worker< IN, OUT >::waiting().


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