--------------------- PatchSet 5963 Date: 2007/10/14 14:44:28 Author: chtsanti Branch: async-calls Tag: (none) Log: applying Alex's dirty fix (attachment id=1497) for bug 2093 Members: src/EventLoop.cc:1.5->1.5.4.1 Index: squid3/src/EventLoop.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/EventLoop.cc,v retrieving revision 1.5 retrieving revision 1.5.4.1 diff -u -r1.5 -r1.5.4.1 --- squid3/src/EventLoop.cc 23 Jul 2007 20:50:56 -0000 1.5 +++ squid3/src/EventLoop.cc 14 Oct 2007 14:44:28 -0000 1.5.4.1 @@ -1,6 +1,6 @@ /* - * $Id: EventLoop.cc,v 1.5 2007/07/23 20:50:56 squidadm Exp $ + * $Id: EventLoop.cc,v 1.5.4.1 2007/10/14 14:44:28 chtsanti Exp $ * * DEBUG: section 1 Main Loop * AUTHOR: Harvest Derived @@ -105,31 +105,50 @@ bool EventLoop::runOnce() { + bool sawActivity = false; runOnceResult = true; error = false; loop_delay = 10; /* 10 ms default delay */ - for (engine_vector::iterator i = engines.begin(); - i != engines.end(); ++i) { - /* check the primary outside the loop */ - - if (*i == primaryEngine) - continue; + AsyncEngine *waitingEngine = primaryEngine; + if (!waitingEngine && !engines.empty()) + waitingEngine = engines.back(); + + do { + sawActivity = false; + + // collect events into dispatchers + typedef engine_vector::iterator EVI; + for (EVI i = engines.begin(); i != engines.end(); ++i) { + if (*i != waitingEngine) + checkEngine(*i, false); + } - /* special case the last engine to be primary */ - checkEngine(*i, primaryEngine == NULL && (i - engines.end() == -1)); - } + // fire events; TODO: make this a method + typedef dispatcher_vector::iterator DVI; + for (DVI i = dispatchers.begin(); i != dispatchers.end(); ++i) { + if ((*i)->dispatch()) + sawActivity = true; + } + if (sawActivity) + runOnceResult = false; + } while (sawActivity); - if (primaryEngine != NULL) - checkEngine(primaryEngine, true); + if (waitingEngine != NULL) + checkEngine(waitingEngine, true); if (timeService != NULL) timeService->tick(); - for (dispatcher_vector::iterator i = dispatchers.begin(); - i != dispatchers.end(); ++i) + // fire events from the waiting engine; TODO: make this a method + sawActivity = false; + typedef dispatcher_vector::iterator DVI; + for (DVI i = dispatchers.begin(); i != dispatchers.end(); ++i) { if ((*i)->dispatch()) - runOnceResult = false; + sawActivity = true; + } + if (sawActivity) + runOnceResult = false; if (error) { ++errcount;