MADNESS  0.10.1
Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
madness::FutureImpl< T > Class Template Reference

Implements the functionality of futures. More...

#include <future.h>

Inheritance diagram for madness::FutureImpl< T >:
Inheritance graph
[legend]
Collaboration diagram for madness::FutureImpl< T >:
Collaboration graph
[legend]

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...
 
Tget (bool dowork=true)
 Gets/forces the value, waiting if necessary. More...
 
const Tget (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 > >, MAXCALLBACKSassignmentT
 Assignment type. More...
 
typedef Stack< CallbackInterface *, MAXCALLBACKScallbackT
 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)
 

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.

◆ 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.

◆ ~FutureImpl()

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

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 madness::FutureImpl< T >::assigned, madness::FutureImpl< T >::assignments, madness::f, madness::Stack< T, N >::push(), T(), and madness::FutureImpl< T >::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, madness::FutureImpl< T >::probe(), madness::FutureImpl< T >::remote_ref, T(), and madness::FutureImpl< T >::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, madness::FutureImpl< T >::probe(), madness::FutureImpl< T >::remote_ref, T(), and madness::FutureImpl< T >::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 madness::FutureImpl< T >::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 madness::FutureImpl< T >::assigned.

Referenced by madness::FutureImpl< T >::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 madness::FutureImpl< T >::assigned, madness::FutureImpl< T >::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 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, madness::FutureImpl< T >::remote_ref, madness::FutureImpl< T >::set_assigned(), T(), and madness::FutureImpl< T >::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::new_am_arg(), madness::FutureImpl< T >::remote_ref, madness::WorldAmInterface::send(), madness::FutureImpl< T >::set_assigned(), T(), and madness::FutureImpl< T >::t.

◆ set_assigned()

template<typename T >
void madness::FutureImpl< T >::set_assigned ( const T value)
inlineprivate

◆ set_handler()

template<typename T >
static void madness::FutureImpl< T >::set_handler ( const AmArg arg)
inlinestaticprivate

Friends And Related Function Documentation

◆ 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

Member Data Documentation

◆ assigned

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

◆ 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 madness::FutureImpl< T >::~FutureImpl(), madness::FutureImpl< T >::add_to_assignments(), and madness::FutureImpl< T >::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 madness::FutureImpl< T >::~FutureImpl(), madness::FutureImpl< T >::register_callback(), and madness::FutureImpl< T >::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

◆ t

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

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