MADNESS 0.10.1
|
Implements the functionality of futures. More...
#include <future.h>
Public Member Functions | |
FutureImpl () | |
Constructor that uses a local unassigned value. | |
FutureImpl (const RemoteReference< FutureImpl< T > > &remote_ref) | |
Constructor that uses a wrapper for a remote future. | |
virtual | ~FutureImpl () |
Destructor. | |
T & | get (bool dowork=true) |
Gets/forces the value, waiting if necessary. | |
const T & | get (bool dowork=true) const |
Gets/forces the value, waiting if necessary. | |
bool | is_local () const |
bool | probe () const |
Checks if the value has been assigned. | |
void | register_callback (CallbackInterface *callback) |
Registers a function to be invoked when future is assigned. | |
bool | replace_with (FutureImpl< T > *f) |
void | set (const archive::BufferInputArchive &input_arch) |
template<typename U > | |
void | set (U &&value) |
Sets the value of the future (assignment). | |
Private Types | |
typedef Stack< std::shared_ptr< FutureImpl< T > >, MAXCALLBACKS > | assignmentT |
Assignment type. | |
typedef Stack< CallbackInterface *, MAXCALLBACKS > | callbackT |
Callback type. | |
Private Member Functions | |
void | add_to_assignments (const std::shared_ptr< FutureImpl< T > > f) |
Pass by value with implied copy to manage lifetime of f . | |
void | set_assigned (const T &value) |
Private Member Functions inherited from madness::Spinlock | |
Spinlock (int junk=0) | |
Make and initialize a spinlock ... initial state is unlocked. | |
virtual | ~Spinlock () |
void | lock () const |
Acquire the spinlock waiting if necessary. | |
bool | try_lock () const |
Try to acquire the spinlock ... return true on success, false on failure. | |
void | unlock () const |
Free a spinlock owned by this thread. | |
Static Private Member Functions | |
static void | set_handler (const AmArg &arg) |
AM handler for remote set operations. | |
Private Attributes | |
std::atomic< bool > | assigned |
A flag indicating if the future has been set. | |
volatile assignmentT | assignments |
volatile callbackT | callbacks |
RemoteReference< FutureImpl< T > > | remote_ref |
Reference to a remote future pimpl. | |
volatile T | t |
The future data. | |
Static Private Attributes | |
static const int | MAXCALLBACKS = 4 |
Friends | |
class | Future< T > |
std::ostream & | operator<< (std::ostream &out, const Future< T > &f) |
Human readable printing of a Future to a stream. | |
Implements the functionality of futures.
T | The type of future. |
|
private |
Assignment type.
|
private |
Callback type.
|
inline |
Constructor that uses a local unassigned value.
|
inline |
Constructor that uses a wrapper for a remote future.
[in] | remote_ref | Description needed. |
|
inlinevirtual |
Destructor.
References madness::FutureImpl< T >::assigned, madness::FutureImpl< T >::assignments, madness::FutureImpl< T >::callbacks, and madness::print().
|
inlineprivate |
Pass by value with implied copy to manage lifetime of f
.
[in] | f | Description needed. |
References madness::FutureImpl< T >::assigned, madness::FutureImpl< T >::assignments, madness::f, T(), and madness::FutureImpl< T >::t.
|
inline |
Gets/forces the value, waiting if necessary.
dowork | If true (default) and the future is not ready this thread will execute other tasks while waiting |
dowork=true
from a callstack containing a running MADNESS task already, hence must use dowork=false
when need to call from within a task this->is_local()
References madness::World::await(), MADNESS_ASSERT, madness::FutureImpl< T >::probe(), madness::FutureImpl< T >::remote_ref, T(), and madness::FutureImpl< T >::t.
Referenced by madness::WorldContainerImpl< keyT, valueT, hashfunT >::find_failure_handler(), and madness::WorldContainerImpl< keyT, valueT, hashfunT >::find_success_handler().
|
inline |
Gets/forces the value, waiting if necessary.
dowork | If true (default) and the future is not ready this thread will execute other tasks while waiting |
dowork=true
from a callstack containing a running MADNESS task already, hence must use dowork=false
when need to call from within a task this->is_local()
References madness::World::await(), MADNESS_ASSERT, madness::FutureImpl< T >::probe(), madness::FutureImpl< T >::remote_ref, T(), and madness::FutureImpl< T >::t.
|
inline |
References madness::FutureImpl< T >::remote_ref.
|
inline |
Checks if the value has been assigned.
References madness::FutureImpl< T >::assigned.
Referenced by madness::FutureImpl< T >::get(), and madness::FutureImpl< T >::get().
|
inline |
Registers a function to be invoked when future is assigned.
Callbacks are invoked in the order registered. If the future is already assigned, the callback is immediately invoked.
callback | Description needed. |
References madness::FutureImpl< T >::assigned, madness::FutureImpl< T >::callbacks, fred(), and madness::CallbackInterface::notify().
|
inline |
Is this function needed?
Details needed.
f | Description needed. |
References MADNESS_EXCEPTION.
|
inline |
[in] | input_arch | Description needed. |
References fred(), MADNESS_ASSERT, madness::FutureImpl< T >::remote_ref, madness::FutureImpl< T >::set_assigned(), T(), and madness::FutureImpl< T >::t.
Sets the value of the future (assignment).
U | Description needed. |
[in] | value | Description needed. |
References madness::World::am, fred(), madness::new_am_arg(), madness::FutureImpl< T >::remote_ref, madness::WorldAmInterface::send(), madness::FutureImpl< T >::set_assigned(), T(), and madness::FutureImpl< T >::t.
|
inlineprivate |
Invoked locally by set routine after assignment.
[in] | value | Description needed. |
References madness::FutureImpl< T >::assigned, madness::FutureImpl< T >::assignments, madness::FutureImpl< T >::callbacks, and MADNESS_ASSERT.
Referenced by madness::FutureImpl< T >::set(), madness::FutureImpl< T >::set(), and madness::FutureImpl< T >::set_handler().
|
inlinestaticprivate |
AM handler for remote set operations.
[in] | arg | Description needed. |
References madness::World::am, madness::arg(), fred(), madness::RemoteReference< T >::get(), madness::new_am_arg(), madness::FutureImpl< T >::remote_ref, madness::RemoteReference< T >::reset(), madness::WorldAmInterface::send(), madness::FutureImpl< T >::set_assigned(), T(), and madness::FutureImpl< T >::t.
|
friend |
Human readable printing of a Future
to a stream.
Stream output operator for a future.
T | The type of future. |
[in,out] | out | The output stream. |
[in] | f | The future. |
T | Description needed. |
[in,out] | The | output stream. |
[in] | f | The future to be output. |
|
private |
A flag indicating if the future has been set.
Referenced by madness::FutureImpl< T >::~FutureImpl(), madness::FutureImpl< T >::add_to_assignments(), madness::FutureImpl< T >::probe(), madness::FutureImpl< T >::register_callback(), and madness::FutureImpl< T >::set_assigned().
|
mutableprivate |
A stack that stores future objects that are set to the same value as this future, once it has been set.
Referenced by madness::FutureImpl< T >::~FutureImpl(), madness::FutureImpl< T >::add_to_assignments(), and madness::FutureImpl< T >::set_assigned().
|
private |
A stack that stores callbacks that are invoked once the future has been assigned.
Referenced by madness::FutureImpl< T >::~FutureImpl(), madness::FutureImpl< T >::register_callback(), and madness::FutureImpl< T >::set_assigned().
|
staticprivate |
The static stack size used for callbacks and future assignment used for small stack size optimizations.
|
private |
Reference to a remote future pimpl.
Referenced by madness::FutureImpl< T >::get(), madness::FutureImpl< T >::get(), madness::FutureImpl< T >::is_local(), madness::FutureImpl< T >::set(), madness::FutureImpl< T >::set(), and madness::FutureImpl< T >::set_handler().
|
private |