21struct TOperationState {
22 TOperationState() =
default;
23 TOperationState(
const TOperationState&) =
delete;
24 TOperationState& operator=(
const TOperationState&) =
delete;
55 return Remove(Ready_, op) || Remove(Reaped_, op);
68 for (
auto* op : Ready_) {
70 op->Index =
static_cast<unsigned>(size);
75 for (
auto* op : Reaped_) {
81 return !Ready_.empty();
86 for (
size_t i = 0; i < Ready_.size(); i++) {
89 if (
auto* op = std::exchange(Ready_[i],
nullptr)) {
90 std::exchange(op->Handle, {}).resume();
97 static void Add(std::vector<TOperationState*>& list,
TOperationState* op) {
98 op->
Index =
static_cast<unsigned>(list.size());
102 static bool Remove(std::vector<TOperationState*>& list, TOperationState& op) {
103 if (op.Index < list.size() && list[op.Index] == &op) {
104 list[op.Index] =
nullptr;
110 std::vector<TOperationState*> Ready_;
111 std::vector<TOperationState*> Reaped_;
Completions taken from the system and not delivered yet.
Definition completions.hpp:37
void Reap(TOperationState *op, int result)
Adds a completion taken while waiting for a cancelled operation.
Definition completions.hpp:46
bool Drop(TOperationState &op)
Drops the completion of a cancelled operation. Returns false if it is not taken yet.
Definition completions.hpp:52
void Collect(TOperationState *op, int result)
Adds a completion taken by the poller's wait.
Definition completions.hpp:40
void Wakeup()
Resumes the coroutines of the ready completions.
Definition completions.hpp:85
bool Carry()
Starts the next batch of ready completions.
Definition completions.hpp:66
State of one operation of a completion-based poller (TUring, TIOCp).
Definition completions.hpp:21
int Result
Result of the completion, e.g. the number of bytes transferred.
Definition completions.hpp:27
unsigned Index
Position of the completion in TCompletions once taken; before that, whatever the poller keeps there.
Definition completions.hpp:28
THandle Handle
Coroutine to resume, set by the caller before posting. Cleared when posting fails,...
Definition completions.hpp:26