#include <Pt/System/EventLoop.h>
Event loop of a thread or process. More...
Inherits Connectable, and EventSink.
Inherited by MainLoop.
Public Member Functions | |
| virtual | ~EventLoop () |
| Destructor. | |
| void | run () |
| Starts the loop. | |
| void | exit () |
| Stops the loop. | |
| void | processEvents () |
| Process all queued events. | |
| Signal< const Event & > & | eventReceived () |
| Reports all events. | |
| Signal & | exited () |
| Emited when the eventloop is exited. | |
| AsyncYield | yieldAsync () |
| Pauses a coroutine and delegates execution back to the loop. | |
| void | post (Selectable &s) |
| Posts the loop to run a selectable. | |
| void | setReady (Selectable &s) |
| Sets the Selectable as ready without waking the loop. | |
| void | commitEvent (const Event &ev) |
| Queues an event and triggers event processing. | |
| void | queueEvent (const Event &ev) |
| Only queues an event. | |
| void | wake () |
| Triggers event processing. | |
Protected Member Functions | |
| virtual void | onCommitEvent (const Event &ev)=0 |
| Queues an event and triggers event processing. | |
| virtual void | onQueueEvent (const Event &ev)=0 |
| Only queues an event. | |
| virtual void | onWake ()=0 |
| Triggers event processing. | |
EventLoop is the dispatch core of a thread or process. It monitors Selectable objects and Timer objects and delivers queued events. A process often runs one loop in the main thread. A second loop can run in another Thread.
The loop is an EventSink. commitEvent() queues an event and wakes the loop. queueEvent() queues without waking, so several events can be added and then released with one wake(). Events are delivered on eventReceived in the thread that called run(), in the order they were queued.
run() enters the loop and returns when exit() stops it. processEvents() delivers queued events without entering run(). exited is emitted when the loop leaves run(). Delivery always happens in the loop thread, including events queued from other threads.
| AsyncYield yieldAsync | ( | ) |
| void post | ( | Selectable & | s | ) |
The event loop is woken up and the selectable's run function is called in the event loop thread. This function may be called from any thread, especially from a selectable, that is based on a parallel execution model e.g. using a worker thread.