From 379dee8a47480938c067fca0acd01dea9b5afa33 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Tue, 4 Jul 2023 15:01:18 -0400 Subject: ioq: New ioq_capacity() function --- src/ioq.c | 9 +++++++-- src/ioq.h | 5 +++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/ioq.c b/src/ioq.c index 10451ac..5673c77 100644 --- a/src/ioq.c +++ b/src/ioq.c @@ -355,6 +355,10 @@ fail: return NULL; } +size_t ioq_capacity(const struct ioq *ioq) { + return ioq->depth - ioq->size; +} + int ioq_opendir(struct ioq *ioq, struct bfs_dir *dir, int dfd, const char *path, void *ptr) { if (ioq->size >= ioq->depth) { return -1; @@ -382,7 +386,6 @@ struct ioq_res *ioq_pop(struct ioq *ioq) { } union ioq_cmd *cmd = ioqq_pop(ioq->ready); - --ioq->size; return &cmd->res; } @@ -396,11 +399,13 @@ struct ioq_res *ioq_trypop(struct ioq *ioq) { return NULL; } - --ioq->size; return &cmd->res; } void ioq_free(struct ioq *ioq, struct ioq_res *res) { + bfs_assert(ioq->size > 0); + --ioq->size; + arena_free(&ioq->cmds, (union ioq_cmd *)res); } diff --git a/src/ioq.h b/src/ioq.h index 064e2e2..9901293 100644 --- a/src/ioq.h +++ b/src/ioq.h @@ -40,6 +40,11 @@ struct ioq_res { */ struct ioq *ioq_create(size_t depth, size_t nthreads); +/** + * Check the remaining capacity of a queue. + */ +size_t ioq_capacity(const struct ioq *ioq); + /** * Asynchronous bfs_opendir(). * -- cgit v1.2.3