eventAdd with zero delay?

From: Rainer Weikusat <rweikusat_at_mobileactivedefense.com>
Date: Wed, 30 Jan 2013 01:47:23 +0000

What's the point of putting these onto the event queue? Wouldn't this
be better done with something like this?

NB: I would submit a proper patch for this if it was.

---------------------
--- mad-squid-ev0/src/event.cc 8 Jan 2013 17:36:44 -0000 1.1.1.3
+++ mad-squid-ev0/src/event.cc 30 Jan 2013 01:40:17 -0000
@@ -233,6 +233,17 @@
     return result;
 }
 
+static void
+fireEvent(char const *name, EVH *func, void *arg, bool cbdata)
+{
+ /* XXX assumes name is static memory! */
+ AsyncCall::Pointer call = asyncCall(41,5, name,
+ EventDialer(func, arg, cbdata));
+ ScheduleCallHere(call);
+
+ last_event_ran = name; // XXX: move this to AsyncCallQueue
+}
+
 int
 EventScheduler::checkEvents(int timeout)
 {
@@ -253,12 +264,8 @@
         if (event->when > current_dtime)
             break;
 
- /* XXX assumes event->name is static memory! */
- AsyncCall::Pointer call = asyncCall(41,5, event->name,
- EventDialer(event->func, event->arg, event->cbdata));
- ScheduleCallHere(call);
+ fireEvent(event->name, event->func, event->arg, event->cbdata);
 
- last_event_ran = event->name; // XXX: move this to AsyncCallQueue
         const bool heavy = event->weight &&
                            (!event->cbdata || cbdataReferenceValid(event->arg));
 
@@ -332,10 +339,12 @@
 void
 EventScheduler::schedule(const char *name, EVH * func, void *arg, double when, int weight, bool cbdata)
 {
- // Use zero timestamp for when=0 events: Many of them are async calls that
- // must fire in the submission order. We cannot use current_dtime for them
- // because it may decrease if system clock is adjusted backwards.
- const double timestamp = when > 0.0 ? current_dtime + when : 0;
+ if (when == 0.0) {
+ fireEvent(name, func, arg, cbdata);
+ return;
+ }
+
+ const double timestamp = current_dtime + when;
     ev_entry *event = new ev_entry(name, func, arg, timestamp, weight, cbdata);
 
     ev_entry **E;
-----------------------
Received on Wed Jan 30 2013 - 01:47:38 MST

This archive was generated by hypermail 2.2.0 : Wed Jan 30 2013 - 12:00:08 MST