Skip to content

Commit 0cdd1ab

Browse files
committed
increment the refcount to the parent dir when creating a child work item
1 parent 9fa91a6 commit 0cdd1ab

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

include/bf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ struct dir_rc {
336336
struct dir_rc *open_dir_rc(int optional_fd, char *path);
337337
int get_dir_fd(struct dir_rc *dir);
338338
void dir_inc(struct dir_rc *dir);
339+
struct dir_rc *dir_clone(struct dir_rc *dir);
339340
void dir_dec(struct dir_rc *dir);
340341

341342
/*

src/bf.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,15 @@ void dir_inc(struct dir_rc *dir) {
626626
__atomic_fetch_add(&dir->rc, 1, __ATOMIC_ACQ_REL);
627627
}
628628

629+
/*
630+
* Clone a `dir_rc`.
631+
* This increments the refcount and returns a pointer to the dir_rc to the caller.
632+
*/
633+
struct dir_rc *dir_clone(struct dir_rc *dir) {
634+
dir_inc(dir);
635+
return dir;
636+
}
637+
629638
/*
630639
* Decrement the reference count for a dir_rc, and free it if that was the last reference.
631640
*/

src/descend.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ int descend(QPTPool_t *ctx, const size_t id, void *args,
127127
}
128128

129129
struct work *child = new_work_with_name(work->name, work->name_len, dir_child->d_name, len);
130+
child->parent_dir = dir_clone(d_rc);
130131

131132
struct entry_data child_ed;
132133
memset(&child_ed, 0, sizeof(child_ed));

0 commit comments

Comments
 (0)