MADNESS  0.10.1
Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
madness::DependencyInterface Class Reference

Provides an interface for tracking dependencies. More...

#include <dependency_interface.h>

Inheritance diagram for madness::DependencyInterface:
Inheritance graph
[legend]
Collaboration diagram for madness::DependencyInterface:
Collaboration graph
[legend]

Public Member Functions

 DependencyInterface (int ndep, const char *caller)
 
 DependencyInterface (int ndep=0)
 
virtual ~DependencyInterface ()
 Destructor. More...
 
void dec ()
 Decrement the number of dependencies and invoke the callback if ndepend==0. More...
 
void dec_debug (const char *caller)
 
void inc ()
 Increment the number of dependencies. More...
 
void inc_debug (const char *caller)
 Same as inc(), but keeps track of caller; calling dec_debug() will signal error if no matching inc_debug() had been invoked
More...
 
int ndep () const
 Returns the number of unsatisfied dependencies. More...
 
void notify ()
 Invoked by callbacks to notify of dependencies being satisfied. More...
 
void notify_debug (const char *caller)
 Overload of CallbackInterface::notify_debug(), updates dec() More...
 
bool probe () const
 Returns true if ndepend == 0 (no unsatisfied dependencies). More...
 
void register_callback (CallbackInterface *callback)
 Registers a callback that will be executed when ndepend==0; immediately invoked if ndepend==0. More...
 
void register_final_callback (CallbackInterface *callback)
 Registers the final callback to be executed when ndepend==0; immediately invoked if ndepend==0. More...
 
- Public Member Functions inherited from madness::CallbackInterface
virtual ~CallbackInterface ()
 

Private Types

using callbackT = Stack< CallbackInterface *, MAXCALLBACKS >
 

Private Member Functions

void do_callbacks (callbackT &cb) const
 
- 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...
 

Private Attributes

volatile callbackT callbacks
 Called ONCE by dec() when ndepend==0. More...
 
volatile CallbackInterfacefinal_callback
 The "final" callback can destroy the task, always invoked last, the object is in an invalid state (ndepend set to -1) after its execution. More...
 
std::atomic< int > ndepend
 Counts dependencies. For a valid object ndepend >= 0, after the final callback is executed ndepend is set to a negative value and the object becomes invalid. More...
 

Static Private Attributes

static const int MAXCALLBACKS = 8
 Maximum number of callbacks. More...
 

Additional Inherited Members

- Protected Member Functions inherited from madness::CallbackInterface
virtual void notify_debug_impl (const char *caller)
 

Detailed Description

Provides an interface for tracking dependencies.

Member Typedef Documentation

◆ callbackT

Todo:
Brief description needed.

Constructor & Destructor Documentation

◆ DependencyInterface() [1/2]

madness::DependencyInterface::DependencyInterface ( int  ndep = 0)
inline
Todo:
Constructor that...
Parameters
[in]ndepThe number of unsatisfied dependencies.

References MADNESS_ASSERT, and ndepend.

◆ DependencyInterface() [2/2]

madness::DependencyInterface::DependencyInterface ( int  ndep,
const char *  caller 
)
inline

Same as ctor above, but keeps track of caller . If a given object was constructed via this ctor, or DependencyInterface::inc_debug() had been called once, debugging variants of mutating calls ( {inc/dec/notify}_debug ) must be used for the rest of this object's lifetime.

Parameters
[in]ndepThe number of unsatisfied dependencies.

References MADNESS_ASSERT, ndep(), ndepend, and madness::print().

◆ ~DependencyInterface()

virtual madness::DependencyInterface::~DependencyInterface ( )
inlinevirtual

Destructor.

References c, madness::error(), MADNESS_ASSERT, ndepend, and madness::print().

Member Function Documentation

◆ dec()

void madness::DependencyInterface::dec ( )
inline

Decrement the number of dependencies and invoke the callback if ndepend==0.

References callbacks, do_callbacks(), madness::error(), final_callback, MADNESS_ASSERT, ndepend, and madness::Stack< T, N >::push().

Referenced by notify().

◆ dec_debug()

void madness::DependencyInterface::dec_debug ( const char *  caller)
inline

◆ do_callbacks()

void madness::DependencyInterface::do_callbacks ( callbackT cb) const
inlineprivate
Todo:
Brief description needed.

Main design point is that, because a callback might destroy this object, when callbacks are invoked we cannot be holding the lock and all necessary data must be on the stack (i.e., not from the object state).

Todo:
Parameter description needed.
Parameters
[in,out]cbDescription needed.

References madness::Stack< T, N >::empty(), madness::Stack< T, N >::pop(), and madness::Stack< T, N >::top().

Referenced by dec(), dec_debug(), register_callback(), and register_final_callback().

◆ inc()

void madness::DependencyInterface::inc ( )
inline

◆ inc_debug()

void madness::DependencyInterface::inc_debug ( const char *  caller)
inline

Same as inc(), but keeps track of caller; calling dec_debug() will signal error if no matching inc_debug() had been invoked

References madness::error(), MADNESS_ASSERT, max, ndep(), ndepend, and madness::print().

◆ ndep()

int madness::DependencyInterface::ndep ( ) const
inline

Returns the number of unsatisfied dependencies.

Returns
The number of unsatisfied dependencies.

References MADNESS_ASSERT, and ndepend.

Referenced by DependencyInterface(), dec_debug(), inc_debug(), and probe().

◆ notify()

void madness::DependencyInterface::notify ( )
inlinevirtual

Invoked by callbacks to notify of dependencies being satisfied.

Implements madness::CallbackInterface.

References dec(), MADNESS_ASSERT, and ndepend.

◆ notify_debug()

void madness::DependencyInterface::notify_debug ( const char *  caller)
inlinevirtual

◆ probe()

bool madness::DependencyInterface::probe ( ) const
inline

Returns true if ndepend == 0 (no unsatisfied dependencies).

Returns
True if there are no unsatisfied dependencies.

References ndep().

Referenced by madness::Future< std::vector< Future< T > > >::probe(), register_callback(), and register_final_callback().

◆ register_callback()

void madness::DependencyInterface::register_callback ( CallbackInterface callback)
inline

Registers a callback that will be executed when ndepend==0; immediately invoked if ndepend==0.

Parameters
[in]callbackThe callback to use.

References callbacks, do_callbacks(), final_callback, MADNESS_ASSERT, ndepend, madness::print(), probe(), and madness::Stack< T, N >::push().

◆ register_final_callback()

void madness::DependencyInterface::register_final_callback ( CallbackInterface callback)
inline

Registers the final callback to be executed when ndepend==0; immediately invoked if ndepend==0.

No additional callbacks can be registered after this call since execution of the final callback can cause destruction of this object.

Parameters
[in]callbackThe callback to use.

References callbacks, do_callbacks(), final_callback, MADNESS_ASSERT, ndepend, madness::print(), probe(), and madness::Stack< T, N >::push().

Referenced by madness::TaskInterface::register_submit_callback().

Member Data Documentation

◆ callbacks

volatile callbackT madness::DependencyInterface::callbacks
mutableprivate

Called ONCE by dec() when ndepend==0.

Referenced by dec(), dec_debug(), register_callback(), and register_final_callback().

◆ final_callback

volatile CallbackInterface* madness::DependencyInterface::final_callback
mutableprivate

The "final" callback can destroy the task, always invoked last, the object is in an invalid state (ndepend set to -1) after its execution.

Referenced by dec(), dec_debug(), register_callback(), and register_final_callback().

◆ MAXCALLBACKS

const int madness::DependencyInterface::MAXCALLBACKS = 8
staticprivate

Maximum number of callbacks.

◆ ndepend

std::atomic<int> madness::DependencyInterface::ndepend
private

Counts dependencies. For a valid object ndepend >= 0, after the final callback is executed ndepend is set to a negative value and the object becomes invalid.

Referenced by DependencyInterface(), ~DependencyInterface(), dec(), dec_debug(), inc(), inc_debug(), ndep(), notify(), notify_debug(), register_callback(), and register_final_callback().


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