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 value_type = PendOutputOf<Pendable>;
30 : pendable_(pendable), output_(
Pending()) {}
36 output_ = pendable_.Pend(cx);
73 return native_.DoRunUntilStalled(*
this,
nullptr);
82 return native_.DoRunUntilStalled(*
this, &task);
89 template <
typename Pendable>
95 return task.TakePoll();
108 native_.DoRunToCompletion(*
this,
nullptr);
113 native_.DoRunToCompletion(*
this, &task);
117 template <
typename Pendable>
122 native_.DoRunToCompletion(*
this, &task);
123 return task.TakePoll().
value();
A single-threaded cooperatively scheduled runtime for async tasks.
Definition: dispatcher.h:48
pw::async2::backend::NativeDispatcher & native()
Returns a reference to the native backend-specific dispatcher type.
Definition: dispatcher.h:138
Poll RunUntilStalled()
Runs tasks until none are able to make immediate progress.
Definition: dispatcher.h:72
Dispatcher()=default
Constructs a new async Dispatcher.
void RunToCompletion()
Runs until all tasks complete.
Definition: dispatcher.h:107
Poll< PendOutputOf< Pendable > > RunPendableUntilStalled(Pendable &pendable)
Definition: dispatcher.h:90
uint32_t tasks_completed() const
Returns the total number of tasks the dispatcher has run to completion.
Definition: dispatcher.h:135
void LogRegisteredTasks()
Definition: dispatcher.h:128
void Post(Task &task)
Definition: dispatcher.h:67
void RunToCompletion(Task &task)
Runs until task completes.
Definition: dispatcher.h:112
Poll RunUntilStalled(Task &task)
Definition: dispatcher.h:80
uint32_t tasks_polled() const
Definition: dispatcher.h:132
PendOutputOf< Pendable > RunPendableToCompletion(Pendable &pendable)
Runs until pendable completes, returning the output of pendable.
Definition: dispatcher.h:118
Definition: dispatcher_native.h:39
Definition: dispatcher.h:26
Poll DoPend(Context &cx) final
Definition: dispatcher.h:35
pw::sync::InterruptSpinLock & dispatcher_lock()
Definition: lock.h:33
constexpr Poll Readiness() const noexcept
Definition: poll.h:140
constexpr PendingType Pending()
Returns a value indicating that an operation was not yet able to complete.
Definition: poll.h:271
constexpr value_type & value() &noexcept
Definition: poll.h:151
#define PW_LOCKS_EXCLUDED(...)
Definition: lock_annotations.h:176