@@ -182,6 +182,24 @@ static inline int io_uring_wait_cqe(struct io_uring *ring,
return 0;
}
+static inline int io_uring_peek_cqe(struct io_uring *ring,
+ struct io_uring_cqe **cqe_ptr)
+{
+ struct io_uring_cq *cq = &ring->cq;
+ const unsigned int mask = *cq->kring_mask;
+ unsigned int head = *cq->khead;
+ unsigned int tail = *cq->ktail;
+
+ *cqe_ptr = NULL;
+
+ read_barrier();
+ if (head-tail) {
+ *cqe_ptr = &cq->cqes[head & mask];
+ return 0;
+ }
+ return -EAGAIN;
+}
+
static inline int io_uring_submit(struct io_uring *ring)
{
struct io_uring_sq *sq = &ring->sq;
mini_liburing.h is used by the io_uring tests as a stand-in for liburing. The next patch in this series needs the io_uring_peek_cqe function, and I speculate that future tests will too, so add that here. Please scrutinize this code, I am somewhat new to io_uring, and whilst I have tested this and know it to work, I very well could've made a mistake somewhere without noticing. Signed-off-by: Oliver Crumrine <ozlinuxc@gmail.com> --- tools/include/io_uring/mini_liburing.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)