2#ifndef CLICK_NOTIFIER_HH
3#define CLICK_NOTIFIER_HH
6#include <click/algorithm.hh>
7#if HAVE_CXX_PRAGMA_INTERFACE
8# pragma interface "click/notifier.hh"
26 inline bool active()
const;
28 inline operator unspecified_bool_type()
const;
32 inline bool idle()
const;
33 inline bool busy()
const;
64 true_mask = 1, false_mask = 2, overderived_mask = 4,
65 uninitialized_mask = 8
71 static bool hard_equals(
const vmpair *a,
const vmpair *b);
76 enum SearchOp { SEARCH_STOP = 0, SEARCH_CONTINUE, SEARCH_CONTINUE_WAKE };
77 typedef void (*callback_type)(
void *,
Notifier *);
79 inline Notifier(SearchOp op = SEARCH_STOP);
93 inline bool active()
const;
107 static const char EMPTY_NOTIFIER[];
108 static const char FULL_NOTIFIER[];
132 static void dependent_signal_callback(
void *,
Notifier *);
149#if CLICK_DEBUG_SCHEDULING
163 task_or_signal_t* _listeners;
165 int listener_add(callback_type f,
void *v);
166 int listener_remove(callback_type f,
void *v);
179 _v.v1 = &static_value;
202 if (unlikely(_mask == 0))
226 return NotifierSignal(&static_value, overderived_mask | true_mask);
248 return (*_v.v1 & _mask) != 0;
250 for (vmpair *vm = _v.vm; vm->mask; ++vm)
251 if ((*vm->value & vm->mask) != 0)
258inline NotifierSignal::operator unspecified_bool_type()
const {
265 return (_mask == false_mask && _v.v1 == &static_value);
274 return ((_mask & true_mask) && _v.v1 == &static_value);
283 return ((_mask & overderived_mask) && _v.v1 == &static_value);
289 return (!(_mask & uninitialized_mask) || _v.v1 != &static_value);
302 assert(_v.v1 != &static_value && !(_mask & (_mask - 1)));
303 uint32_t expected = *_v.v1;
304#if !CLICK_USERLEVEL || HAVE_MULTITHREAD
306#if ! CLICK_ATOMIC_COMPARE_SWAP
308 uint32_t desired = (
active ? expected | _mask : expected & ~_mask);
309 if(_v.v1->compare_and_swap(expected, desired))
314 uint32_t desired = (
active ? expected | _mask : expected & ~_mask);
315 uint32_t actual = _v.v1->compare_swap(expected, desired);
316 if (expected == actual)
322 *_v.v1 = (
active ? expected | _mask : expected & ~_mask);
324 return expected & _mask;
329 if (likely(
this != &x)) {
330 if (unlikely(_mask == 0))
343 click_swap(_v, x._v);
344 click_swap(_mask, x._mask);
356 if (a._mask == b._mask) {
358 return a._v.v1 == b._v.v1;
360 return NotifierSignal::hard_equals(a._v.vm, b._v.vm);
435 : _signal(
NotifierSignal::uninitialized_signal()), _search_op(op) {
449 : _signal(signal), _search_op(op) {
592 return upstream_signal(e, port, (callback_type) 0, 0, Notifier::EMPTY_NOTIFIER);
603 return upstream_signal(e, port, (callback_type) 0, task, Notifier::EMPTY_NOTIFIER);
614 Task* task,
const char * signal) {
626 return upstream_signal(e, port, dependent_signal_callback, &dependent_notifier->_signal, Notifier::EMPTY_NOTIFIER);
739 if (
active && schedule && !was_active) {
747 else if (task_or_signal_t *tos = _listeners) {
748 for (; tos->p > 1; tos++)
749 tos->t->reschedule();
751 for (tos++; tos->p; tos += 2)
752 tos->f(tos[1].v,
this);
An atomic 32-bit integer.
A basic activity signal and notification provider that can reschedule any dependent Task objects.
Definition notifier.hh:136
void set_active(bool active, bool schedule=true)
Set the associated signal's activity, possibly scheduling any listener tasks.
Definition notifier.hh:737
int add_activate_callback(callback_type f, void *v)
Register an activate callback with this Notifier.
Definition notifier.cc:336
~ActiveNotifier()
Destroy an ActiveNotifier.
Definition notifier.cc:330
void remove_activate_callback(callback_type f, void *v)
Unregister an activate callback with this Notifier.
Definition notifier.cc:398
void listeners(Vector< Task * > &v) const
Return the listener list.
Definition notifier.cc:432
void wake()
Set the associated signal to active and schedule any listener tasks.
Definition notifier.hh:765
void sleep()
Set the associated signal to inactive.
Definition notifier.hh:772
Base class for Click elements.
Definition element.hh:42
A basic activity signal and notification provider.
Definition notifier.hh:74
bool active() const
Returns whether the associated signal is active.
Definition notifier.hh:474
Notifier(SearchOp op=SEARCH_STOP)
Constructs a Notifier.
Definition notifier.hh:434
int add_dependent_signal(NotifierSignal *signal)
Register a dependent signal with this Notifier.
Definition notifier.hh:542
int add_listener(Task *task)
Register a listener with this Notifier.
Definition notifier.hh:517
bool set_active(bool active)
Set the associated signal's activity.
Definition notifier.hh:490
const NotifierSignal & signal() const
Return this Notifier's associated NotifierSignal.
Definition notifier.hh:458
static NotifierSignal downstream_full_signal(Element *e, int port)
Calculate and return the NotifierSignal derived from all full notifiers downstream of element e's out...
Definition notifier.hh:673
SearchOp search_op() const
Return this Notifier's search operation.
Definition notifier.hh:466
bool safe_active() const
Returns whether the associated signal is active.
Definition notifier.hh:482
void sleep()
Set the associated signal to inactive.
Definition notifier.hh:504
void remove_listener(Task *task)
Unregister a listener with this Notifier.
Definition notifier.hh:529
virtual int add_activate_callback(callback_type f, void *user_data)
Register an activate callback with this Notifier.
Definition notifier.cc:274
void remove_dependent_signal(NotifierSignal *signal)
Unregister a dependent signal with this Notifier.
Definition notifier.hh:555
static NotifierSignal upstream_signal(Element *e, int port, Task *task, const char *signal)
Calculate and return the NotifierSignal derived from all empty notifiers upstream of element e's inpu...
Definition notifier.hh:613
int initialize(const char *name, Router *router)
Initialize the associated NotifierSignal, if necessary.
Definition notifier.cc:308
bool initialized() const
Return whether the Notifier is initialized.
Definition notifier.hh:84
static NotifierSignal upstream_empty_signal(Element *e, int port)
Calculate and return the NotifierSignal derived from all empty notifiers upstream of element e's inpu...
Definition notifier.hh:591
virtual ~Notifier()
Destruct a Notifier.
Definition notifier.cc:248
virtual void remove_activate_callback(callback_type f, void *user_data)
Unregister an activate callback with this Notifier.
Definition notifier.cc:294
void wake()
Set the associated signal to active.
Definition notifier.hh:497
An activity signal.
Definition notifier.hh:12
void swap(NotifierSignal &x)
Exchange the values of this signal and x.
Definition notifier.hh:342
bool idle() const
Test if the signal is idle.
Definition notifier.hh:264
bool overderived() const
Test if the signal is overderived.
Definition notifier.hh:282
friend NotifierSignal operator+(NotifierSignal a, const NotifierSignal &b)
Return a derived signal.
Definition notifier.hh:391
bool safe_active() const
Test if the signal is active.
Definition notifier.hh:246
bool busy() const
Test if the signal is busy.
Definition notifier.hh:273
friend bool operator!=(const NotifierSignal &a, const NotifierSignal &b)
Test if two NotifierSignals are unequal.
Definition notifier.hh:369
bool set_active(bool active)
Set whether the basic signal is active.
Definition notifier.hh:301
~NotifierSignal()
Destroy a signal.
Definition notifier.hh:201
bool active() const
Test if the signal is active.
Definition notifier.hh:238
static NotifierSignal overderived_signal()
Return an overderived busy signal.
Definition notifier.hh:225
NotifierSignal & operator+=(const NotifierSignal &x)
Make this signal derived by adding information from x.
Definition notifier.cc:125
String unparse(Router *router) const
Return a human-readable representation of the signal.
Definition notifier.cc:215
friend bool operator==(const NotifierSignal &a, const NotifierSignal &b)
Test if two NotifierSignals are equal.
Definition notifier.hh:355
static NotifierSignal uninitialized_signal()
Return an uninitialized signal.
Definition notifier.hh:233
static void static_initialize()
Initialize the NotifierSignal implementation.
Definition notifier.cc:113
NotifierSignal()
Construct a busy signal.
Definition notifier.hh:177
static NotifierSignal busy_signal()
Return a busy signal.
Definition notifier.hh:216
NotifierSignal & operator=(const NotifierSignal &x)
Assign a signal.
Definition notifier.hh:328
static NotifierSignal idle_signal()
Return an idle signal.
Definition notifier.hh:209
bool initialized() const
Test if the signal is initialized.
Definition notifier.hh:288
A router configuration.
Definition router.hh:28
A string of characters.
Definition string.hh:22
Represents a frequently-scheduled computational task.
Definition task.hh:49
void reschedule()
Reschedule the task.
Definition task.hh:206
Vector template.
Definition vector.hh:111
A 32-bit integer with support for atomic operations.
Definition atomic.hh:71
Support for Task, which triggers execution frequently.