Skip to contentSkip to conversation

queue, liburing.h: Avoid `io_uring_get_sqe()` code duplication

PATCH Applied Ammar Faizi 2 participants 2 messages Feb 25, 2022 io_uring

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 queue, liburing.h: Avoid `io_uring_get_sqe()` code duplication

Since commit 8be8af4afcb4909104c ("queue: provide io_uring_get_sqe() symbol again"), we have the same definition of io_uring_get_sqe() in queue.c and liburing.h.

Make it simpler, maintain it in a single place, create a new static inline function wrapper with name _io_uring_get_sqe(). Then tail call both io_uring_get_sqe() functions to _io_uring_get_sqe().

---

v2:
- Address a comment from Alviro (fix typo).
- Append Reviewed-by and Tested-by tag from Alviro.

 src/include/liburing.h |  9 +++++++--
 src/queue.c            | 11 +----------
 2 files changed, 8 insertions(+), 12 deletions(-)
src/include/liburing.h +7 -2
index 590fe7f..ef5a4cd 100644
@@ -831,8 +831,7 @@ static inline int io_uring_wait_cqe(struct io_uring *ring,
  *
  * Returns a vacant sqe, or NULL if we're full.
  */
-#ifndef LIBURING_INTERNAL
-static inline struct io_uring_sqe *io_uring_get_sqe(struct io_uring *ring)
+static inline struct io_uring_sqe *_io_uring_get_sqe(struct io_uring *ring)
 {
 	struct io_uring_sq *sq = &ring->sq;
 	unsigned int head = io_uring_smp_load_acquire(sq->khead);
@@ -845,6 +844,12 @@ static inline struct io_uring_sqe *io_uring_get_sqe(struct io_uring *ring)
 	}
 	return sqe;
 }
+
+#ifndef LIBURING_INTERNAL
+static inline struct io_uring_sqe *io_uring_get_sqe(struct io_uring *ring)
+{
+	return _io_uring_get_sqe(ring);
+}
 #else
 struct io_uring_sqe *io_uring_get_sqe(struct io_uring *ring);
 #endif
src/queue.c +1 -10
index 6b63490..f9b6c86 100644
@@ -405,16 +405,7 @@ int io_uring_submit_and_wait(struct io_uring *ring, unsigned wait_nr)
 
 struct io_uring_sqe *io_uring_get_sqe(struct io_uring *ring)
 {
-	struct io_uring_sq *sq = &ring->sq;
-	unsigned int head = io_uring_smp_load_acquire(sq->khead);
-	unsigned int next = sq->sqe_tail + 1;
-	struct io_uring_sqe *sqe = NULL;
-
-	if (next - head <= *sq->kring_entries) {
-		sqe = &sq->sqes[sq->sqe_tail & *sq->kring_mask];
-		sq->sqe_tail = next;
-	}
-	return sqe;
+	return _io_uring_get_sqe(ring);
 }
 
 int __io_uring_sqring_wait(struct io_uring *ring)

base-commit: 868be37473052893b68a8586d45a750980be4329

Signature · 1 line
2.32.0
maintainer Applied
#1 lore raw
Quoted 9 lines · Ammar Faizi

Since commit 8be8af4afcb4909104c ("queue: provide io_uring_get_sqe() symbol again"), we have the same definition of io_uring_get_sqe() in queue.c and liburing.h.

Make it simpler, maintain it in a single place, create a new static inline function wrapper with name _io_uring_get_sqe(). Then tail call both io_uring_get_sqe() functions to _io_uring_get_sqe().

[...]

Applied, thanks!

[1/1] queue, liburing.h: Avoid io_uring_get_sqe() code duplication

      commit: 15c01fcd1b0d37a12d945ab8dcdf96b3e055a4fd

Best regards,

Signature · 1 line
Jens Axboe