summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2019-09-21 15:04:52 -0600
committerJens Axboe <axboe@kernel.dk>2019-09-21 15:04:52 -0600
commit11e18b3558b9dec4a2b9b109e9d04c9ff2849fb3 (patch)
treece1518d59981e2417bacc49dc8e2b7103216cdea /src
parent2d5ee6983ab55616bacb042370da8bb35492030c (diff)
downloadliburing-11e18b3558b9dec4a2b9b109e9d04c9ff2849fb3.tar.gz
liburing-11e18b3558b9dec4a2b9b109e9d04c9ff2849fb3.tar.bz2
Add io_uring_wait_cqes_timeout()
Like io_uring_wait_cqe_timeout(), except this one takes an argument for how many CQEs to ask for when waiting in the kernel. Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'src')
-rw-r--r--src/include/liburing.h2
-rw-r--r--src/liburing.map1
-rw-r--r--src/queue.c44
3 files changed, 33 insertions, 14 deletions
diff --git a/src/include/liburing.h b/src/include/liburing.h
index 1cae1cd..cfce895 100644
--- a/src/include/liburing.h
+++ b/src/include/liburing.h
@@ -74,6 +74,8 @@ extern int io_uring_peek_cqe(struct io_uring *ring,
struct io_uring_cqe **cqe_ptr);
extern int io_uring_wait_cqe(struct io_uring *ring,
struct io_uring_cqe **cqe_ptr);
+extern int io_uring_wait_cqes_timeout(struct io_uring *ring,
+ struct io_uring_cqe **cqe_ptr, unsigned wait_nr, struct timespec *ts);
extern int io_uring_wait_cqe_timeout(struct io_uring *ring,
struct io_uring_cqe **cqe_ptr, struct timespec *ts);
extern int io_uring_submit(struct io_uring *ring);
diff --git a/src/liburing.map b/src/liburing.map
index 4f5f9c1..730d5eb 100644
--- a/src/liburing.map
+++ b/src/liburing.map
@@ -6,6 +6,7 @@ LIBURING_0.1 {
io_uring_peek_cqe;
io_uring_wait_cqe;
io_uring_wait_cqe_timeout;
+ io_uring_wait_cqes_timeout;
io_uring_submit;
io_uring_submit_and_wait;
io_uring_get_sqe;
diff --git a/src/queue.c b/src/queue.c
index 97a99d7..18040d5 100644
--- a/src/queue.c
+++ b/src/queue.c
@@ -69,25 +69,30 @@ int io_uring_wait_cqe(struct io_uring *ring, struct io_uring_cqe **cqe_ptr)
* Note that the application need not call io_uring_submit() before calling
* this function, as we will do that on its behalf.
*/
-int io_uring_wait_cqe_timeout(struct io_uring *ring,
- struct io_uring_cqe **cqe_ptr,
- struct timespec *ts)
+int io_uring_wait_cqes_timeout(struct io_uring *ring,
+ struct io_uring_cqe **cqe_ptr,
+ unsigned wait_nr,
+ struct timespec *ts)
{
- struct io_uring_sqe *sqe;
int ret;
- /*
- * If the SQ ring is full, we may need to submit IO first
- */
- sqe = io_uring_get_sqe(ring);
- if (!sqe) {
- ret = io_uring_submit(ring);
- if (ret < 0)
- return ret;
+ if (wait_nr) {
+ struct io_uring_sqe *sqe;
+
+ /*
+ * If the SQ ring is full, we may need to submit IO first
+ */
sqe = io_uring_get_sqe(ring);
+ if (!sqe) {
+ ret = io_uring_submit(ring);
+ if (ret < 0)
+ return ret;
+ sqe = io_uring_get_sqe(ring);
+ }
+ io_uring_prep_timeout(sqe, ts, wait_nr);
+ sqe->user_data = LIBURING_UDATA_TIMEOUT;
}
- io_uring_prep_timeout(sqe, ts, 1);
- sqe->user_data = LIBURING_UDATA_TIMEOUT;
+
ret = io_uring_submit(ring);
if (ret < 0)
return ret;
@@ -96,6 +101,17 @@ int io_uring_wait_cqe_timeout(struct io_uring *ring,
}
/*
+ * See io_uring_wait_cqes_timeout() - this function is the same, it just
+ * always uses '1' as the wait_nr.
+ */
+int io_uring_wait_cqe_timeout(struct io_uring *ring,
+ struct io_uring_cqe **cqe_ptr,
+ struct timespec *ts)
+{
+ return io_uring_wait_cqes_timeout(ring, cqe_ptr, 1, ts);
+}
+
+/*
* Returns true if we're not using SQ thread (thus nobody submits but us)
* or if IORING_SQ_NEED_WAKEUP is set, so submit thread must be explicitly
* awakened. For the latter case, we set the thread wakeup flag.