16#include "pw_assert/assert.h"
17#include "pw_async2/internal/config.h"
18#include "pw_async2/lock.h"
19#include "pw_containers/intrusive_forward_list.h"
20#include "pw_log/tokenized_args.h"
21#include "pw_sync/lock_annotations.h"
32template <
typename Callable>
33[[nodiscard]]
constexpr auto InvokeWithNodiscard(Callable&& callable) {
37[[nodiscard]]
bool CloneWaker(Waker& waker_in,
39 log::Token wait_reason = log::kDefaultToken)
60#define PW_ASYNC_STORE_WAKER(context, waker_or_queue_out, wait_reason_string) \
62 bool waker_or_queue_had_space = PW_ASYNC_TRY_STORE_WAKER( \
63 context, waker_or_queue_out, wait_reason_string); \
64 PW_ASSERT(waker_or_queue_had_space); \
81#define PW_ASYNC_TRY_STORE_WAKER( \
82 context, waker_or_queue_out, wait_reason_string) \
83 _PW_ASYNC_TRY_GET_WAKER(::pw::async2::internal::StoreWaker, \
102#define PW_ASYNC_CLONE_WAKER(waker_in, waker_or_queue_out, wait_reason_string) \
104 bool waker_or_queue_had_space = PW_ASYNC_TRY_CLONE_WAKER( \
105 waker_in, waker_or_queue_out, wait_reason_string); \
106 PW_ASSERT(waker_or_queue_had_space); \
123#define PW_ASYNC_TRY_CLONE_WAKER( \
124 waker_in, waker_or_queue_out, wait_reason_string) \
125 _PW_ASYNC_TRY_GET_WAKER(::pw::async2::internal::CloneWaker, \
127 waker_or_queue_out, \
133#define _PW_ASYNC_TRY_GET_WAKER( \
134 func, source, waker_or_queue_out, wait_reason_string) \
135 ::pw::async2::internal::InvokeWithNodiscard( \
136 [&]() PW_NO_LOCK_SAFETY_ANALYSIS { \
137 [[maybe_unused]] constexpr const char* \
138 pw_async2_wait_reason_must_be_string = wait_reason_string; \
139 constexpr ::pw::log::Token pw_async2_wait_reason = \
140 PW_LOG_TOKEN("pw_async2", wait_reason_string); \
141 return func(source, waker_or_queue_out, pw_async2_wait_reason); \
166 constexpr Waker() =
default;
175 ~Waker() noexcept { RemoveFromTaskWakerList(); }
205 RemoveFromTaskWakerList();
209 friend bool internal::CloneWaker(
Waker& waker_in,
211 log::Token wait_reason);
214 InsertIntoTaskWakerList();
225 void InternalCloneIntoLocked(Waker& waker_out, log::Token wait_reason) &
228 void InsertIntoTaskWakerList();
229 void InsertIntoTaskWakerListLocked()
231 void RemoveFromTaskWakerList();
232 void RemoveFromTaskWakerListLocked()
236 Task* task_
PW_GUARDED_BY(impl::dispatcher_lock()) =
nullptr;
238#if PW_ASYNC2_DEBUG_WAIT_REASON
239 log::Token wait_reason_ = log::kDefaultToken;
Definition: intrusive_forward_list.h:91
Definition: dispatcher_base.h:49
Waker & operator=(Waker &&other) noexcept
void Clear()
Definition: waker.h:204
Definition: waker_queue.h:23
pw::sync::InterruptSpinLock & dispatcher_lock()
Definition: lock.h:33
#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