16#include "pw_async2/context.h"
17#include "pw_async2/dispatcher_native.h"
18#include "pw_async2/lock.h"
19#include "pw_async2/task.h"
20#include "pw_async2/waker.h"
25template <
typename Pendable>
28 using OutputType = PendOutputOf<Pendable>;
30 : pendable_(pendable), output_(Pending()) {}
36 output_ = pendable_.Pend(cx);
65 void Post(
Task& task) PW_LOCKS_EXCLUDED(impl::dispatcher_lock()) {
71 return native_.DoRunUntilStalled(*
this,
nullptr);
79 PW_LOCKS_EXCLUDED(impl::dispatcher_lock()) {
80 return native_.DoRunUntilStalled(*
this, &task);
87 template <
typename Pendable>
89 PW_LOCKS_EXCLUDED(impl::dispatcher_lock()) {
93 return task.TakePoll();
106 native_.DoRunToCompletion(*
this,
nullptr);
111 native_.DoRunToCompletion(*
this, &task);
115 template <
typename Pendable>
117 PW_LOCKS_EXCLUDED(impl::dispatcher_lock()) {
120 native_.DoRunToCompletion(*
this, &task);
121 return task.TakePoll().
value();
A single-threaded cooperatively-scheduled runtime for async tasks.
Definition: dispatcher.h:46
pw::async2::backend::NativeDispatcher & native()
Returns a reference to the native backend-specific dispatcher type.
Definition: dispatcher.h:136
Poll RunUntilStalled()
Runs tasks until none are able to make immediate progress.
Definition: dispatcher.h:70
Dispatcher()=default
Constructs a new async Dispatcher.
void RunToCompletion()
Runs until all tasks complete.
Definition: dispatcher.h:105
Poll< PendOutputOf< Pendable > > RunPendableUntilStalled(Pendable &pendable)
Definition: dispatcher.h:88
uint32_t tasks_completed() const
Returns the total number of tasks the dispatcher has run to completion.
Definition: dispatcher.h:133
void LogRegisteredTasks()
Definition: dispatcher.h:126
void Post(Task &task)
Definition: dispatcher.h:65
void RunToCompletion(Task &task)
Runs until task completes.
Definition: dispatcher.h:110
Poll RunUntilStalled(Task &task)
Definition: dispatcher.h:78
uint32_t tasks_polled() const
Definition: dispatcher.h:130
PendOutputOf< Pendable > RunPendableToCompletion(Pendable &pendable)
Runs until pendable completes, returning the output of pendable.
Definition: dispatcher.h:116
constexpr Poll Readiness() const noexcept
Definition: poll.h:132
constexpr T & value() &noexcept
Definition: poll.h:143
Definition: dispatcher_native.h:39
Definition: dispatcher.h:26
Poll DoPend(Context &cx) final
Definition: dispatcher.h:35