MADNESS 0.10.1
madness::FutureImpl< T > Class Template Reference

Implements the functionality of futures. More...

#include <future.h>

Inheritance diagram for madness::FutureImpl< T >:
Collaboration diagram for madness::FutureImpl< T >:

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.

Detailed Description

template<typename T>
class madness::FutureImpl< T >

Implements the functionality of futures.

Template Parameters
TThe type of future.

Member Typedef Documentation

◆ assignmentT

template<typename T>
typedef Stack<std::shared_ptr<FutureImpl<T> >,MAXCALLBACKS> madness::FutureImpl< T >::assignmentT
private

Assignment type.

◆ callbackT

template<typename T>
typedef Stack<CallbackInterface*, MAXCALLBACKS> madness::FutureImpl< T >::callbackT
private

Callback type.

Constructor & Destructor Documentation

◆ FutureImpl() [1/2]

template<typename T>
madness::FutureImpl< T >::FutureImpl ( )
inline

Constructor that uses a local unassigned value.

References assigned, assignments, callbacks, remote_ref, and t.

Referenced by FutureImpl(), add_to_assignments(), replace_with(), and set_handler().

◆ FutureImpl() [2/2]

template<typename T>
madness::FutureImpl< T >::FutureImpl ( const RemoteReference< FutureImpl< T > > & remote_ref)
inline

Constructor that uses a wrapper for a remote future.

Todo
Description needed.
Parameters
[in]remote_refDescription needed.

References FutureImpl(), assigned, assignments, callbacks, remote_ref, and t.

◆ ~FutureImpl()

template<typename T>
virtual madness::FutureImpl< T >::~FutureImpl ( )
inlinevirtual

Destructor.

Todo
Perhaps a comment about its behavior.

References assigned, assignments, callbacks, and madness::print().

Member Function Documentation

◆ add_to_assignments()

template<typename T>
void madness::FutureImpl< T >::add_to_assignments ( const std::shared_ptr< FutureImpl< T > > f)
inlineprivate

Pass by value with implied copy to manage lifetime of f.

Todo
Description needed.
Parameters
[in]fDescription needed.

References FutureImpl(), assigned, assignments, madness::f, madness::Stack< T, N >::push(), and t.

◆ get() [1/2]

template<typename T>
T & madness::FutureImpl< T >::get ( bool dowork = true)
inline

Gets/forces the value, waiting if necessary.

Parameters
doworkIf true (default) and the future is not ready this thread will execute other tasks while waiting
Warning
PaRSEC backend does not support dowork=true from a callstack containing a running MADNESS task already, hence must use dowork=false when need to call from within a task
Returns
reference to the contained value
Precondition
this->is_local()

References madness::World::await(), MADNESS_ASSERT, probe(), remote_ref, and t.

◆ get() [2/2]

template<typename T>
const T & madness::FutureImpl< T >::get ( bool dowork = true) const
inline

Gets/forces the value, waiting if necessary.

Parameters
doworkIf true (default) and the future is not ready this thread will execute other tasks while waiting
Warning
PaRSEC backend does not support dowork=true from a callstack containing a running MADNESS task already, hence must use dowork=false when need to call from within a task
Returns
reference to the contained value
Precondition
this->is_local()

References madness::World::await(), MADNESS_ASSERT, probe(), remote_ref, and t.

◆ is_local()

template<typename T>
bool madness::FutureImpl< T >::is_local ( ) const
inline
Todo
Brief description needed.
Todo
Description needed.
Returns
Description needed.

References remote_ref.

◆ probe()

template<typename T>
bool madness::FutureImpl< T >::probe ( ) const
inline

Checks if the value has been assigned.

Returns
True if the value has been assigned; false otherwise.

References assigned.

Referenced by get(), and get().

◆ register_callback()

template<typename T>
void madness::FutureImpl< T >::register_callback ( CallbackInterface * callback)
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.

Todo
Description needed.
Parameters
callbackDescription needed.

References assigned, callbacks, fred(), and madness::CallbackInterface::notify().

◆ replace_with()

template<typename T>
bool madness::FutureImpl< T >::replace_with ( FutureImpl< T > * f)
inline
Todo
Brief description needed.
Todo

Is this function needed?

Details needed.

Parameters
fDescription needed.
Returns
Description needed.

References FutureImpl(), madness::f, and MADNESS_EXCEPTION.

◆ set() [1/2]

template<typename T>
void madness::FutureImpl< T >::set ( const archive::BufferInputArchive & input_arch)
inline
Todo
Brief description needed.
Todo
Descriptions needed.
Parameters
[in]input_archDescription needed.

References fred(), MADNESS_ASSERT, remote_ref, set_assigned(), and t.

◆ set() [2/2]

template<typename T>
template<typename U>
void madness::FutureImpl< T >::set ( U && value)
inline

Sets the value of the future (assignment).

Todo
Descriptions needed.
Template Parameters
UDescription needed.
Parameters
[in]valueDescription needed.

References madness::World::am, fred(), madness::Future< void >::value, madness::new_am_arg(), remote_ref, madness::WorldAmInterface::send(), set_assigned(), set_handler(), and t.

◆ set_assigned()

template<typename T>
void madness::FutureImpl< T >::set_assigned ( const T & value)
inlineprivate
Todo
Brief description needed.

Invoked locally by set routine after assignment.

Todo
Description needed.
Parameters
[in]valueDescription needed.

References assigned, assignments, callbacks, madness::Stack< T, N >::empty(), madness::Future< void >::value, MADNESS_ASSERT, madness::CallbackInterface::notify(), madness::Stack< T, N >::pop(), madness::Stack< T, N >::reset(), and madness::Stack< T, N >::top().

Referenced by set(), set(), and set_handler().

◆ set_handler()

◆ Future< T >

template<typename T>
friend class Future< T >
friend

◆ operator<<

template<typename T>
std::ostream & operator<< ( std::ostream & out,
const Future< T > & f )
friend

Human readable printing of a Future to a stream.

Stream output operator for a future.

Template Parameters
TThe type of future.
Parameters
[in,out]outThe output stream.
[in]fThe future.
Returns
The output stream.
Todo
Brief description needed.
Todo
Descriptions needed.
Template Parameters
TDescription needed.
Parameters
[in,out]Theoutput stream.
[in]fThe future to be output.
Returns
The output stream.

Member Data Documentation

◆ assigned

template<typename T>
std::atomic<bool> madness::FutureImpl< T >::assigned
private

A flag indicating if the future has been set.

Referenced by FutureImpl(), FutureImpl(), ~FutureImpl(), add_to_assignments(), probe(), register_callback(), and set_assigned().

◆ assignments

template<typename T>
volatile assignmentT madness::FutureImpl< T >::assignments
mutableprivate

A stack that stores future objects that are set to the same value as this future, once it has been set.

Referenced by FutureImpl(), FutureImpl(), ~FutureImpl(), add_to_assignments(), and set_assigned().

◆ callbacks

template<typename T>
volatile callbackT madness::FutureImpl< T >::callbacks
private

A stack that stores callbacks that are invoked once the future has been assigned.

Referenced by FutureImpl(), FutureImpl(), ~FutureImpl(), register_callback(), and set_assigned().

◆ MAXCALLBACKS

template<typename T>
const int madness::FutureImpl< T >::MAXCALLBACKS = 4
staticprivate

The static stack size used for callbacks and future assignment used for small stack size optimizations.

◆ remote_ref

template<typename T>
RemoteReference< FutureImpl<T> > madness::FutureImpl< T >::remote_ref
private

Reference to a remote future pimpl.

Referenced by FutureImpl(), FutureImpl(), get(), get(), is_local(), set(), set(), and set_handler().

◆ t

template<typename T>
volatile T madness::FutureImpl< T >::t
private

The future data.

Referenced by FutureImpl(), FutureImpl(), add_to_assignments(), get(), get(), set(), set(), and set_handler().


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