summaryrefslogtreecommitdiffstats
path: root/src/bftw.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2023-07-04 15:17:23 -0400
committerTavian Barnes <tavianator@tavianator.com>2023-07-10 14:53:46 -0400
commit222ac5ba4fbab0ab880e36423d0f1338e39b02c7 (patch)
treee2f4610625ac5fbe58eba9ff121bce745b3c940f /src/bftw.c
parent35d357793c35ed0263d57a439323027c80a4a5b7 (diff)
downloadbfs-222ac5ba4fbab0ab880e36423d0f1338e39b02c7.tar.xz
ioq: Implement async close() and closedir()
Diffstat (limited to 'src/bftw.c')
-rw-r--r--src/bftw.c41
1 files changed, 23 insertions, 18 deletions
diff --git a/src/bftw.c b/src/bftw.c
index ec67817..64f221b 100644
--- a/src/bftw.c
+++ b/src/bftw.c
@@ -901,34 +901,39 @@ static int bftw_ioq_pop(struct bftw_state *state, bool block) {
return -1;
}
- struct ioq_res *res = block ? ioq_pop(ioq) : ioq_trypop(ioq);
- if (!res) {
+ struct ioq_ent *ent = block ? ioq_pop(ioq) : ioq_trypop(ioq);
+ if (!ent) {
return -1;
}
struct bftw_cache *cache = &state->cache;
- ++cache->capacity;
-
- struct bftw_file *file = res->ptr;
- file->ioqueued = false;
+ struct bftw_file *file;
+ struct bfs_dir *dir;
- if (file->parent) {
- bftw_cache_unpin(cache, file->parent);
- }
+ enum ioq_op op = ent->op;
+ if (op == IOQ_OPENDIR) {
+ file = ent->ptr;
+ file->ioqueued = false;
- if (res->error) {
- arena_free(&cache->dirs, res->dir);
- } else {
- bftw_file_set_dir(cache, file, res->dir);
- }
+ ++cache->capacity;
+ if (file->parent) {
+ bftw_cache_unpin(cache, file->parent);
+ }
- ioq_free(ioq, res);
+ dir = ent->opendir.dir;
+ if (ent->ret == 0) {
+ bftw_file_set_dir(cache, file, dir);
+ } else {
+ arena_free(&cache->dirs, dir);
+ }
- if (!(state->flags & BFTW_SORT)) {
- SLIST_PREPEND(&state->dirs, file);
+ if (!(state->flags & BFTW_SORT)) {
+ SLIST_PREPEND(&state->dirs, file);
+ }
}
- return 0;
+ ioq_free(ioq, ent);
+ return op;
}
/** Try to reserve space in the I/O queue. */