16#include "pw_async2/context.h"
17#include "pw_async2/poll.h"
18#include "pw_async2/waker_queue.h"
19#include "pw_containers/internal/count_and_capacity.h"
21namespace pw::containers::internal {
34template <
typename SizeType,
size_t kMaxWakers = 1>
37 using size_type = SizeType;
40 : count_and_capacity_(capacity) {}
42 *
this = std::move(other);
46 count_and_capacity_ = std::move(other.count_and_capacity_);
47 pushes_reserved_ = std::exchange(other.pushes_reserved_, 0);
48 pop_reserved_ = std::exchange(other.pop_reserved_,
false);
49 wakers_ = std::move(other.wakers_);
53 constexpr size_type capacity()
const noexcept {
54 return count_and_capacity_.capacity();
56 constexpr size_type count()
const noexcept {
57 return count_and_capacity_.count();
60 constexpr void SetCount(size_type count) {
61 count_and_capacity_.SetCount(count);
66 constexpr void IncrementCount(size_type n = 1) {
67 count_and_capacity_.IncrementCount(n);
68 pushes_reserved_ -= std::min(n, pushes_reserved_);
73 constexpr void DecrementCount(size_type n = 1) {
74 count_and_capacity_.DecrementCount(n);
75 pop_reserved_ =
false;
83 PW_ASSERT(num <= capacity());
84 if (pushes_reserved_ == 0 && num <= capacity() - count()) {
85 pushes_reserved_ = num;
89 context, wakers_,
"waiting for space for items in container");
95 if (!pop_reserved_ && count() != 0) {
103 constexpr void SetCapacity(size_type capacity) {
104 count_and_capacity_.SetCapacity(capacity);
109 CountAndCapacity<size_type> count_and_capacity_;
110 size_type pushes_reserved_ = 0;
111 bool pop_reserved_ =
false;
Definition: waker_queue.h:65
Definition: async_count_and_capacity.h:35
async2::Poll PendHasSpace(async2::Context &context, size_type num)
Definition: async_count_and_capacity.h:82
async2::Poll PendNotEmpty(async2::Context &context)
Waits until an item is available in the container.
Definition: async_count_and_capacity.h:94
constexpr PendingType Pending()
Returns a value indicating that an operation was not yet able to complete.
Definition: poll.h:271
#define PW_ASYNC_STORE_WAKER(context, waker_or_queue_out, wait_reason_string)
Definition: waker.h:60
constexpr Poll Ready()
Returns a value indicating completion.
Definition: poll.h:255