|
MADNESS 0.10.1
|
Provides an interface for tracking dependencies. More...
#include <dependency_interface.h>


Public Member Functions | |
| DependencyInterface (int ndep, const char *caller) | |
| DependencyInterface (int ndep=0) | |
| virtual | ~DependencyInterface () |
| Destructor. | |
| void | dec () |
Decrement the number of dependencies and invoke the callback if ndepend==0. | |
| void | dec_debug (const char *caller) |
| void | inc () |
| Increment the number of dependencies. | |
| 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 | |
| int | ndep () const |
| Returns the number of unsatisfied dependencies. | |
| void | notify () |
| Invoked by callbacks to notify of dependencies being satisfied. | |
| void | notify_debug (const char *caller) |
| Overload of CallbackInterface::notify_debug(), updates dec() | |
| bool | probe () const |
Returns true if ndepend == 0 (no unsatisfied dependencies). | |
| void | register_callback (CallbackInterface *callback) |
Registers a callback that will be executed when ndepend==0; immediately invoked if ndepend==0. | |
| void | register_final_callback (CallbackInterface *callback) |
Registers the final callback to be executed when ndepend==0; immediately invoked if ndepend==0. | |
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. | |
| 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. | |
Private Attributes | |
| volatile callbackT | callbacks |
Called ONCE by dec() when ndepend==0. | |
| volatile CallbackInterface * | final_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. | |
| 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. | |
Static Private Attributes | |
| static const int | MAXCALLBACKS = 8 |
| Maximum number of callbacks. | |
Additional Inherited Members | |
Protected Member Functions inherited from madness::CallbackInterface | |
| virtual void | notify_debug_impl (const char *caller) |
Provides an interface for tracking dependencies.
|
inline |
| [in] | ndep | The number of unsatisfied dependencies. |
References MADNESS_ASSERT, and ndepend.
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.
| [in] | ndep | The number of unsatisfied dependencies. |
References MADNESS_ASSERT, ndep(), ndepend, madness::nonlinear_vector_solver(), and madness::print().
|
inlinevirtual |
Destructor.
References c, madness::error(), MADNESS_ASSERT, ndepend, madness::nonlinear_vector_solver(), and madness::print().
|
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::nonlinear_vector_solver().
Referenced by notify().
References callbacks, do_callbacks(), madness::error(), final_callback, MADNESS_ASSERT, ndep(), ndepend, madness::nonlinear_vector_solver(), and madness::print().
Referenced by notify_debug().
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).
| [in,out] | cb | Description needed. |
References madness::nonlinear_vector_solver().
Referenced by dec(), dec_debug(), register_callback(), and register_final_callback().
|
inline |
Increment the number of dependencies.
References madness::error(), MADNESS_ASSERT, ndepend, and madness::nonlinear_vector_solver().
Referenced by madness::TaskFn< fnT, arg1T, arg2T, arg3T, arg4T, arg5T, arg6T, arg7T, arg8T, arg9T >::check_dependency(), and madness::TaskFn< fnT, arg1T, arg2T, arg3T, arg4T, arg5T, arg6T, arg7T, arg8T, arg9T >::check_dependency().
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, ndep(), ndepend, madness::nonlinear_vector_solver(), and madness::print().
|
inline |
Returns the number of unsatisfied dependencies.
References MADNESS_ASSERT, and ndepend.
Referenced by DependencyInterface(), dec_debug(), inc_debug(), and probe().
|
inlinevirtual |
Invoked by callbacks to notify of dependencies being satisfied.
Implements madness::CallbackInterface.
References dec(), MADNESS_ASSERT, and ndepend.
Overload of CallbackInterface::notify_debug(), updates dec()
Reimplemented from madness::CallbackInterface.
References dec_debug(), MADNESS_ASSERT, ndepend, madness::nonlinear_vector_solver(), and madness::CallbackInterface::notify_debug_impl().
|
inline |
Returns true if ndepend == 0 (no unsatisfied dependencies).
References ndep().
Referenced by madness::Future< std::vector< Future< T > > >::probe(), register_callback(), and register_final_callback().
|
inline |
Registers a callback that will be executed when ndepend==0; immediately invoked if ndepend==0.
| [in] | callback | The callback to use. |
References callbacks, do_callbacks(), final_callback, MADNESS_ASSERT, ndepend, madness::nonlinear_vector_solver(), madness::print(), and probe().
Referenced by madness::Future< std::vector< Future< T > > >::Future().
|
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.
| [in] | callback | The callback to use. |
References callbacks, do_callbacks(), final_callback, MADNESS_ASSERT, ndepend, madness::nonlinear_vector_solver(), madness::print(), and probe().
Referenced by madness::TaskInterface::register_submit_callback().
Called ONCE by dec() when ndepend==0.
Referenced by dec(), dec_debug(), register_callback(), and register_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().
|
staticprivate |
Maximum number of callbacks.
|
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(), ~DependencyInterface(), dec(), dec_debug(), inc(), inc_debug(), ndep(), notify(), notify_debug(), register_callback(), and register_final_callback().