C/C++ API Reference
Loading...
Searching...
No Matches
context.h
1// Copyright 2025 The Pigweed Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may not
4// use this file except in compliance with the License. You may obtain a copy of
5// the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12// License for the specific language governing permissions and limitations under
13// the License.
14#pragma once
15
16#include "pw_async2/poll.h"
17#include "pw_async2/waker.h"
18#include "pw_log/tokenized_args.h"
19
20namespace pw::async2 {
21
22class Context;
23class Dispatcher;
24
25namespace internal {
26
27class WakerQueueBase;
28
33[[nodiscard]] bool StoreWaker(Context& cx,
34 Waker& waker_out,
35 log::Token wait_reason);
36
37// Overload of StoreWaker taking a queue, allowing PW_ASYNC_STORE_WAKER to be
38// used with a WakerQueue as the target.
39[[nodiscard]] bool StoreWaker(Context& cx,
40 WakerQueueBase& queue,
41 log::Token wait_reason);
42
43} // namespace internal
44
46
54class Context {
55 public:
59 : dispatcher_(&dispatcher), waker_(&waker), requires_waker_(true) {}
60
65 Dispatcher& dispatcher() { return *dispatcher_; }
66
81 void ReEnqueue();
82
87 template <typename T = ReadyType>
89 requires_waker_ = false;
90 return Pending();
91 }
92
93 private:
94 friend class Task;
95 friend bool internal::StoreWaker(Context& cx,
96 Waker& waker_out,
97 log::Token wait_reason);
98 friend bool internal::StoreWaker(Context& cx,
100 log::Token wait_reason);
101
102 Dispatcher* dispatcher_;
103 Waker* waker_;
104 bool requires_waker_;
105};
106
108
109} // namespace pw::async2
Definition: context.h:54
Poll< T > Unschedule()
Definition: context.h:88
Context(Dispatcher &dispatcher, Waker &waker)
Definition: context.h:58
Dispatcher & dispatcher()
Definition: context.h:65
Definition: dispatcher.h:53
Definition: poll.h:60
Definition: task.h:62
Definition: waker.h:160
Definition: waker_queue.h:23
constexpr PendingType Pending()
Returns a value indicating that an operation was not yet able to complete.
Definition: poll.h:271