--------------------- PatchSet 6411 Date: 2007/12/20 05:43:02 Author: rousskov Branch: async-calls Tag: (none) Log: Converted CompletionDispatcher-based SignalDispatcher into AsyncEngine-based SignalEngine to get rid of CompletionDispatchers. Members: src/main.cc:1.89.4.2->1.89.4.3 Index: squid3/src/main.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/main.cc,v retrieving revision 1.89.4.2 retrieving revision 1.89.4.3 diff -u -r1.89.4.2 -r1.89.4.3 --- squid3/src/main.cc 20 Dec 2007 04:42:06 -0000 1.89.4.2 +++ squid3/src/main.cc 20 Dec 2007 05:43:02 -0000 1.89.4.3 @@ -1,6 +1,6 @@ /* - * $Id: main.cc,v 1.89.4.2 2007/12/20 04:42:06 rousskov Exp $ + * $Id: main.cc,v 1.89.4.3 2007/12/20 05:43:02 rousskov Exp $ * * DEBUG: section 1 Startup and Main Loop * AUTHOR: Harvest Derived @@ -142,14 +142,12 @@ }; }; -class SignalDispatcher : public CompletionDispatcher +class SignalEngine: public AsyncEngine { public: - SignalDispatcher(EventLoop &loop) : loop(loop), events_dispatched(false) {} - - void addEventLoop(EventLoop * loop); - virtual bool dispatch(); + SignalEngine(EventLoop &loop) : loop(loop) {} + virtual int checkEvents(int timeout); private: static void StopEventLoop(void * data) @@ -157,14 +155,15 @@ static_cast(data)->loop.stop(); } + void doShutdown(time_t wait); + EventLoop &loop; - bool events_dispatched; }; -bool -SignalDispatcher::dispatch() +int +SignalEngine::checkEvents(int timeout) { - PROF_start(SignalDispatcher_dispatch); + PROF_start(SignalEngine_checkEvents); if (do_reconfigure) { mainReconfigure(); @@ -173,24 +172,28 @@ mainRotate(); do_rotate = 0; } else if (do_shutdown) { - time_t wait = do_shutdown > 0 ? (int) Config.shutdownLifetime : 0; - debugs(1, 1, "Preparing for shutdown after " << statCounter.client_http.requests << " requests"); - debugs(1, 1, "Waiting " << wait << " seconds for active connections to finish"); + doShutdown(do_shutdown > 0 ? (int) Config.shutdownLifetime : 0); do_shutdown = 0; - shutting_down = 1; -#if USE_WIN32_SERVICE + } - WIN32_svcstatusupdate(SERVICE_STOP_PENDING, (wait + 1) * 1000); -#endif + PROF_stop(SignalEngine_checkEvents); + return EVENT_IDLE; +} - serverConnectionsClose(); - eventAdd("SquidShutdown", StopEventLoop, this, (double) (wait + 1), 1, false); - } +void +SignalEngine::doShutdown(time_t wait) +{ + debugs(1, 1, "Preparing for shutdown after " << statCounter.client_http.requests << " requests"); + debugs(1, 1, "Waiting " << wait << " seconds for active connections to finish"); - bool result = events_dispatched; - events_dispatched = false; - PROF_stop(SignalDispatcher_dispatch); - return result; + shutting_down = 1; + +#if USE_WIN32_SERVICE + WIN32_svcstatusupdate(SERVICE_STOP_PENDING, (wait + 1) * 1000); +#endif + + serverConnectionsClose(); + eventAdd("SquidShutdown", &StopEventLoop, this, (double) (wait + 1), 1, false); } static void @@ -1288,9 +1291,9 @@ /* main loop */ EventLoop mainLoop; - SignalDispatcher signal_dispatcher(mainLoop); + SignalEngine signalEngine(mainLoop); - mainLoop.registerDispatcher(&signal_dispatcher); + mainLoop.registerEngine(&signalEngine); /* TODO: stop requiring the singleton here */ mainLoop.registerEngine(EventScheduler::GetInstance());