|
Anklang-0.3.0.dev712+gdc4e642f anklang-0.3.0.dev712+gdc4e642f
ASE — Anklang Sound Engine (C++)
« « « Anklang Documentation |
Loop implementation with internal state. More...
Classes | |
| struct | MakeSharedAllocator_ |
Public Types | |
| typedef std::vector< LoopSourceP > | SourceList |
Public Types inherited from Ase::Loop | |
| typedef std::function< void(void)> | VoidSlot |
| typedef std::function< bool(void)> | BoolSlot |
| typedef std::function< void(PollFD &)> | VPfdSlot |
| typedef std::function< bool(PollFD &)> | BPfdSlot |
| typedef std::function< bool(const LoopState &)> | DispatcherSlot |
| typedef std::function< bool(int8)> | USignalSlot |
| typedef std::function< void(int, int)> | SigchldSlot |
Public Member Functions | |
| bool | finishable_L () |
| int | run () override |
| Run the event loop. | |
| bool | running () override |
| Indicates if quit() has been called already. | |
| void | wakeup () override |
| Wake up the event loop. | |
| void | quit (int quit_code) override |
| Stop the event loop. | |
| bool | finishable () override |
| Indicates wether this loop has no primary sources left to process. | |
| bool | iterate (bool may_block) override |
| Iterate the main loop once. | |
| void | iterate_pending () override |
| Iterate pending sources. | |
| bool | pending () override |
| Check if iterate() needs to be called for dispatching. | |
| bool | set_g_main_context (GlibGMainContext *glib_main_context) override |
| Set context to integrate with a GLib GMainContext loop. | |
| bool | has_quit () override |
| Check if quit() has been called. | |
| bool | iterate_loops_Lm (LoopState &, bool b, bool d) |
| void | destroy_loop () override |
| Remove all sources from a loop and prevent any further execution. | |
| LoopSourceP & | find_first_L () |
| LoopSourceP & | find_source_L (LoopID id) |
| bool | has_primary_L (void) |
| void | remove_source_Lm (LoopSourceP source) |
| void | kill_sources_Lm (void) |
| void | unpoll_sources_U () |
| void | collect_sources_Lm (LoopState &) |
| bool | prepare_sources_Lm (LoopState &, std::vector< PollFD > &) |
| bool | check_sources_Lm (LoopState &, const std::vector< PollFD > &) |
| void | dispatch_source_Lm (LoopState &) |
| void | process_atomic_stacks () |
| LoopID | add_source (LoopSourceP loop_source, LoopPriority priority) override |
| Add an event source to the loop. | |
| void | cancel (LoopID id) override |
| Cancel an event source. | |
| void | cancel (LoopID *idp) override |
| Cancel an event source. | |
| bool | has_primary () override |
| Indicates whether loop contains primary sources. | |
| LoopID | exec_sigchld (int64_t pid, const SigchldSlot &vfunc, LoopPriority priority) override |
| Execute a signal callback for prepare, check, dispatch. | |
| bool | exec_once (uint delay_ms, LoopID *once_id, const VoidSlot &vfunc, LoopPriority priority) override |
Execute a callback once on SIGCHLD for pid. | |
Public Member Functions inherited from Ase::Loop | |
| LoopID | exec_dispatcher (const DispatcherSlot &sl, LoopPriority priority=LoopPriority::NORMAL) |
| LoopID | exec_usignal (int8 signum, const USignalSlot &sl, LoopPriority priority=LoopPriority::USIGNAL) |
| Execute a single dispatcher callback for prepare, check, dispatch. | |
| template<IsLoopCallback Func> | |
| LoopID | add (Func &&func, std::chrono::milliseconds interval=std::chrono::milliseconds(0), LoopPriority priority=LoopPriority::NORMAL) |
| template<IsLoopCallback Func> requires IsAwaitable<std::invoke_result_t<Coroutine>> | |
| LoopID | add (Func &&func, LoopPriority priority) |
|
template<class Coroutine > requires IsAwaitable<std::invoke_result_t<Coroutine>> | |
| LoopID | add (Coroutine &&coroutine, LoopPriority priority=LoopPriority::NORMAL) |
| template<class BoolVoidPollFunctor > | |
| LoopID | exec_io_handler (BoolVoidPollFunctor &&bvf, int fd, const String &mode, LoopPriority priority=LoopPriority::NORMAL) |
| Execute a callback after polling for mode on fd, returning true repeats callback. | |
| template<typename Result > | |
| std::shared_ptr< Promise< Result > > | make_promise (const std::function< void(std::function< void(Result)>)> &executor) |
| Create promise and immediately run executor. | |
| std::shared_ptr< Promise< void > > | make_promise (const std::function< void(std::function< void()>)> &executor) |
| Create promise and immediately run executor. | |
| std::shared_ptr< Promise< uint64_t > > | delay (std::chrono::milliseconds ms) |
Create a promise that resolves after ms milliseconds and returns the elapsed delay. | |
Public Member Functions inherited from std::enable_shared_from_this< Loop > | |
| T | enable_shared_from_this (T... args) |
| T | operator= (T... args) |
| T | shared_from_this (T... args) |
| T | weak_from_this (T... args) |
| T | ~enable_shared_from_this (T... args) |
Static Public Member Functions | |
| template<typename ... Args> | |
| static std::shared_ptr< LoopImpl > | make_shared (Args &&...args) |
Static Public Member Functions inherited from Ase::Loop | |
| static LoopP | current () |
| Return the thread-local singleton loop, created on first call. | |
Public Attributes | |
| SourceList | sources_ |
| std::vector< LoopSourceP > | poll_sources_ |
| AtomicStack< LoopSourceP > | pending_add_stack_ |
| AtomicStack< LoopID > | pending_cancel_stack_ |
| std::atomic< int16_t > | quit_code_ |
| uint | running_ |
| uint | rr_index_ |
| int16 | dispatch_priority_ |
| EventFd | eventfd_ |
| GlibGMainContext * | gcontext_ |
Additional Inherited Members |
|
overridevirtual |
Add an event source to the loop.
This method adds a LoopSource to the event loop with a specified priority. The source will be monitored and dispatched according to its implementation and the loop's iteration logic. This method is thread-safe and can be called from any thread. If the loop is currently blocked in a poll() call, it will be woken up to process the new source.
| source | The event source to add. |
| priority | The priority at which the source should be dispatched. |
LoopID for the added source, or LoopID::INVALID on failure. Implements Ase::Loop.
Definition at line 185 of file loop.cc.
References assert_return, uint16_t, and wakeup().
Referenced by exec_sigchld().
|
overridevirtual |
Cancel an event source.
This method removes a source from the loop using its unique LoopID. If the source is currently being dispatched, it will be removed after the dispatch callback returns. This method is thread-safe.
| idp | Pointer to the unique ID of the source to cancel. The ID will be reset to INVALID (0). |
Implements Ase::Loop.
Definition at line 237 of file loop.cc.
References cancel().
|
overridevirtual |
Cancel an event source.
This method removes a source from the loop using its unique LoopID. If the source is currently being dispatched, it will be removed after the dispatch callback returns. This method is thread-safe.
| id | The unique ID of the source to cancel. |
Implements Ase::Loop.
Definition at line 222 of file loop.cc.
References Ase::AtomicStack< Value, GrowOnlyAllocator >::push(), return_unless, and wakeup().
Referenced by cancel(), and exec_once().
| bool Ase::LoopImpl::check_sources_Lm | ( | LoopState & | state, |
| const std::vector< PollFD > & | pfda | ||
| ) |
|
overridevirtual |
Remove all sources from a loop and prevent any further execution.
The destroy_loop() method removes all sources from a loop and in case of a sub Loop (see create_sub_loop()) removes it from its associated main loop. Calling destroy_loop() on a main loop also calls destroy_loop() for all its sub loops. Note that LoopImpl objects are artificially kept alive until LoopImpl::destroy_loop() is called, so calling destroy_loop() is mandatory for LoopImpl objects to prevent object leaks.
Implements Ase::Loop.
Definition at line 358 of file loop.cc.
References set_g_main_context().
|
overridevirtual |
Execute a callback once on SIGCHLD for pid.
Execute a callback once, re-schedules the callback if 0 != *once_id.
Implements Ase::Loop.
Definition at line 247 of file loop.cc.
References assert_return, cancel(), std::vector::push_back(), uint16_t, uint64_t, and wakeup().
|
overridevirtual |
Execute a signal callback for prepare, check, dispatch.
Implements Ase::Loop.
Definition at line 280 of file loop.cc.
References add_source().
| LoopSourceP & Ase::LoopImpl::find_first_L | ( | ) |
| LoopSourceP & Ase::LoopImpl::find_source_L | ( | LoopID | id | ) |
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
Iterate the main loop once.
LoopImpl::iterate() is the heart of the main event loop. For loop iteration, all event sources are polled for incoming events. Then dispatchable sources are picked one per iteration and dispatched in round-robin fashion. If no sources need immediate dispatching and may_block is true, iterate() will wait for events to become available.
| may_block | If true, iterate() will wait for events occour. |
Implements Ase::Loop.
|
overridevirtual |
|
static |
|
overridevirtual |
| bool Ase::LoopImpl::prepare_sources_Lm | ( | LoopState & | state, |
| std::vector< PollFD > & | pfda | ||
| ) |
|
overridevirtual |
Stop the event loop.
This method signals the event loop to stop processing events and exit its run() method. The provided quit_code will be the return value of Loop::run(). This method is safe to call from any thread.
| quit_code | The exit code for the loop to return. |
Implements Ase::Loop.
Definition at line 420 of file loop.cc.
References wakeup().
| void Ase::LoopImpl::remove_source_Lm | ( | LoopSourceP | source | ) |
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
Set context to integrate with a GLib GMainContext loop.
Implements Ase::Loop.
Definition at line 497 of file loop.cc.
Referenced by destroy_loop().
|
overridevirtual |
Wake up the event loop.
This method wakes up the event loop if it is currently blocked waiting for events. It is safe to call from any thread.
Implements Ase::Loop.
Definition at line 372 of file loop.cc.
References Ase::EventFd::opened(), and Ase::EventFd::wakeup().
Referenced by add_source(), cancel(), exec_once(), and quit().
| AtomicStack<LoopSourceP> Ase::LoopImpl::pending_add_stack_ |
| AtomicStack<LoopID> Ase::LoopImpl::pending_cancel_stack_ |
| std::vector<LoopSourceP> Ase::LoopImpl::poll_sources_ |
| std::atomic<int16_t> Ase::LoopImpl::quit_code_ |
| SourceList Ase::LoopImpl::sources_ |