16#include "pw_assert/assert.h"
17#include "pw_async2/internal/config.h"
18#include "pw_async2/internal/lock.h"
19#include "pw_containers/intrusive_forward_list.h"
20#include "pw_log/tokenized_args.h"
21#include "pw_sync/lock_annotations.h"
30template <
typename Callable>
31[[nodiscard]]
constexpr auto InvokeWithNodiscard(Callable&& callable) {
35[[nodiscard]]
bool CloneWaker(Waker& waker_in,
37 log::Token wait_reason = log::kDefaultToken)
58#define PW_ASYNC_STORE_WAKER(context, waker_or_queue_out, wait_reason_string) \
60 bool waker_or_queue_had_space = PW_ASYNC_TRY_STORE_WAKER( \
61 context, waker_or_queue_out, wait_reason_string); \
62 PW_ASSERT(waker_or_queue_had_space); \
79#define PW_ASYNC_TRY_STORE_WAKER( \
80 context, waker_or_queue_out, wait_reason_string) \
81 _PW_ASYNC_TRY_GET_WAKER(::pw::async2::internal::StoreWaker, \
100#define PW_ASYNC_CLONE_WAKER(waker_in, waker_or_queue_out, wait_reason_string) \
102 bool waker_or_queue_had_space = PW_ASYNC_TRY_CLONE_WAKER( \
103 waker_in, waker_or_queue_out, wait_reason_string); \
104 PW_ASSERT(waker_or_queue_had_space); \
121#define PW_ASYNC_TRY_CLONE_WAKER( \
122 waker_in, waker_or_queue_out, wait_reason_string) \
123 _PW_ASYNC_TRY_GET_WAKER(::pw::async2::internal::CloneWaker, \
125 waker_or_queue_out, \
131#define _PW_ASYNC_TRY_GET_WAKER( \
132 func, source, waker_or_queue_out, wait_reason_string) \
133 ::pw::async2::internal::InvokeWithNodiscard( \
134 [&]() PW_NO_LOCK_SAFETY_ANALYSIS { \
135 [[maybe_unused]] constexpr const char* \
136 pw_async2_wait_reason_must_be_string = wait_reason_string; \
137 constexpr ::pw::log::Token pw_async2_wait_reason = \
138 PW_LOG_TOKEN("pw_async2", wait_reason_string); \
139 return func(source, waker_or_queue_out, pw_async2_wait_reason); \
163 constexpr Waker() =
default;
171 ~Waker() noexcept { RemoveFromTaskWakerList(); }
198 RemoveFromTaskWakerList();
202 friend bool internal::CloneWaker(
Waker& waker_in,
204 log::Token wait_reason);
207 InsertIntoTaskWakerList();
218 void InternalCloneIntoLocked(Waker& waker_out, log::Token wait_reason) &
221 void InsertIntoTaskWakerList();
222 void InsertIntoTaskWakerListLocked()
224 void RemoveFromTaskWakerList();
225 void RemoveFromTaskWakerListLocked()
231#if PW_ASYNC2_DEBUG_WAIT_REASON
232 log::Token wait_reason_ = log::kDefaultToken;
Definition: intrusive_forward_list.h:99
Definition: dispatcher.h:46
Waker & operator=(Waker &&other) noexcept
void Clear()
Definition: waker.h:197
#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