Pigweed
C/C++ API Reference
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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;
24class NativeDispatcherBase;
25
26namespace internal {
27
28class WakerQueueBase;
29
34bool StoreWaker(Context& cx, Waker& waker_out, log::Token wait_reason);
35
36// Overload of StoreWaker taking a queue, allowing PW_ASYNC_STORE_WAKER to be
37// used with a WakerQueue as the target.
38bool StoreWaker(Context& cx, WakerQueueBase& queue, log::Token wait_reason);
39
40} // namespace internal
41
49class Context {
50 public:
54 : dispatcher_(&dispatcher), waker_(&waker), requires_waker_(true) {}
55
60 Dispatcher& dispatcher() { return *dispatcher_; }
61
76 void ReEnqueue();
77
80 // removed from the dispatcher, requiring it to be manually re-posted to run
81 // again.
82 template <typename T = ReadyType>
84 requires_waker_ = false;
85 return Pending();
86 }
87
88 private:
89 friend class NativeDispatcherBase;
90 friend bool internal::StoreWaker(Context& cx,
91 Waker& waker_out,
92 log::Token wait_reason);
93 friend bool internal::StoreWaker(Context& cx,
95 log::Token wait_reason);
96
97 Dispatcher* dispatcher_;
98 Waker* waker_;
99 bool requires_waker_;
100};
101
102} // namespace pw::async2
Definition: context.h:49
Poll< T > Unschedule()
Definition: context.h:83
Context(Dispatcher &dispatcher, Waker &waker)
Definition: context.h:53
Dispatcher & dispatcher()
Definition: context.h:60
A single-threaded cooperatively-scheduled runtime for async tasks.
Definition: dispatcher.h:46
Definition: dispatcher_base.h:47
Definition: poll.h:54
Definition: waker.h:148
Definition: waker_queue.h:23