MADNESS
0.10.1
|
Implements the functionality of futures. More...
#include <future.h>
Public Member Functions | |
FutureImpl () | |
Constructor that uses a local unassigned value. More... | |
FutureImpl (const RemoteReference< FutureImpl< T > > &remote_ref) | |
Constructor that uses a wrapper for a remote future. More... | |
virtual | ~FutureImpl () |
Destructor. More... | |
T & | get (bool dowork=true) |
Gets/forces the value, waiting if necessary. More... | |
const T & | get (bool dowork=true) const |
Gets/forces the value, waiting if necessary. More... | |
bool | is_local () const |
bool | probe () const |
Checks if the value has been assigned. More... | |
void | register_callback (CallbackInterface *callback) |
Registers a function to be invoked when future is assigned. More... | |
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). More... | |
Private Types | |
typedef Stack< std::shared_ptr< FutureImpl< T > >, MAXCALLBACKS > | assignmentT |
Assignment type. More... | |
typedef Stack< CallbackInterface *, MAXCALLBACKS > | callbackT |
Callback type. More... | |
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 . More... | |
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. More... | |
virtual | ~Spinlock () |
void | lock () const |
Acquire the spinlock waiting if necessary. More... | |
bool | try_lock () const |
Try to acquire the spinlock ... return true on success, false on failure. More... | |
void | unlock () const |
Free a spinlock owned by this thread. More... | |
Static Private Member Functions | |
static void | set_handler (const AmArg &arg) |
AM handler for remote set operations. More... | |
Private Attributes | |
std::atomic< bool > | assigned |
A flag indicating if the future has been set. More... | |
volatile assignmentT | assignments |
volatile callbackT | callbacks |
RemoteReference< FutureImpl< T > > | remote_ref |
Reference to a remote future pimpl. More... | |
volatile T | t |
The future data. More... | |
Static Private Attributes | |
static const int | MAXCALLBACKS = 4 |
Friends | |
class | Future< T > |
std::ostream & | operator (std::ostream &out, const Future< T > &f) |
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, madness::Stack< T, N >::push(), 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.
|
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().
|
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, madness::Stack< T, N >::empty(), MADNESS_ASSERT, madness::Stack< T, N >::pop(), madness::Stack< T, N >::reset(), and madness::Stack< T, N >::top().
Referenced by 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.
|
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 >::is_local(), madness::FutureImpl< T >::set(), and madness::FutureImpl< T >::set_handler().
|
private |
The future data.
Referenced by madness::FutureImpl< T >::add_to_assignments(), madness::FutureImpl< T >::get(), madness::FutureImpl< T >::set(), and madness::FutureImpl< T >::set_handler().