From 2006536959fb2c5580b8cb14d0dfc8b5710c1559 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Tue, 18 May 2021 18:11:46 -0400 Subject: [PATCH] linux::io_uring: add CQE-related functions Signed-off-by: Drew DeVault --- io_uring/queue.ha | 30 ++++++++++++++++++++++++++++-- diff --git a/io_uring/queue.ha b/io_uring/queue.ha index 1df8a71d816739eaadbc10ab995622a8400903d7..db43998643dab79581a255a1f75748b328b0877b 100644 --- a/io_uring/queue.ha +++ b/io_uring/queue.ha @@ -82,6 +82,32 @@ return submitted; }; }; +// Advances the completion queue by N items. +export fn cq_advance(ring: *io_uring, n: uint) void = { + *ring.cq.khead = *ring.cq.khead + n; +}; + +// Call after processing a [[cqe]]. The cqe is returned to the pool and cannot +// be used by the application again. +export fn cqe_seen(ring: *io_uring, cqe: *cqe) void = cq_advance(ring, 1); + +// Waits until a CQE is available, then returns it. The caller must pass the +// returned CQE to [[cqe_seen]] to advance the queue. +export fn wait(ring: *io_uring) (*cqe | error) = { + return match (get_cqe(ring, 0, 1)) { + err: error => err, + cq: nullable *cqe => { + assert(cq != null); // XXX: Correct? + cq: *cqe; + }, + }; +}; + +// Peeks the next CQE from the queue and returns it, or null if none are +// pending. The caller must pass the returned CQE to [[cqe_seen]] to advance the +// queue. +export fn peek(ring: *io_uring) (nullable *cqe | error) = get_cqe(ring, 0, 0); + fn peek_cqe(ring: *io_uring) (nullable *cqe, uint) = { let head = *ring.cq.khead; let tail = *ring.cq.ktail; @@ -93,11 +119,11 @@ }; return (&ring.cq.cqes[head & mask], avail); }; -export fn get_cqe( +fn get_cqe( ring: *io_uring, submit: uint, wait: uint, -) (nullable *cqe | errors::opaque) = { +) (nullable *cqe | error) = { let cq: nullable *cqe = null; for (cq == null) { let enter = false, overflow = false; -- 2.48.1