From 28eab34ecea8b3677808c00cebbf4bd3227f8c68 Mon Sep 17 00:00:00 2001 From: David Härdeman Date: Mon, 22 Jun 2020 12:07:48 +0200 Subject: Use more descriptive names in struct cfg --- uring.c | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) (limited to 'uring.c') diff --git a/uring.c b/uring.c index e923947..31dfe26 100644 --- a/uring.c +++ b/uring.c @@ -33,10 +33,10 @@ get_sqe(struct uring_task *task) assert_die(task, "invalid arguments"); - sqe = io_uring_get_sqe(&cfg->uev->uring); + sqe = io_uring_get_sqe(&cfg->uring->uring); if (!sqe) { - io_uring_submit(&cfg->uev->uring); - sqe = io_uring_get_sqe(&cfg->uev->uring); + io_uring_submit(&cfg->uring->uring); + sqe = io_uring_get_sqe(&cfg->uring->uring); if (!sqe) die("failed to get an sqe!"); } @@ -203,9 +203,9 @@ uring_task_close_fd(struct uring_task *task) struct uring_task * uring_parent() { - assert_die(cfg->uev, "invalid arguments"); + assert_die(cfg->uring, "invalid arguments"); - return &cfg->uev->task; + return &cfg->uring->task; } void @@ -558,24 +558,24 @@ uring_poll_cancel(struct uring_task *task) static void uring_free(struct uring_task *task) { - struct uring_ev *uev = container_of(task, struct uring_ev, task); + struct uring_ev *uring = container_of(task, struct uring_ev, task); assert_return(task); debug(DBG_UR, "task %s (%p), fd %i, refcount %u", task->name, task, task->fd, task->refcount); - io_uring_queue_exit(&uev->uring); - cfg->uev = NULL; - xfree(uev); + io_uring_queue_exit(&uring->uring); + cfg->uring = NULL; + xfree(uring); } void uring_refdump() { - assert_return(cfg->uev); + assert_return(cfg->uring); - uring_task_refdump(&cfg->uev->task); + uring_task_refdump(&cfg->uring->task); } void @@ -583,9 +583,9 @@ uring_delete() { struct uring_task *task; - assert_return(cfg->uev); + assert_return(cfg->uring); - task = &cfg->uev->task; + task = &cfg->uring->task; debug(DBG_UR, "task %s (%p), fd %i, refcount %u", task->name, task, task->fd, task->refcount); @@ -595,20 +595,22 @@ uring_delete() void uring_init() { - struct uring_ev *uev; + struct uring_ev *uring; - uev = zmalloc(sizeof(*uev)); - if (!uev) + assert_return(!cfg->uring); + + uring = zmalloc(sizeof(*uring)); + if (!uring) die("malloc: %m"); - if (io_uring_queue_init_params(4096, &uev->uring, &uev->uring_params) < 0) + if (io_uring_queue_init_params(4096, &uring->uring, &uring->uring_params) < 0) die("io_uring_queue_init_params"); debug(DBG_UR, "uring initialized, features: 0x%08x", - uev->uring_params.features); + uring->uring_params.features); - uring_task_init(&uev->task, "io_uring", &cfg->task, uring_free); - cfg->uev = uev; + uring_task_init(&uring->task, "io_uring", &cfg->task, uring_free); + cfg->uring = uring; } static inline void @@ -636,8 +638,8 @@ uring_event_loop() unsigned nr, head; int r; - io_uring_submit(&cfg->uev->uring); - r = io_uring_wait_cqe(&cfg->uev->uring, &cqe); + io_uring_submit(&cfg->uring->uring); + r = io_uring_wait_cqe(&cfg->uring->uring, &cqe); if (r < 0) { if (errno == EINTR) continue; @@ -646,7 +648,7 @@ uring_event_loop() } nr = 0; - io_uring_for_each_cqe(&cfg->uev->uring, head, cqe) { + io_uring_for_each_cqe(&cfg->uring->uring, head, cqe) { struct uring_task *task = io_uring_cqe_get_data(cqe); bool do_cb; enum cqe_type cqe_type; @@ -695,7 +697,7 @@ uring_event_loop() nr++; } - io_uring_cq_advance(&cfg->uev->uring, nr); + io_uring_cq_advance(&cfg->uring->uring, nr); } } -- cgit v1.2.3