]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/EventLoop.h
1f579cb0bebc3a407d256d303256fc391a917dbc
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 #ifndef SQUID_EVENTLOOP_H
10 #define SQUID_EVENTLOOP_H
12 #include "time/forward.h"
16 #define EVENT_LOOP_TIMEOUT 1000 /* 1s timeout */
20 /** An event loop. An event loop is the core inner loop of squid.
21 * The event loop can be run until exit, or once. After it finishes control
22 * returns to the caller. If desired it can be run again.
24 * The event loop cannot be run once it is running until it has finished.
32 /** register an async engine which will be given the opportunity to perform
33 * in-main-thread tasks each event loop.
35 void registerEngine(AsyncEngine
*engine
);
37 /** start the event loop running. The loop will run until it is stopped by
38 * calling stop(), or when the loop is completely idle - nothing
39 * dispatched in a loop, and all engines idle.
43 /** run the loop once. This may not complete all events! It should therefor
45 * TODO: signal in runOnce whether or not the loop is over - IDLE vs OK vs
50 /** set the primary async engine. The primary async engine receives the
51 * lowest requested timeout gathered from the other engines each loop.
52 * (There is a default of 10ms if all engines are idle or request higher
54 * If no primary has been nominated, the last async engine added is
55 * implicitly the default.
57 void setPrimaryEngine(AsyncEngine
* engine
);
59 /** set the time service. There can be only one time service set at any
60 * time. The time service is invoked on each loop
62 void setTimeService(Time::Engine
*);
64 /** stop the event loop - it will finish the current loop and then return to the
71 /// the [main program] loop running now; may be nil
72 /// for simplicity, we assume there are no concurrent loops
73 static EventLoop
*Running
;
76 /** setup state variables prior to running */
79 /** check an individual engine */
80 void checkEngine(AsyncEngine
* engine
, bool const primary
);
82 /** dispatch calls and events scheduled during checkEngine() */
86 typedef std::vector
<AsyncEngine
*> engine_vector
;
87 engine_vector engines
;
88 Time::Engine
*timeService
;
89 AsyncEngine
* primaryEngine
;
90 int loop_delay
; /**< the delay to be given to the primary engine */
91 bool error
; /**< has an error occurred in this loop */
92 bool runOnceResult
; /**< the result from runOnce */
95 #endif /* SQUID_EVENTLOOP_H */