Anklang-0.3.0.dev712+gdc4e642f anklang-0.3.0.dev712+gdc4e642f
ASE — Anklang Sound Engine (C++)

« « « Anklang Documentation
Loading...
Searching...
No Matches
loop.hh
Go to the documentation of this file.
1 // This Source Code Form is licensed MPL-2.0: http://mozilla.org/MPL/2.0
2#pragma once
3
4#include <ase/defs.hh>
5#include <ase/cotask.hh>
6#include <chrono>
7#include <mutex>
8#include <variant>
9
10namespace Ase {
11
12// === PollFD ===
13struct PollFD
14{
15 int fd;
16 uint16 events;
17 uint16 revents;
19 enum : uint {
20 IN = ASE_SYSVAL_POLLINIT[0],
21 PRI = ASE_SYSVAL_POLLINIT[1],
22 OUT = ASE_SYSVAL_POLLINIT[2],
23 RDNORM = ASE_SYSVAL_POLLINIT[3],
24 RDBAND = ASE_SYSVAL_POLLINIT[4],
25 WRNORM = ASE_SYSVAL_POLLINIT[5],
26 WRBAND = ASE_SYSVAL_POLLINIT[6],
27 // Event types unconditionally updated in .revents
28 ERR = ASE_SYSVAL_POLLINIT[7],
29 HUP = ASE_SYSVAL_POLLINIT[8],
30 NVAL = ASE_SYSVAL_POLLINIT[9],
31 };
32};
33
34// == LoopPriority ==
35enum class LoopPriority : uint16_t {
36 SYSALLOC = 900,
37 RTAUDIO = 800,
38 USIGNAL = 700,
39 COAWAIT = 600,
40 NOTIFY = 500,
41 AFRAME = 400,
42 NORMAL = 300,
43 IDLE = 200,
44 LOW = 100,
45};
46
47// === Prototypes ===
48class LoopSource;
49typedef std::shared_ptr<LoopSource> LoopSourceP;
50class TimedSource;
51typedef std::shared_ptr<TimedSource> TimedSourceP;
52class PollFDSource;
53typedef std::shared_ptr<PollFDSource> PollFDSourceP;
54class DispatcherSource;
55typedef std::shared_ptr<DispatcherSource> DispatcherSourceP;
56class USignalSource;
57typedef std::shared_ptr<USignalSource> USignalSourceP;
58class SigchldSource;
59typedef std::shared_ptr<SigchldSource> SigchldSourceP;
60class Loop;
61typedef std::shared_ptr<Loop> LoopP;
62struct LoopState;
63#if defined __G_LIB_H__ || defined DOXYGEN
64typedef ::GMainContext GlibGMainContext;
65#else
66struct GlibGMainContext; // dummy type
67#endif
68
69// === Concepts ===
70template<typename Func>
73
74// === Loop ===
76class Loop : public virtual std::enable_shared_from_this<Loop>
77{
78 friend class LoopImpl;
80protected:
81 explicit Loop ();
82 virtual ~Loop ();
83 virtual void destroy_loop () = 0;
84public:
85 typedef std::function<void (void)> VoidSlot;
86 typedef std::function<bool (void)> BoolSlot;
87 typedef std::function<void (PollFD&)> VPfdSlot;
91 typedef std::function<void (int,int)> SigchldSlot;
92 template<typename Result> struct Promise;
93 virtual void wakeup () = 0;
94 // source handling
95 virtual LoopID add_source (LoopSourceP loop_source, LoopPriority priority
97 virtual void cancel (LoopID id) = 0;
98 virtual void cancel (LoopID *idp) = 0;
99 virtual bool has_primary (void) = 0;
100 LoopID exec_dispatcher (const DispatcherSlot &sl, LoopPriority priority
102 LoopID exec_usignal (int8 signum, const USignalSlot &sl, LoopPriority priority
104 virtual LoopID exec_sigchld (int64_t pid, const SigchldSlot &vfunc, LoopPriority priority
105 = LoopPriority::NORMAL) = 0;
106 virtual bool exec_once (uint delay_ms, LoopID *once_id, const VoidSlot &vfunc, LoopPriority priority
107 = LoopPriority::NORMAL) = 0;
108 template<IsLoopCallback Func>
109 LoopID add (Func &&func, std::chrono::milliseconds interval = std::chrono::milliseconds (0), LoopPriority priority = LoopPriority::NORMAL);
110 template<IsLoopCallback Func>
111 LoopID add (Func &&func, LoopPriority priority);
112 template<class Coroutine> requires IsAwaitable<std::invoke_result_t<Coroutine>>
113 LoopID add (Coroutine &&coroutine, LoopPriority priority = LoopPriority::NORMAL);
115 template<class BoolVoidPollFunctor>
116 LoopID exec_io_handler (BoolVoidPollFunctor &&bvf, int fd, const String &mode, LoopPriority priority = LoopPriority::NORMAL);
117 // Event processing
118 virtual int run () = 0;
119 virtual bool running () = 0;
120 virtual bool finishable () = 0;
121 virtual void quit (int quit_code = 0) = 0;
122 virtual bool pending () = 0;
123 virtual bool iterate (bool block) = 0;
124 virtual void iterate_pending () = 0;
125 virtual bool set_g_main_context (GlibGMainContext *glib_main_context) = 0;
126 virtual bool has_quit () = 0;
127 static LoopP current ();
128 template<typename Result>
129 std::shared_ptr<Promise<Result>> make_promise (const std::function<void(std::function<void(Result)>)> &executor);
132};
133
134// === LoopState ===
135struct LoopState {
136 enum Phase { NONE, COLLECT, PREPARE, CHECK, DISPATCH, DESTROY };
137 Phase phase = NONE;
138 bool seen_primary = false;
141};
142
143// === LoopSource ===
145{
146 friend class Loop;
147 friend class LoopImpl;
149protected:
150 Loop *loop_;
151 struct {
152 PollFD *pfd;
153 uint idx;
154 } *pfds_;
155 LoopID id_;
156 int16 priority_;
157 uint8 loop_state_;
158 uint may_recurse_ : 1;
159 uint dispatching_ : 1;
160 uint was_dispatching_ : 1;
161 uint primary_ : 1;
162 uint n_pfds ();
163 explicit LoopSource ();
164 LoopID source_id () { return loop_ ? id_ : LoopID::INVALID; }
165 virtual ~LoopSource ();
166public:
167 virtual bool prepare (const LoopState &state,
168 int64 *timeout_usecs_p) = 0;
169 virtual bool check (const LoopState &state) = 0;
170 virtual bool dispatch (const LoopState &state) = 0;
171 virtual void destroy ();
172 bool recursion () const;
173 bool may_recurse () const;
174 void may_recurse (bool may_recurse);
175 bool primary () const;
176 void primary (bool is_primary);
177 void add_poll (PollFD * const pfd);
178 void remove_poll (PollFD * const pfd);
179 void loop_remove ();
180 Loop* loop () const { return loop_; }
181};
182
183// === DispatcherSource ===
184class DispatcherSource : public virtual LoopSource
185{
187 DispatcherSlot slot_;
189protected:
190 virtual ~DispatcherSource ();
191 virtual bool prepare (const LoopState &state, int64 *timeout_usecs_p);
192 virtual bool check (const LoopState &state);
193 virtual bool dispatch (const LoopState &state);
194 virtual void destroy ();
195 explicit DispatcherSource (const DispatcherSlot &slot);
196public:
197 static DispatcherSourceP create (const DispatcherSlot &slot)
198 { return make_shared (slot); }
199};
200
201// === USignalSource ===
202class USignalSource : public virtual LoopSource
203{
205 USignalSlot slot_;
206 int8 signum_ = 0, index_ = 0, shift_ = 0;
208protected:
209 virtual ~USignalSource ();
210 virtual bool prepare (const LoopState &state, int64 *timeout_usecs_p);
211 virtual bool check (const LoopState &state);
212 virtual bool dispatch (const LoopState &state);
213 virtual void destroy ();
214 explicit USignalSource (int8 signum, const USignalSlot &slot);
215public:
216 static void raise (int8 signum);
217 static USignalSourceP create (int8 signum, const USignalSlot &slot)
218 { return make_shared (signum, slot); }
219 static void install_sigaction (int8);
220};
221
222// === SigchldSource ===
223class SigchldSource : public virtual LoopSource
224{
227 SigchldSlot slot_;
228 uint64_t sigchld_counter_ = 0;
229 int64_t pid_ = 0;
230protected:
231 virtual ~SigchldSource ();
232 virtual bool prepare (const LoopState &state, int64 *timeout_usecs_p);
233 virtual bool check (const LoopState &state);
234 virtual bool dispatch (const LoopState &state);
235 virtual void destroy ();
236 explicit SigchldSource (int64_t pid, const SigchldSlot &slot);
237public:
238 static SigchldSourceP create (int64_t pid, const SigchldSlot &slot)
239 { return make_shared (pid, slot); }
240};
241
242// === TimedSource ===
243class TimedSource : public virtual LoopSource
244{
245 typedef Loop::BoolSlot BoolSlot;
246 typedef Loop::VoidSlot VoidSlot;
247 uint64 expiration_usecs_;
248 uint interval_msecs_;
249 bool first_interval_;
250 const bool oneshot_;
251 union {
252 BoolSlot bool_slot_;
253 VoidSlot void_slot_;
254 };
256protected:
257 virtual ~TimedSource ();
258 virtual bool prepare (const LoopState &state, int64 *timeout_usecs_p);
259 virtual bool check (const LoopState &state);
260 virtual bool dispatch (const LoopState &state);
261 explicit TimedSource (const BoolSlot &slot, uint initial_interval_msecs, uint repeat_interval_msecs);
262 explicit TimedSource (const VoidSlot &slot, uint initial_interval_msecs, uint repeat_interval_msecs);
263public:
264 static TimedSourceP create (const BoolSlot &slot, uint initial_interval_msecs = 0, uint repeat_interval_msecs = 0)
265 { return make_shared (slot, initial_interval_msecs, repeat_interval_msecs); }
266 static TimedSourceP create (const VoidSlot &slot, uint initial_interval_msecs = 0, uint repeat_interval_msecs = 0)
267 { return make_shared (slot, initial_interval_msecs, repeat_interval_msecs); }
268};
269
270// === PollFDSource ===
271class PollFDSource : public virtual LoopSource
272{
273 typedef Loop::BPfdSlot BPfdSlot;
274 typedef Loop::VPfdSlot VPfdSlot;
275protected:
276 void construct (const String &mode);
277 virtual ~PollFDSource ();
278 virtual bool prepare (const LoopState &state, int64 *timeout_usecs_p);
279 virtual bool check (const LoopState &state);
280 virtual bool dispatch (const LoopState &state);
281 virtual void destroy ();
282 PollFD pfd_;
283 uint never_close_ : 1; // 'C'
284private:
285 const uint oneshot_ : 1;
286 union {
287 BPfdSlot bool_poll_slot_;
288 VPfdSlot void_poll_slot_;
289 };
290 explicit PollFDSource (const BPfdSlot &slot, int fd, const String &mode);
291 explicit PollFDSource (const VPfdSlot &slot, int fd, const String &mode);
293public:
294 static PollFDSourceP create (const BPfdSlot &slot, int fd, const String &mode)
295 { return make_shared (slot, fd, mode); }
296 static PollFDSourceP create (const VPfdSlot &slot, int fd, const String &mode)
297 { return make_shared (slot, fd, mode); }
298};
299
300// === Loop methods ===
301inline LoopID
302Loop::exec_dispatcher (const DispatcherSlot &slot, LoopPriority priority)
303{
304 return add_source (DispatcherSource::create (slot), priority);
305}
306
307inline LoopID
308Loop::exec_usignal (int8 signum, const USignalSlot &slot, LoopPriority priority)
309{
310 return add_source (USignalSource::create (signum, slot), priority);
311}
312
313template<class BoolVoidPollFunctor> LoopID
314Loop::exec_io_handler (BoolVoidPollFunctor &&bvf, int fd, const String &mode, LoopPriority priority)
315{
316 using ReturnType = decltype (bvf (*std::declval<PollFD*>()));
317 std::function<ReturnType (PollFD&)> slot (bvf);
318 return add_source (PollFDSource::create (slot, fd, mode), priority);
319}
320
321template<IsLoopCallback Func> LoopID
322Loop::add (Func &&func, std::chrono::milliseconds interval, LoopPriority priority)
323{
324 using ReturnType = decltype (func());
325 std::function<ReturnType()> slot (std::forward<decltype (func)> (func));
326 const uint interval_ms = interval.count();
327 return add_source (TimedSource::create (std::move (slot), interval_ms, interval_ms), priority);
328}
329
330template<IsLoopCallback Func> LoopID
331Loop::add (Func &&func, LoopPriority priority)
332{
333 return add (std::forward<decltype (func)> (func), std::chrono::milliseconds (0), priority);
334}
335
336template<class Coroutine> requires IsAwaitable<std::invoke_result_t<Coroutine>> LoopID
337Loop::add (Coroutine &&coroutine, LoopPriority priority)
338{
339 using CoroutineType = std::decay_t<Coroutine>;
341 ASE_ASSERT_RETURN (coroutine, LoopID::INVALID);
342 // Keep Coroutine and parameters alive until after co_return
343 auto coroutine_ptr = std::make_shared<CoroutineType> (std::forward<Coroutine> (coroutine));
344 // Guarantee: coroutine will be started as a loop callback
345 auto start_coroutine = [coroutine_ptr] ()
346 {
347 // dprintf (2, "%s: start loop_coawait…\n", "start_coroutine");
348 static auto loop_coawait = [] (auto coroutine_ptr) -> DetachedTask
349 {
350 // dprintf (2, "%s: co_await…\n", "loop_coawait");
351 co_await (*coroutine_ptr) ();
352 // dprintf (2, "%s: co_return…\n", "loop_coawait");
353 co_return;
354 };
355 loop_coawait (coroutine_ptr);
356 // dprintf (2, "%s: done, return false\n", "start_coroutine");
357 return false;
358 };
359 return this->add (start_coroutine, std::chrono::milliseconds (0), priority);
360}
361
362// === Loop::Promise ===
363template<typename Result>
365 // If Result is void, we store std::monostate in the 'Resolved' slot
367 // The State Variant: { Pending | Resolved | Rejected }
372 bool
373 await_ready() const noexcept
374 {
375 // No lock, state_ is stable once not 0
376 return promise_->state_.index() > 0;
377 }
378 bool
379 await_suspend (std::coroutine_handle<> waiter) noexcept
380 {
381 std::unique_lock lock (promise_->mtx_);
382 if (promise_->state_.index() > 0)
383 return false; // already resolved
384 promise_->waiters_.push_back (waiter); // caller to resume on resolve()
385 return true; // caller suspended
386 }
387 Result
388 await_resume()
389 {
390 ASE_ASSERT_WARN (promise_->state_.index() > 0);
391 // No lock, state_ is stable once not 0
392 if (auto *ex = std::get_if<2> (&promise_->state_))
393 ase_rethrow (*ex);
394 if constexpr (std::is_void_v<Result>)
395 return; // Nothing to return
396 else
397 // move-only results are empty after first awaiter
398 return std::move (std::get<1> (promise_->state_));
399 }
400 };
403 operator co_await() noexcept
404 {
405 return PromiseAwaiter (this->shared_from_this());
406 }
407
409 template<typename T = Result> requires (!std::is_void_v<T>) void
410 resolve (T &&value)
411 {
412 resolve_impl (StateVariant (std::in_place_index<1>, std::forward<T> (value)));
413 }
415 template<typename T = Result> requires (std::is_void_v<T>) void
417 {
419 }
421 void
423 {
424 if (!exc)
425 exc = std::make_exception_ptr (std::runtime_error ("Promise rejected"));
426 resolve_impl (StateVariant {std::in_place_index<2>, exc});
427 }
428 ~Promise() {}
429private:
430 friend class Loop;
431 std::mutex mtx_;
432 StateVariant state_;
433 Loop *loop_;
435 explicit Promise (Loop &loop) : loop_ (&loop) {}
436 // State transition to non-pending with new std::variant
437 void
438 resolve_impl (StateVariant &&new_state)
439 {
440 std::vector<std::coroutine_handle<>> waiters_to_notify;
441 {
442 std::lock_guard lock (mtx_);
443 if (state_.index() != 0) return; // Already resolved/rejected
444 state_ = std::move (new_state);
445 waiters_to_notify.swap (waiters_);
446 } // guard released
447 auto keep_alive = this->shared_from_this();
448 for (auto h : waiters_to_notify)
449 if (h && !h.done())
450 loop_->add ([h, keep_alive]
451 {
452 if (!h.done())
453 h.resume();
454 return false; // one-shot
456 }
457};
458
459template<typename Result>
460using LoopPromiseP = std::shared_ptr<Loop::Promise<Result>>;
461
462template<typename T> auto
463operator co_await (LoopPromiseP<T> p)
464{
465 return p->operator co_await();
466}
467
469template<typename Result> std::shared_ptr<Loop::Promise<Result>>
470Loop::make_promise (const std::function<void(std::function<void(Result)>)> &executor)
471{
472 struct EnableMakeShared : Promise<Result> {
473 EnableMakeShared (Loop &l) : Promise<Result> (l) {}
474 };
475 auto promisep = std::make_shared<EnableMakeShared> (*this);
476 auto resolver = [promisep] (Result value) { promisep->resolve (value); };
477 try {
478 executor (resolver);
479 } catch (...) {
480 promisep->reject (std::current_exception());
481 }
482 return promisep;
483}
484
487Loop::make_promise (const std::function<void(std::function<void()>)> &executor)
488{
489 struct EnableMakeShared : Promise<void> {
490 EnableMakeShared (Loop &l) : Promise<void> (l) {}
491 };
492 auto promisep = std::make_shared<EnableMakeShared> (*this);
493 auto resolver = [promisep] () { promisep->resolve(); };
494 try {
495 executor (resolver);
496 } catch (...) {
497 promisep->reject (std::current_exception());
498 }
499 return promisep;
500}
501
502} // Ase
Loop source for handler execution.
Definition loop.hh:185
virtual bool dispatch(const LoopState &state)
Dispatch source, returns if it should be kept alive.
Definition loop.cc:925
virtual bool prepare(const LoopState &state, int64 *timeout_usecs_p)
Prepare the source for dispatching (true return) or polling (false).
Definition loop.cc:913
virtual bool check(const LoopState &state)
Check the source and its PollFD descriptors for dispatching (true return).
Definition loop.cc:919
Loop implementation with internal state.
Definition loop.cc:75
Loop source for callback execution.
Definition loop.hh:145
virtual bool prepare(const LoopState &state, int64 *timeout_usecs_p)=0
Prepare the source for dispatching (true return) or polling (false).
bool recursion() const
Indicates wether the source is currently in recursion.
Definition loop.cc:846
virtual bool check(const LoopState &state)=0
Check the source and its PollFD descriptors for dispatching (true return).
void add_poll(PollFD *const pfd)
Add a PollFD descriptors for poll(2) and check().
Definition loop.cc:852
bool primary() const
Indicate whether this source is primary.
Definition loop.cc:834
Loop * loop() const
Get the main loop for this source.
Definition loop.hh:180
virtual bool dispatch(const LoopState &state)=0
Dispatch source, returns if it should be kept alive.
bool may_recurse() const
Indicates if this source may recurse.
Definition loop.cc:828
void loop_remove()
Remove this source from its event loop if any.
Definition loop.cc:889
void remove_poll(PollFD *const pfd)
Remove a previously added PollFD.
Definition loop.cc:866
Loop object, polling for events and executing callbacks in accordance.
Definition loop.hh:77
std::shared_ptr< Promise< uint64_t > > delay(std::chrono::milliseconds ms)
Create a promise that resolves after ms milliseconds and returns the elapsed delay.
Definition loop.cc:314
virtual void cancel(LoopID id)=0
Cancel a source and remove it from the loop.
virtual bool set_g_main_context(GlibGMainContext *glib_main_context)=0
Set context to integrate with a GLib GMainContext loop.
virtual void quit(int quit_code=0)=0
Cause run() to return with quit_code.
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.
Definition loop.hh:314
virtual void iterate_pending()=0
Call iterate() until no immediate dispatching is needed.
LoopID exec_usignal(int8 signum, const USignalSlot &sl, LoopPriority priority=LoopPriority::USIGNAL)
Execute a single dispatcher callback for prepare, check, dispatch.
Definition loop.hh:308
virtual int run()=0
Run loop iterations until a call to quit() or finishable becomes true.
virtual LoopID exec_sigchld(int64_t pid, const SigchldSlot &vfunc, LoopPriority priority=LoopPriority::NORMAL)=0
Execute a signal callback for prepare, check, dispatch.
virtual bool iterate(bool block)=0
Perform one loop iteration and return whether more iterations are needed.
virtual bool finishable()=0
Indicates wether this loop has no primary sources left to process.
virtual LoopID add_source(LoopSourceP loop_source, LoopPriority priority=LoopPriority::NORMAL)=0
Adds a new source to the loop with custom priority.
virtual bool has_primary(void)=0
Indicates whether loop contains primary sources.
virtual bool exec_once(uint delay_ms, LoopID *once_id, const VoidSlot &vfunc, LoopPriority priority=LoopPriority::NORMAL)=0
Execute a callback once on SIGCHLD for pid.
static LoopP current()
Return the thread-local singleton loop, created on first call.
Definition loop.cc:306
virtual void wakeup()=0
Wakeup loop from polling.
virtual bool pending()=0
Check if iterate() needs to be called for dispatching.
virtual void cancel(LoopID *idp)=0
Cancel a source by id if present and resets the id.
virtual bool running()=0
Indicates if quit() has been called already.
std::shared_ptr< Promise< Result > > make_promise(const std::function< void(std::function< void(Result)>)> &executor)
Create promise and immediately run executor.
Definition loop.hh:470
virtual bool has_quit()=0
Check if quit() has been called.
Loop source for IO callbacks.
Definition loop.hh:272
virtual bool dispatch(const LoopState &state)
Dispatch source, returns if it should be kept alive.
Definition loop.cc:1221
virtual bool prepare(const LoopState &state, int64 *timeout_usecs_p)
Prepare the source for dispatching (true return) or polling (false).
Definition loop.cc:1208
virtual bool check(const LoopState &state)
Check the source and its PollFD descriptors for dispatching (true return).
Definition loop.cc:1215
Loop source for handler execution.
Definition loop.hh:224
virtual bool dispatch(const LoopState &state)
Dispatch source, returns if it should be kept alive.
Definition loop.cc:1060
virtual bool prepare(const LoopState &state, int64 *timeout_usecs_p)
Prepare the source for dispatching (true return) or polling (false).
Definition loop.cc:1048
virtual bool check(const LoopState &state)
Check the source and its PollFD descriptors for dispatching (true return).
Definition loop.cc:1054
Loop source for timer execution.
Definition loop.hh:244
virtual bool check(const LoopState &state)
Check the source and its PollFD descriptors for dispatching (true return).
Definition loop.cc:1125
virtual bool prepare(const LoopState &state, int64 *timeout_usecs_p)
Prepare the source for dispatching (true return) or polling (false).
Definition loop.cc:1110
virtual bool dispatch(const LoopState &state)
Dispatch source, returns if it should be kept alive.
Definition loop.cc:1131
Loop source for handler execution.
Definition loop.hh:203
virtual bool dispatch(const LoopState &state)
Dispatch source, returns if it should be kept alive.
Definition loop.cc:977
virtual bool prepare(const LoopState &state, int64 *timeout_usecs_p)
Prepare the source for dispatching (true return) or polling (false).
Definition loop.cc:965
static void raise(int8 signum)
Flag a unix signal being raised, this function may be called from any thread at any time.
Definition loop.cc:956
virtual bool check(const LoopState &state)
Check the source and its PollFD descriptors for dispatching (true return).
Definition loop.cc:971
Concept: Is T an awaitable?
Definition cotask.hh:14
T current_exception(T... args)
#define ASE_ASSERT_RETURN(expr,...)
Return from the current function if expr evaluates to false and issue an assertion warning.
Definition cxxaux.hh:82
#define ASE_DEFINE_MAKE_SHARED(CLASS)
Define a member function static shared_ptr<CLASS> make_shared(ctorargs...);.
Definition cxxaux.hh:274
#define ASE_ASSERT_WARN(expr)
Issue an assertion warning if expr evaluates to false.
Definition cxxaux.hh:94
#define ASE_CLASS_NON_COPYABLE(ClassName)
Delete copy ctor and assignment operator.
Definition cxxaux.hh:111
T forward(T... args)
T make_exception_ptr(T... args)
The Anklang C++ API namespace.
Definition api.hh:9
uint64_t uint64
A 64-bit unsigned integer, use PRI*64 in format strings.
Definition cxxaux.hh:25
int16_t int16
A 16-bit signed integer.
Definition cxxaux.hh:27
uint8_t uint8
An 8-bit unsigned integer.
Definition cxxaux.hh:22
int8_t int8
An 8-bit signed integer.
Definition cxxaux.hh:26
int64_t int64
A 64-bit unsigned integer, use PRI*64 in format strings.
Definition cxxaux.hh:29
LoopPriority
Definition loop.hh:35
@ NORMAL
Normal importantance, GUI event processing, RPC.
@ USIGNAL
Used for unix signal delivery.
@ LOW
Unimportant, used when everything else done.
@ NOTIFY
For async notification, delivery of change notifications.
@ IDLE
Mildly important, used for background tasks.
@ RTAUDIO
Threshold for priorization across different loops.
@ COAWAIT
Used for coroutines, continuations of functions.
@ SYSALLOC
Internal maintenance, don't use.
@ AFRAME
Animation frame timers, prioritized over normal event processing.
uint16_t uint16
A 16-bit unsigned integer.
Definition cxxaux.hh:23
uint32_t uint
Provide 'uint' as convenience type.
Definition cxxaux.hh:18
void ase_rethrow(std::exception_ptr exception)
Helper to trace rethrown exceptions.
Definition cxxaux.cc:87
typedef uint16_t
bool seen_primary
Useful as hint for primary source presence, MainLoop::finishable() checks exhaustively.
Definition loop.hh:138
uint64 current_time_usecs
Equals timestamp_realtime() as of prepare() and check().
Definition loop.hh:139
int64 timeout_usecs
Maximum timeout for poll, queried during prepare().
Definition loop.hh:140
Helper to capture shared_ptr<Promise> to allow co_await on temporary Promise instances.
Definition loop.hh:370
void resolve()
Resolve Promise<void>
Definition loop.hh:416
void reject(std::exception_ptr exc=nullptr)
Reject promise with exception.
Definition loop.hh:422
Mirrors struct pollfd for poll(3posix)
Definition loop.hh:14
@ RDNORM
reading data will not block
Definition loop.hh:23
@ HUP
file descriptor closed
Definition loop.hh:29
@ IN
RDNORM || RDBAND.
Definition loop.hh:20
@ WRNORM
writing data will not block
Definition loop.hh:25
@ PRI
urgent data available
Definition loop.hh:21
@ NVAL
invalid PollFD
Definition loop.hh:30
@ RDBAND
reading priority data will not block
Definition loop.hh:24
@ OUT
writing data will not block
Definition loop.hh:22
@ ERR
error condition
Definition loop.hh:28
@ WRBAND
writing priority data will not block
Definition loop.hh:26