Pigweed
C/C++ API Reference
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
waker_queue.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/context.h"
17#include "pw_async2/waker.h"
18#include "pw_containers/inline_queue.h"
19
20namespace pw::async2 {
21namespace internal {
22
24 public:
25 constexpr WakerQueueBase(InlineQueue<Waker>& queue) : queue_(queue) {}
26
28 size_t size() const { return queue_.size(); }
29
31 bool empty() const { return queue_.empty(); }
32
34 bool full() const { return queue_.full(); }
35
37 void WakeOne() { WakeMany(1); }
38
40 void WakeMany(size_t count);
41
43 void WakeAll() { WakeMany(queue_.size()); }
44
50 bool Add(Waker&& waker);
51
52 private:
53 InlineQueue<Waker>& queue_;
54};
55
56} // namespace internal
57
62template <size_t kCapacity>
64 public:
65 constexpr WakerQueue() : internal::WakerQueueBase(queue_) {}
66
67 private:
69};
70
71} // namespace pw::async2
Definition: inline_queue.h:50
Definition: waker.h:154
Definition: waker_queue.h:63
Definition: waker_queue.h:23
bool empty() const
Returns true if there are no wakers in the queue.
Definition: waker_queue.h:31
bool full() const
Returns true if the queue has no remaining space.
Definition: waker_queue.h:34
size_t size() const
Returns the number of wakers in the queue.
Definition: waker_queue.h:28
void WakeMany(size_t count)
Wakes count Wakers from the front of the queue.
void WakeOne()
Wakes the first Waker in the queue.
Definition: waker_queue.h:37
void WakeAll()
Wakes every Waker in the queue.
Definition: waker_queue.h:43