16#include "pw_async2/context.h"
17#include "pw_async2/internal/config.h"
18#include "pw_async2/lock.h"
19#include "pw_async2/task.h"
20#include "pw_async2/waker.h"
21#include "pw_containers/intrusive_list.h"
22#include "pw_metric/metric.h"
23#include "pw_sync/lock_annotations.h"
24#include "pw_sync/mutex.h"
33using PendOutputOf =
typename decltype(std::declval<T>().Pend(
34 std::declval<Context&>()))::OutputType;
60 PW_EXCLUSIVE_LOCKS_REQUIRED(impl::dispatcher_lock()) {
61 return task.dispatcher_ ==
this;
71 void Deregister() PW_LOCKS_EXCLUDED(impl::dispatcher_lock());
73 void Post(
Task& task) PW_LOCKS_EXCLUDED(impl::dispatcher_lock());
83 bool should_sleep()
const {
return should_sleep_; }
86 SleepInfo(
bool should_sleep) : should_sleep_(should_sleep) {}
109 PW_LOCKS_EXCLUDED(impl::dispatcher_lock());
117 bool completed_main_task,
119 : completed_all_tasks_(completed_all_tasks),
120 completed_main_task_(completed_main_task),
121 ran_a_task_(ran_a_task) {}
122 bool completed_all_tasks()
const {
return completed_all_tasks_; }
123 bool completed_main_task()
const {
return completed_main_task_; }
124 bool ran_a_task()
const {
return ran_a_task_; }
127 bool completed_all_tasks_;
128 bool completed_main_task_;
135 Task* task_to_look_for);
137 uint32_t tasks_polled()
const {
return tasks_polled_.value(); }
138 uint32_t tasks_completed()
const {
return tasks_completed_.value(); }
139 uint32_t sleep_count()
const {
return sleep_count_.value(); }
140 uint32_t wake_count()
const {
return wake_count_.value(); }
143 friend class Dispatcher;
148 wake_count_.Increment();
163 PW_EXCLUSIVE_LOCKS_REQUIRED(impl::dispatcher_lock());
164 void RemoveWokenTaskLocked(
Task&)
165 PW_EXCLUSIVE_LOCKS_REQUIRED(impl::dispatcher_lock());
166 void RemoveSleepingTaskLocked(
Task&)
167 PW_EXCLUSIVE_LOCKS_REQUIRED(impl::dispatcher_lock());
170 void WakeTask(
Task&) PW_EXCLUSIVE_LOCKS_REQUIRED(impl::dispatcher_lock());
173 Task* PopWokenTask() PW_EXCLUSIVE_LOCKS_REQUIRED(impl::dispatcher_lock());
175 void LogRegisteredTasks();
177#if PW_ASYNC2_DEBUG_WAIT_REASON
178 void LogTaskWakers(
const Task& task)
179 PW_EXCLUSIVE_LOCKS_REQUIRED(impl::dispatcher_lock());
197 bool wants_wake_ PW_GUARDED_BY(impl::dispatcher_lock()) =
false;
199 PW_METRIC_GROUP(metrics_,
"pw::async2::NativeDispatcherBase");
200 PW_METRIC(metrics_, tasks_polled_,
"tasks_polled", 0u);
201 PW_METRIC(metrics_, tasks_completed_,
"tasks_completed", 0u);
202 PW_METRIC(metrics_, sleep_count_,
"sleep_count", 0u);
203 PW_METRIC(metrics_, wake_count_,
"wake_count", 0u);
A single-threaded cooperatively-scheduled runtime for async tasks.
Definition: dispatcher.h:46
Definition: dispatcher_base.h:114
Definition: dispatcher_base.h:79
Definition: dispatcher_base.h:47
RunOneTaskResult RunOneTask(Dispatcher &dispatcher, Task *task_to_look_for)
bool HasPostedTask(Task &task)
Check that a task is posted on this Dispatcher.
Definition: dispatcher_base.h:59
SleepInfo AttemptRequestWake(bool allow_empty)
Definition: intrusive_list.h:82
#define PW_MODIFY_DIAGNOSTICS_POP()
Definition: compiler.h:191
#define PW_MODIFY_DIAGNOSTIC_GCC(kind, option)
Definition: compiler.h:208
#define PW_MODIFY_DIAGNOSTICS_PUSH()
Definition: compiler.h:186