16#include "pw_assert/assert.h"
17#include "pw_async2/context.h"
18#include "pw_async2/lock.h"
19#include "pw_async2/poll.h"
20#include "pw_containers/intrusive_forward_list.h"
21#include "pw_containers/intrusive_list.h"
22#include "pw_log/tokenized_args.h"
23#include "pw_sync/lock_annotations.h"
30#define PW_ASYNC_TASK_NAME(name) PW_LOG_TOKEN_EXPR("pw_async2", name)
32class NativeDispatcherBase;
72 explicit constexpr Task(log::Token name = kDefaultName) : name_(name) {}
76 Task& operator=(
const Task&) =
delete;
135 static constexpr log::Token kDefaultName =
141 constexpr Task(log::Token name, OwnedTag)
142 : owned_by_dispatcher_(true), name_(name) {}
172 PW_DASSERT(state_ == State::kUnposted);
173 PW_DASSERT(dispatcher_ ==
nullptr);
174 state_ = State::kWoken;
175 dispatcher_ = &dispatcher;
180 state_ = State::kUnposted;
181 dispatcher_ =
nullptr;
182 RemoveAllWakersLocked();
197 kCompletedNeedsDestroy,
203 RunResult RunInDispatcher(Dispatcher& dispatcher)
208 [[nodiscard]]
bool Wake()
212 void RemoveAllWakersLocked()
217 void AddWakerLocked(Waker&)
224 void RemoveWakerLocked(Waker&)
227 enum class State :
unsigned char {
230 kDeregisteredButRunning,
A single-threaded cooperatively scheduled runtime for async tasks.
Definition: dispatcher.h:48
Definition: dispatcher_base.h:47
Definition: owned_task.h:31
virtual Poll DoPend(Context &)=0
Poll Pend(Context &cx)
Definition: task.h:101
bool IsRegistered() const
constexpr Task(log::Token name=kDefaultName)
Definition: task.h:72
Definition: intrusive_list.h:88
pw::sync::InterruptSpinLock & dispatcher_lock()
Definition: lock.h:33
#define PW_LOG_TOKEN(...)
Definition: tokenized_args.h:63
#define PW_GUARDED_BY(x)
Definition: lock_annotations.h:60
#define PW_EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: lock_annotations.h:146
#define PW_LOCKS_EXCLUDED(...)
Definition: lock_annotations.h:176