diff options
author | Jens Axboe <axboe@kernel.dk> | 2020-07-03 08:06:52 -0600 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2020-07-03 08:06:52 -0600 |
commit | 76f2926e550cc9bfedeaa26ddf712a8e63807fbd (patch) | |
tree | 5aa951f90175f4f912b8f35760aa1a522f5b8d80 | |
parent | ea91734dfae57c4222040cbdda9391ae0bda3862 (diff) | |
parent | 1c95b9cac7310ae4b445f06c210007b9fd86e131 (diff) | |
download | liburing-76f2926e550cc9bfedeaa26ddf712a8e63807fbd.tar.gz liburing-76f2926e550cc9bfedeaa26ddf712a8e63807fbd.tar.bz2 |
Merge branch 'dev' of https://github.com/CarterLi/liburing
* 'dev' of https://github.com/CarterLi/liburing:
examples/ucontext-cp.c: use IORING_OP_TIMEOUT
man/io_uring_enter: correct the description of
-rw-r--r-- | examples/ucontext-cp.c | 29 | ||||
-rw-r--r-- | man/io_uring_enter.2 | 7 |
2 files changed, 17 insertions, 19 deletions
diff --git a/examples/ucontext-cp.c b/examples/ucontext-cp.c index d588a14..0b2a6b5 100644 --- a/examples/ucontext-cp.c +++ b/examples/ucontext-cp.c @@ -85,25 +85,22 @@ int await_poll(async_context *pctx, int fd, short poll_mask) { } int await_delay(async_context *pctx, time_t seconds) { - struct itimerspec exp = { - .it_interval = {}, - .it_value = { seconds, 0 }, + struct io_uring_sqe *sqe = io_uring_get_sqe(pctx->ring); + struct io_uring_cqe *cqe; + struct __kernel_timespec ts = { + .tv_sec = seconds, + .tv_nsec = 0 }; - int tfd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK); - if (tfd < 0) { - perror("timerfd_create"); - return -1; - } - if (timerfd_settime(tfd, 0, &exp, NULL)) { - perror("timerfd_settime"); - close(tfd); - return -1; - } - int ret = await_poll(pctx, tfd, POLLIN); - assert(ret == POLLIN); + if (!sqe) + return -1; - close(tfd); + io_uring_prep_timeout(sqe, &ts, 0, 0); + io_uring_sqe_set_data(sqe, pctx); + swapcontext(&pctx->ctx_fnew, &pctx->ctx_main); + io_uring_peek_cqe(pctx->ring, &cqe); + assert(cqe); + io_uring_cqe_seen(pctx->ring, cqe); return 0; } diff --git a/man/io_uring_enter.2 b/man/io_uring_enter.2 index 054afbe..fc331e4 100644 --- a/man/io_uring_enter.2 +++ b/man/io_uring_enter.2 @@ -208,7 +208,7 @@ will contain .TP .B IORING_OP_EPOLL_CTL -Add, remove or modify entries in the interest list of +Add, remove or modify entries in the interest list of .BR epoll (7). See .BR epoll_ctl (2) @@ -291,11 +291,12 @@ must contain 1 to signify one timespec64 structure, may contain IORING_TIMEOUT_ABS for an absolute timeout value, or 0 for a relative timeout. .I off -may contain a completion event count. If not set, this defaults to 1. A timeout +may contain a completion event count. A timeout will trigger a wakeup event on the completion ring for anyone waiting for events. A timeout condition is met when either the specified timeout expires, or the specified number of events have completed. Either condition will -trigger the event. io_uring timeouts use the +trigger the event. If set to 0, completed events are not counted, which +effectively acts like a timer. io_uring timeouts use the .B CLOCK_MONOTONIC clock source. The request will complete with .I -ETIME |