]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/EventLoop.h
3d5151fbd55d1c355343a6270c82b66360066c9c
2 * Copyright (C) 1996-2016 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
14 #define EVENT_LOOP_TIMEOUT 1000 /* 1s timeout */
19 /** An event loop. An event loop is the core inner loop of squid.
20 * The event loop can be run until exit, or once. After it finishes control
21 * returns to the caller. If desired it can be run again.
23 * The event loop cannot be run once it is running until it has finished.
31 /** register an async engine which will be given the opportunity to perform
32 * in-main-thread tasks each event loop.
34 void registerEngine(AsyncEngine
*engine
);
36 /** start the event loop running. The loop will run until it is stopped by
37 * calling stop(), or when the loop is completely idle - nothing
38 * dispatched in a loop, and all engines idle.
42 /** run the loop once. This may not complete all events! It should therefor
44 * TODO: signal in runOnce whether or not the loop is over - IDLE vs OK vs
49 /** set the primary async engine. The primary async engine recieves the
50 * lowest requested timeout gathered from the other engines each loop.
51 * (There is a default of 10ms if all engines are idle or request higher
53 * If no primary has been nominated, the last async engine added is
54 * implicitly the default.
56 void setPrimaryEngine(AsyncEngine
* engine
);
58 /** set the time service. There can be only one time service set at any
59 * time. The time service is invoked on each loop
61 void setTimeService(TimeEngine
*engine
);
63 /** stop the event loop - it will finish the current loop and then return to the
70 /// the [main program] loop running now; may be nil
71 /// for simplicity, we assume there are no concurrent loops
72 static EventLoop
*Running
;
75 /** setup state variables prior to running */
78 /** check an individual engine */
79 void checkEngine(AsyncEngine
* engine
, bool const primary
);
81 /** dispatch calls and events scheduled during checkEngine() */
85 typedef std::vector
<AsyncEngine
*> engine_vector
;
86 engine_vector engines
;
87 TimeEngine
* timeService
;
88 AsyncEngine
* primaryEngine
;
89 int loop_delay
; /**< the delay to be given to the primary engine */
90 bool error
; /**< has an error occured in this loop */
91 bool runOnceResult
; /**< the result from runOnce */
94 #endif /* SQUID_EVENTLOOP_H */