summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/liburing.h32
1 files changed, 26 insertions, 6 deletions
diff --git a/src/liburing.h b/src/liburing.h
index 7973af9..df01040 100644
--- a/src/liburing.h
+++ b/src/liburing.h
@@ -74,17 +74,26 @@ extern int io_uring_wait_cqe(struct io_uring *ring,
extern int io_uring_submit(struct io_uring *ring);
extern struct io_uring_sqe *io_uring_get_sqe(struct io_uring *ring);
+#define io_uring_for_each_cqe(ring, head, cqe) \
+ for (head = *(ring)->cq.khead; \
+ /* See read_barrier() explanation in __io_uring_get_cqe() */ \
+ ({read_barrier(); \
+ cqe = (head != *(ring)->cq.ktail ? \
+ &(ring)->cq.cqes[head & (*(ring)->cq.kring_mask)] : NULL);}); \
+ head++) \
+
+
/*
- * Must be called after io_uring_{peek,wait}_cqe() after the cqe has
- * been processed by the application.
+ * Must be called after io_uring_for_each_cqe()
*/
-static inline void io_uring_cqe_seen(struct io_uring *ring,
- struct io_uring_cqe *cqe)
+static inline void io_uring_cq_advance(struct io_uring *ring,
+ unsigned nr)
{
- if (cqe) {
+ if (nr) {
struct io_uring_cq *cq = &ring->cq;
- (*cq->khead)++;
+ (*cq->khead) += nr;
+
/*
* Ensure that the kernel sees our new head, the kernel has
* the matching read barrier.
@@ -94,6 +103,17 @@ static inline void io_uring_cqe_seen(struct io_uring *ring,
}
/*
+ * Must be called after io_uring_{peek,wait}_cqe() after the cqe has
+ * been processed by the application.
+ */
+static inline void io_uring_cqe_seen(struct io_uring *ring,
+ struct io_uring_cqe *cqe)
+{
+ if (cqe)
+ io_uring_cq_advance(ring, 1);
+}
+
+/*
* Command prep helpers
*/
static inline void io_uring_sqe_set_data(struct io_uring_sqe *sqe, void *data)