summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarter Li <carter.li@eoitek.com>2020-06-01 10:08:36 +0800
committerCarter Li <carter.li@eoitek.com>2020-06-10 15:54:22 +0800
commit1c95b9cac7310ae4b445f06c210007b9fd86e131 (patch)
tree26d8a1eea2c73b0c10c97a97ad6124171d2fc2ab
parentbfda2d43c0bc985ae99a0dd1649471e0e3473759 (diff)
downloadliburing-1c95b9cac7310ae4b445f06c210007b9fd86e131.tar.gz
liburing-1c95b9cac7310ae4b445f06c210007b9fd86e131.tar.bz2
examples/ucontext-cp.c: use IORING_OP_TIMEOUT
-rw-r--r--examples/ucontext-cp.c29
1 files changed, 13 insertions, 16 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;
}