felspar::io::uring_warden::uring_warden(unsigned entries, unsigned flags)
: ring{std::make_unique<impl>()} {
if (auto const ret = ::io_uring_queue_init(entries, &ring->uring, flags);
ret < 0) {
throw felspar::stdexcept::system_error{
-ret, std::system_category(), "uring_queue_init"};
}
}
felspar::io::uring_warden::~uring_warden() {
if (ring) { ::io_uring_queue_exit(&ring->uring); }
}
void felspar::io::uring_warden::run_until(
felspar::coro::coroutine_handle<> coro) {
coro.resume();
while (not coro.done()) {
::io_uring_submit(&ring->uring);
::io_uring_cqe *cqe = {};
auto const ret = ::io_uring_wait_cqe(&ring->uring, &cqe);
if (ret < 0) {
throw felspar::stdexcept::system_error{
-ret, std::system_category(), "uring_wait_cqe"};
}
ring->execute(cqe);
while (::io_uring_peek_cqe(&ring->uring, &cqe) == 0) {
ring->execute(cqe);
}
}
}
void felspar::io::uring_warden::run_batch() {
::io_uring_submit(&ring->uring);
::io_uring_cqe *cqe = {};
while (::io_uring_peek_cqe(&ring->uring, &cqe) == 0) { ring->execute(cqe); }
}