[Xorp-hackers] libxorp eventloop.cc comments

Ben Greear greearb at candelatech.com
Tue Oct 7 15:37:55 PDT 2008


I notice that some work was done on the event
loop recently.

I haven't actually tried to run this yet (it conflicts badly
with my own hackings...I'm still resolving that), but I think it
still has some of the same issues I hit before.

Mainly:  Each call to do_work() will run a timer OR a task OR a selector.

If it is ever possible that a task is high priority, but is waiting
on a selector, then we have effective deadlock.

I can't remember if I ever saw this for certain, but it would seem
possible to me.

At the least, if the selector is ready to read, the loop is going to spin
(since select() will not block now) until the socket(s) are dealt with.

So, I still like my original patch that got rid of all of the priority
stuff between selectors, timers, and tasks and ran each of them at each
spin through do_work.  Always run the selector last, since it may sleep if
there are no tasks or timers waiting to run.

      TimeVal t;

-    _timer_list.advance_time();
      _timer_list.get_next_delay(t);

+    // Run timers if they need it.
+    if (t == TimeVal::ZERO()) {
+	_timer_list.run();
+    }
+
+    if (!_task_list.empty()) {
+	_task_list.run();
+	if (!_task_list.empty()) {
+	    // Run task again as soon as possible.
+	    t = TimeVal::ZERO();
+	}
+    }
+
+#ifdef HOST_OS_WINDOWS
+    _win_dispatcher.wait_and_dispatch(t);
+#else
+    _selector_list.wait_and_dispatch(t);
+#endif
+
+    _timer_list.current_time(last_ev_run);
+
+#if 0
      int timer_priority = XorpTask::PRIORITY_INFINITY;
      int selector_priority = XorpTask::PRIORITY_INFINITY;
      int task_priority = XorpTask::PRIORITY_INFINITY;
@@ -139,6 +157,7 @@ EventLoop::run()
      }

      last_ev_run = time(0);
+#endif
  }



Also, last_ev_run should NOT be a static variable..it should be a member
of the EventLoop class.

Thanks,
Ben

-- 
Ben Greear <greearb at candelatech.com>
Candela Technologies Inc  http://www.candelatech.com



More information about the Xorp-hackers mailing list