Pigweed
C/C++ API Reference
Home
Modules
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
20
namespace
pw::async2 {
21
22
class
Context;
23
class
Dispatcher;
24
class
NativeDispatcherBase;
25
26
namespace
internal {
27
28
class
WakerQueueBase;
29
34
[[nodiscard]]
bool
StoreWaker(Context& cx,
35
Waker& waker_out,
36
log::Token wait_reason);
37
38
// Overload of StoreWaker taking a queue, allowing PW_ASYNC_STORE_WAKER to be
39
// used with a WakerQueue as the target.
40
[[nodiscard]]
bool
StoreWaker(Context& cx,
41
WakerQueueBase& queue,
42
log::Token wait_reason);
43
44
}
// namespace internal
45
47
55
class
Context
{
56
public
:
59
Context
(
Dispatcher
&
dispatcher
,
Waker
& waker)
60
: dispatcher_(&
dispatcher
), waker_(&waker), requires_waker_(true) {}
61
66
Dispatcher
&
dispatcher
() {
return
*dispatcher_; }
67
82
void
ReEnqueue
();
83
88
template
<
typename
T = ReadyType>
89
Poll<T>
Unschedule
() {
90
requires_waker_ =
false
;
91
return
Pending
();
92
}
93
94
private
:
95
friend
class
NativeDispatcherBase
;
96
friend
bool
internal::StoreWaker(
Context
& cx,
97
Waker
& waker_out,
98
log::Token wait_reason);
99
friend
bool
internal::StoreWaker(
Context
& cx,
100
internal::WakerQueueBase
& queue,
101
log::Token wait_reason);
102
103
Dispatcher
* dispatcher_;
104
Waker
* waker_;
105
bool
requires_waker_;
106
};
107
109
110
}
// namespace pw::async2
pw::async2::Context
Definition:
context.h:55
pw::async2::Context::ReEnqueue
void ReEnqueue()
pw::async2::Context::Unschedule
Poll< T > Unschedule()
Definition:
context.h:89
pw::async2::Context::Context
Context(Dispatcher &dispatcher, Waker &waker)
Definition:
context.h:59
pw::async2::Context::dispatcher
Dispatcher & dispatcher()
Definition:
context.h:66
pw::async2::Dispatcher
A single-threaded cooperatively scheduled runtime for async tasks.
Definition:
dispatcher.h:48
pw::async2::NativeDispatcherBase
Definition:
dispatcher_base.h:49
pw::async2::Poll
Definition:
poll.h:60
pw::async2::Waker
Definition:
waker.h:160
pw::async2::internal::WakerQueueBase
Definition:
waker_queue.h:23
pw::async2::Pending
constexpr PendingType Pending()
Returns a value indicating that an operation was not yet able to complete.
Definition:
poll.h:271
pw_async2
public
pw_async2
context.h
Generated by
1.9.6