summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2023-07-04 15:01:18 -0400
committerTavian Barnes <tavianator@tavianator.com>2023-07-06 15:24:38 -0400
commit379dee8a47480938c067fca0acd01dea9b5afa33 (patch)
treef6e41efe2e019d360bc38c7229914c6b17724c13 /src
parent187ef092b6ea0f92dac53fbd2deb71379400446e (diff)
downloadbfs-379dee8a47480938c067fca0acd01dea9b5afa33.tar.xz
ioq: New ioq_capacity() function
Diffstat (limited to 'src')
-rw-r--r--src/ioq.c9
-rw-r--r--src/ioq.h5
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
@@ -41,6 +41,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().
*
* @param ioq