21 Ring(
unsigned int entries, io_uring_params *params,
22 [[maybe_unused]]
void *buf, [[maybe_unused]]
size_t buf_size,
24 : submit_batch_(submit_batch) {
26#if !IO_URING_CHECK_VERSION(2, 5)
27 if (params->flags & IORING_SETUP_NO_MMAP) {
28 r = io_uring_queue_init_mem(entries, &ring_, params, buf, buf_size);
30 r = io_uring_queue_init_params(entries, &ring_, params);
33 r = io_uring_queue_init_params(entries, &ring_, params);
36 throw make_system_error(
"io_uring_queue_init_params", -r);
40 ~Ring() { io_uring_queue_exit(&ring_); }
42 CONDY_DELETE_COPY_MOVE(Ring);
45 void submit() noexcept {
46 maybe_submit_count_ = 0;
47 io_uring_submit(&ring_);
50 void maybe_submit() noexcept {
51 maybe_submit_count_++;
52 if (maybe_submit_count_ >= submit_batch_) {
57 template <
typename Func>
58 ssize_t reap_completions_wait(Func &&process_func)
noexcept {
63 int r = io_uring_submit_and_wait(&ring_, 1);
64 if (r >= 0) [[likely]] {
65 maybe_submit_count_ = 0;
67 }
else if (r == -EINTR) {
74 io_uring_for_each_cqe(&ring_, head, cqe) {
76#if !IO_URING_CHECK_VERSION(2, 13)
77 reaped += io_uring_cqe_nr(cqe);
82 io_uring_cq_advance(&ring_, reaped);
86 template <
typename Func>
87 ssize_t reap_completions(Func &&process_func)
noexcept {
89 int r = io_uring_peek_cqe(&ring_, &cqe);
98 io_uring_for_each_cqe(&ring_, head, cqe) {
100#if !IO_URING_CHECK_VERSION(2, 13)
101 reaped += io_uring_cqe_nr(cqe);
106 io_uring_cq_advance(&ring_, reaped);
110 void reserve_space(
size_t n)
noexcept {
113 space_left = io_uring_sq_space_left(&ring_);
114 if (space_left >= n) {
121 io_uring *ring() noexcept {
return &ring_; }
123 io_uring_sqe *get_sqe() noexcept {
return get_sqe_<io_uring_get_sqe>(); }
125#if !IO_URING_CHECK_VERSION(2, 13)
126 io_uring_sqe *get_sqe128() noexcept {
127 if (ring_.flags & (IORING_SETUP_SQE128 | IORING_SETUP_SQE_MIXED))
129 return get_sqe_<io_uring_get_sqe128>();
136 template <io_uring_sqe *(*get_sqe)(struct io_uring *)>
137 io_uring_sqe *get_sqe_() noexcept {
138 [[maybe_unused]]
int r;
141 sqe = get_sqe(&ring_);
146 if (ring_.flags & IORING_SETUP_SQPOLL) {
147 r = io_uring_sqring_wait(&ring_);
156 size_t submit_batch_;
157 size_t maybe_submit_count_ = 0;
The main namespace for the Condy library.
Internal utility classes and functions used by Condy.