From 4889f3ebb59c926b8e53a2e12edd5009d7cd4cbe Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Mon, 19 Jun 2023 13:46:54 -0400 Subject: ioq: Arena-allocate ioq_cmd --- src/ioq.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/ioq.c b/src/ioq.c index 3e304ce..33316fa 100644 --- a/src/ioq.c +++ b/src/ioq.c @@ -266,6 +266,9 @@ struct ioq { /** The current size of the queue. */ size_t size; + /** ioq_cmd command arena. */ + struct arena cmds; + /** Pending I/O requests. */ struct ioqq *pending; /** Ready I/O responses. */ @@ -311,6 +314,7 @@ struct ioq *ioq_create(size_t depth, size_t nthreads) { } ioq->depth = depth; + ARENA_INIT(&ioq->cmds, union ioq_cmd); ioq->pending = ioqq_create(depth); if (!ioq->pending) { @@ -345,7 +349,7 @@ int ioq_opendir(struct ioq *ioq, int dfd, const char *path, void *ptr) { return -1; } - union ioq_cmd *cmd = ALLOC(union ioq_cmd); + union ioq_cmd *cmd = arena_alloc(&ioq->cmds); if (!cmd) { return -1; } @@ -385,8 +389,7 @@ struct ioq_res *ioq_trypop(struct ioq *ioq) { } void ioq_free(struct ioq *ioq, struct ioq_res *res) { - union ioq_cmd *cmd = (union ioq_cmd *)res; - free(cmd); + arena_free(&ioq->cmds, (union ioq_cmd *)res); } void ioq_destroy(struct ioq *ioq) { @@ -407,5 +410,7 @@ void ioq_destroy(struct ioq *ioq) { ioqq_destroy(ioq->ready); ioqq_destroy(ioq->pending); + arena_destroy(&ioq->cmds); + free(ioq); } -- cgit v1.2.3