io/uring/Ring: add io_uring_for_each_cqe() wrapper
This commit is contained in:
parent
c8e88408b2
commit
a9bee1c64b
@ -126,6 +126,35 @@ public:
|
|||||||
void SeenCompletion(struct io_uring_cqe &cqe) noexcept {
|
void SeenCompletion(struct io_uring_cqe &cqe) noexcept {
|
||||||
io_uring_cqe_seen(&ring, &cqe);
|
io_uring_cqe_seen(&ring, &cqe);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke a function with a reference to each completion (but
|
||||||
|
* do not mark it "seen" or advance the completion queue
|
||||||
|
* head).
|
||||||
|
*/
|
||||||
|
unsigned ForEachCompletion(struct io_uring_cqe *cqe,
|
||||||
|
std::invocable<struct io_uring_cqe &> auto f) noexcept {
|
||||||
|
unsigned dummy, n = 0;
|
||||||
|
|
||||||
|
io_uring_for_each_cqe(&ring, dummy, cqe) {
|
||||||
|
++n;
|
||||||
|
f(*cqe);
|
||||||
|
}
|
||||||
|
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Like ForEachCompletion(), but advance the completion queue
|
||||||
|
* head.
|
||||||
|
*/
|
||||||
|
unsigned VisitCompletions(struct io_uring_cqe *cqe,
|
||||||
|
std::invocable<const struct io_uring_cqe &> auto f) noexcept {
|
||||||
|
unsigned n = ForEachCompletion(cqe, f);
|
||||||
|
if (n > 0)
|
||||||
|
io_uring_cq_advance(&ring, n);
|
||||||
|
return n;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Uring
|
} // namespace Uring
|
||||||
|
Loading…
x
Reference in New Issue
Block a user