#include <synchro.h>
Inheritance diagram for rpa::future< Ftor, Thr >:
Public Member Functions | |
Ftor & | functor_ref (void) |
For reduction because the inner functor may have intermediate results. | |
~future () | |
future (Ftor &aFtor, Thr *ptrThr) | |
The constructor launches the sub-thread. | |
const result_type & | wait_end_const (void) |
result_type & | wait_end (void) |
This is used for reducing and the internal value may be changed. | |
Private Types | |
typedef Ftor::result_type | result_type |
Private Member Functions | |
future (const future &) | |
No default constructor, not copyable nor assignable. | |
future | operator= (const future &) |
void | sync_end (void) |
Static Private Member Functions | |
static void * | func (void *aThis) |
Private Attributes | |
char | _retRawBuf [sizeof(result_type)] |
Raw memory to store a return object, no need of default constructor. | |
Ftor * | _ptrFtor |
Not copy the functor to execute, nor the thread that will execute it. | |
Thr * | _ptrThr |
This value is used as a flag too. |
Waits until the thread is finished, and stores its result.
typedef Ftor::result_type rpa::future< Ftor, Thr >::result_type [private] |
Reimplemented in rpa::spawn< ThreadTree, Ftor >, and rpa::thread_stack< Ftor, Thr >::node.
rpa::future< Ftor, Thr >::future | ( | const future< Ftor, Thr > & | ) | [private] |
No default constructor, not copyable nor assignable.
rpa::future< Ftor, Thr >::~future | ( | ) | [inline] |
Here, the thread must absolutely be joined. As this object was created with a 'placement new', it has to be explicitely destroyed.
Maybe the program does not care about the result so did not wait for it.
Maybe the object was not constructed because an exception was thrown.
For performance , we may avoid this if the return type is a POD (Plain Old Data), which has no constructors.
rpa::future< Ftor, Thr >::future | ( | Ftor & | aFtor, | |
Thr * | ptrThr | |||
) | [inline] |
The constructor launches the sub-thread.
We MUST cross a memory barrier before launching the sub-threads : Because of '_ptrFtor' and '_ptrThr'. Throws an exception if the thread could not be started.
static void* rpa::future< Ftor, Thr >::func | ( | void * | aThis | ) | [inline, static, private] |
Called by a sub-thread. Executes the functor and stores its return value in our internal buffer. This returns NULL because nothing else is needed. It may be used in the future to trap exceptions.
Default ctor is unneeded because the result is stored in a raw memory chunk, which is initialised with a placement new.
Ftor& rpa::future< Ftor, Thr >::functor_ref | ( | void | ) | [inline] |
For reduction because the inner functor may have intermediate results.
future rpa::future< Ftor, Thr >::operator= | ( | const future< Ftor, Thr > & | ) | [private] |
void rpa::future< Ftor, Thr >::sync_end | ( | void | ) | [inline, private] |
result_type& rpa::future< Ftor, Thr >::wait_end | ( | void | ) | [inline] |
This is used for reducing and the internal value may be changed.
const result_type& rpa::future< Ftor, Thr >::wait_end_const | ( | void | ) | [inline] |
This sub-thread we are waiting for must have been created by the main thread, in which we are actually running. It makes no harm to call it several times, only the first call will do a real join of the thread.
Ftor* rpa::future< Ftor, Thr >::_ptrFtor [private] |
Not copy the functor to execute, nor the thread that will execute it.
Do not change this value because it is later used by the calling thread.
Thr* rpa::future< Ftor, Thr >::_ptrThr [private] |
This value is used as a flag too.
char rpa::future< Ftor, Thr >::_retRawBuf[sizeof(result_type)] [private] |
Raw memory to store a return object, no need of default constructor.
Put at first, to avoid alignments problems. Beware !!! When all 'result' functions called by all the functors of the library, will be able to return 'const result_type &', this temporary storage will not be necessary anymore.