From 9688b0aee3c5c1989873b5ef9f0c2071107af5ef Mon Sep 17 00:00:00 2001 From: rousskov <> Date: Wed, 13 Feb 2008 06:57:47 +0000 Subject: [PATCH] Merging async-call branch changes to HEAD: Async-call work replaces event-based asynchronous calls with stand-alone implementation. The common async call API allows Squid core do call, debug, and troubleshoot all callback handlers in a uniform way. An async "job" API is introduced to manage independent logical threads or work such as protocol transaction handlers on client, server, and ICAP sides. These jobs should communicate with each other using async calls to minimize dependencies and avoid reentrant callback loops. These changes will eventually improve overall code quality, debugging quality, and Squid robustness. Below you will find log messages from the async-call branch that are relevant to the file(s) being committed. Removed CommDispatcher as unused. Use async calls for firing ready events. Deleted EventDispatcher as unused. Converted CompletionDispatcher-based SignalDispatcher into AsyncEngine-based SignalEngine to get rid of CompletionDispatchers. --- src/main.cc | 64 +++++++++++++++++++++++++---------------------------- 1 file changed, 30 insertions(+), 34 deletions(-) diff --git a/src/main.cc b/src/main.cc index e96beca6d4..9b2c56e283 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,6 +1,6 @@ /* - * $Id: main.cc,v 1.456 2008/01/24 19:20:43 serassio Exp $ + * $Id: main.cc,v 1.457 2008/02/12 23:57:47 rousskov Exp $ * * DEBUG: section 1 Startup and Main Loop * AUTHOR: Harvest Derived @@ -143,29 +143,28 @@ public: }; }; -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) { - static_cast(data)->loop.stop(); + 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(); @@ -174,24 +173,28 @@ SignalDispatcher::dispatch() 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 @@ -1289,12 +1292,9 @@ main(int argc, char **argv) /* main loop */ EventLoop mainLoop; - SignalDispatcher signal_dispatcher(mainLoop); + SignalEngine signalEngine(mainLoop); - mainLoop.registerDispatcher(&signal_dispatcher); - - /* TODO: stop requiring the singleton here */ - mainLoop.registerDispatcher(EventDispatcher::GetInstance()); + mainLoop.registerEngine(&signalEngine); /* TODO: stop requiring the singleton here */ mainLoop.registerEngine(EventScheduler::GetInstance()); @@ -1303,10 +1303,6 @@ main(int argc, char **argv) mainLoop.registerEngine(&store_engine); - CommDispatcher comm_dispatcher; - - mainLoop.registerDispatcher(&comm_dispatcher); - CommSelectEngine comm_engine; mainLoop.registerEngine(&comm_engine); -- 2.47.2