MainLoop Class Reference

#include <Pt/System/MainLoop.h>

Platform event loop. More...

Inherits EventLoop.

Public Member Functions

 MainLoop ()
 Default Constructor.
 MainLoop (Allocator &a)
 Construct with allocator.
virtual ~MainLoop ()
 Destructor.
void run ()
 Starts the loop.
void exit ()
 Stops the loop.
void processEvents ()
 Process all queued events.
Signal< const Event & > & eventReceived ()
 Reports all events.
Signalexited ()
 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)
 Queues an event and triggers event processing.
virtual void onQueueEvent (const Event &ev)
 Only queues an event.
virtual void onWake ()
 Triggers event processing.

Detailed Description

MainLoop is the EventLoop implementation for the platform. It multiplexes I/O and timers. Application creates one by default. Construct a MainLoop directly when the process has no Application, or when a second loop runs in another thread.

Member Function Documentation

◆ yieldAsync()

AsyncYield yieldAsync ( )
inherited
Returns
C++20 awaitable yielding execution to the loop processing queue.

◆ post()

void post ( Selectable & s)
inherited

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.