Scope
Active< RT > Class Template Reference

#include <Active.h>

Public Types

typedef std::function< RT(StopCondition *const sc)> Command
 

Public Member Functions

 Active ()
 
std::future< RT > Send (const Command &_cmd)
 
void AbortCurrent ()
 
void Quit ()
 

Protected Member Functions

 Active (const Active &)
 
void operator= (const Active &)
 

Protected Attributes

StopCondition stop
 
bool done
 
SynchronizedQueue< const std::function< void(StopCondition *const sc)> > ptq
 
std::thread thread
 

Detailed Description

template<class RT>
class Active< RT >

An active object implementation.

I got most of the stuff from Herb Sutters column in Dr. Dobbs: http://www.drdobbs.com/parallel/prefer-using-active-objects-instead-of-n/225700095 .
I did some pimping with packaged tasks and futures...

Definition at line 11 of file Active.h.

Member Typedef Documentation

template<class RT>
typedef std::function<RT(StopCondition* const sc)> Active< RT >::Command

Type of the worker function to be executed in Active's thread.

It should monitor the StopCondition and return an RT if the StopCondition is true.

Definition at line 16 of file Active.h.

Constructor & Destructor Documentation

template<class RT>
Active< RT >::Active ( const Active< RT > &  )
protected

disable copy

template<class RT>
Active< RT >::Active ( )
inline

The thread execution loop is created from a lambda.

Definition at line 42 of file Active.h.

Member Function Documentation

template<class RT>
void Active< RT >::operator= ( const Active< RT > &  )
protected

disable assignment

template<class RT>
std::future<RT> Active< RT >::Send ( const Command _cmd)
inline

Sends a worker function/packaged task to the queue to be executed in the Active's thread.

Parameters
[in]_cmdThe worker function/packaged task to be queued
Returns
the future for the return value of the worker function

Definition at line 59 of file Active.h.

template<class RT>
void Active< RT >::AbortCurrent ( )
inline

Aborts the currently executed worker function.

Definition at line 75 of file Active.h.

template<class RT>
void Active< RT >::Quit ( )
inline

Send lambda with done=true to the worker, join the worker thread, and clear the packaged task queue.

Definition at line 80 of file Active.h.

Member Data Documentation

template<class RT>
StopCondition Active< RT >::stop
protected

the abort signal

Definition at line 20 of file Active.h.

template<class RT>
bool Active< RT >::done
protected

this is set to quit the worker thread

Definition at line 23 of file Active.h.

template<class RT>
SynchronizedQueue<const std::function<void(StopCondition* const sc)> > Active< RT >::ptq
protected

synchronized queue of worker functions/packaged tasks that are executed in the Active' thread (see lambda in constructor).

Definition at line 26 of file Active.h.

template<class RT>
std::thread Active< RT >::thread
protected

a thread in which Run runs

Definition at line 29 of file Active.h.


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