#include <EventLoop.h>

Inheritance diagram for EventLoop:
Collaboration diagram for EventLoop:

Public Member Functions

 EventLoop ()
void registerEngine (AsyncEngine *engine)
void run ()
bool runOnce ()
void setPrimaryEngine (AsyncEngine *engine)
void setTimeService (Time::Engine *)
void stop ()

Public Attributes

int errcount

Static Public Attributes

static EventLoopRunning = nullptr

Private Types

typedef std::vector< AsyncEngine * > engine_vector

Private Member Functions

void prepareToRun ()
void checkEngine (AsyncEngine *engine, bool const primary)
bool dispatchCalls ()

Private Attributes

bool last_loop
engine_vector engines
int loop_delay
bool error
bool runOnceResult

Detailed Description

An event loop. An event loop is the core inner loop of squid. The event loop can be run until exit, or once. After it finishes control returns to the caller. If desired it can be run again.

The event loop cannot be run once it is running until it has finished.

Definition at line 26 of file EventLoop.h.

Member Typedef Documentation

◆ engine_vector

Definition at line 86 of file EventLoop.h.

Constructor & Destructor Documentation

◆ EventLoop()

EventLoop::EventLoop ( )

Definition at line 21 of file EventLoop.cc.

Member Function Documentation

◆ checkEngine()

void EventLoop::checkEngine ( AsyncEngine engine,
bool const  primary 

check an individual engine

Definition at line 29 of file EventLoop.cc.

References AsyncEngine::checkEvents(), debugs, error, AsyncEngine::EVENT_ERROR, AsyncEngine::EVENT_IDLE, fatal_dump(), loop_delay, and runOnceResult.

Referenced by runOnce().

◆ dispatchCalls()

bool EventLoop::dispatchCalls ( )

dispatch calls and events scheduled during checkEngine()

Definition at line 142 of file EventLoop.cc.

References AsyncCallQueue::fire(), and AsyncCallQueue::Instance().

Referenced by runOnce().

◆ prepareToRun()

void EventLoop::prepareToRun ( )

setup state variables prior to running

Definition at line 63 of file EventLoop.cc.

References errcount, and last_loop.

Referenced by run().

◆ registerEngine()

void EventLoop::registerEngine ( AsyncEngine engine)

register an async engine which will be given the opportunity to perform in-main-thread tasks each event loop.

Definition at line 70 of file EventLoop.cc.

References engines.

Referenced by StockEventLoop::StockEventLoop(), Adaptation::Ecap::ServiceRep::makeXactLauncher(), SquidMain(), TestEventLoop::testEngineErrors(), TestEventLoop::testEngineTimeout(), TestEventLoop::testRunOnce(), and TestEventLoop::testSetPrimaryEngine().

◆ run()

void EventLoop::run ( )

start the event loop running. The loop will run until it is stopped by calling stop(), or when the loop is completely idle - nothing dispatched in a loop, and all engines idle.

Definition at line 76 of file EventLoop.cc.

References assert, prepareToRun(), Running, and runOnce().

Referenced by SquidMain(), TestRock::storeInit(), TestEventLoop::testEngineErrors(), TestRock::testRockSwapOut(), and TestEventLoop::testRunOnce().

◆ runOnce()

bool EventLoop::runOnce ( )

run the loop once. This may not complete all events! It should therefor be used with care. TODO: signal in runOnce whether or not the loop is over - IDLE vs OK vs TIMEOUT?

Definition at line 89 of file EventLoop.cc.

References checkEngine(), DBG_CRITICAL, debugs, dispatchCalls(), engines, errcount, error, EVENT_LOOP_TIMEOUT, last_loop, loop_delay, primaryEngine, runOnceResult, Time::Engine::tick(), and timeService.

Referenced by run(), TestEventLoop::testEngineErrors(), TestEventLoop::testEngineTimeout(), TestEventLoop::testRunOnce(), TestEventLoop::testSetPrimaryEngine(), TestEventLoop::testSetTimeService(), and TestUfs::testUfsSearch().

◆ setPrimaryEngine()

void EventLoop::setPrimaryEngine ( AsyncEngine engine)

set the primary async engine. The primary async engine receives the lowest requested timeout gathered from the other engines each loop. (There is a default of 10ms if all engines are idle or request higher delays). If no primary has been nominated, the last async engine added is implicitly the default.

Definition at line 149 of file EventLoop.cc.

References engines, fatal(), and primaryEngine.

Referenced by SquidMain(), and TestEventLoop::testSetPrimaryEngine().

◆ setTimeService()

void EventLoop::setTimeService ( Time::Engine engine)

set the time service. There can be only one time service set at any time. The time service is invoked on each loop

Definition at line 162 of file EventLoop.cc.

References timeService.

Referenced by StockEventLoop::StockEventLoop(), SquidMain(), and TestEventLoop::testSetTimeService().

◆ stop()

void EventLoop::stop ( )

stop the event loop - it will finish the current loop and then return to the caller of run().

Definition at line 168 of file EventLoop.cc.

References last_loop.

Referenced by SignalEngine::StopEventLoop().

Member Data Documentation

◆ engines

engine_vector EventLoop::engines

Definition at line 87 of file EventLoop.h.

Referenced by registerEngine(), runOnce(), and setPrimaryEngine().

◆ errcount

int EventLoop::errcount

Definition at line 69 of file EventLoop.h.

Referenced by prepareToRun(), runOnce(), SquidMain(), and TestEventLoop::testEngineErrors().

◆ error

bool EventLoop::error

has an error occurred in this loop

Definition at line 91 of file EventLoop.h.

Referenced by checkEngine(), and runOnce().

◆ last_loop

bool EventLoop::last_loop

Definition at line 85 of file EventLoop.h.

Referenced by prepareToRun(), runOnce(), and stop().

◆ loop_delay

int EventLoop::loop_delay

the delay to be given to the primary engine

Definition at line 90 of file EventLoop.h.

Referenced by checkEngine(), and runOnce().

◆ primaryEngine

AsyncEngine* EventLoop::primaryEngine

Definition at line 89 of file EventLoop.h.

Referenced by runOnce(), and setPrimaryEngine().

◆ Running

EventLoop * EventLoop::Running = nullptr

the [main program] loop running now; may be nil for simplicity, we assume there are no concurrent loops

Definition at line 73 of file EventLoop.h.

Referenced by Adaptation::Ecap::ServiceRep::makeXactLauncher(), run(), and SignalEngine::StopEventLoop().

◆ runOnceResult

bool EventLoop::runOnceResult

the result from runOnce

Definition at line 92 of file EventLoop.h.

Referenced by checkEngine(), and runOnce().

◆ timeService

Time::Engine* EventLoop::timeService

Definition at line 88 of file EventLoop.h.

Referenced by runOnce(), and setTimeService().

The documentation for this class was generated from the following files:






Web Site Translations