list: change locking discipline
Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
parent
2cf76fd225
commit
071a5651e0
11 changed files with 61 additions and 15 deletions
|
|
@ -139,10 +139,13 @@ static int link(inode_t *parent_dir, inode_t *child, const char *name, dirent_t
|
|||
|
||||
new->inode = child;
|
||||
|
||||
list_lock(&parent_dir->dirents);
|
||||
if (!list_insert(&parent_dir->dirents, new)) {
|
||||
list_unlock(&parent_dir->dirents);
|
||||
dirent_free(new);
|
||||
return -ENOMEM;
|
||||
}
|
||||
list_unlock(&parent_dir->dirents);
|
||||
|
||||
*out = new;
|
||||
return 0;
|
||||
|
|
@ -153,17 +156,21 @@ static int unlink(inode_t *parent_dir, const char *name)
|
|||
if (!parent_dir || !name)
|
||||
return -EINVAL;
|
||||
|
||||
list_lock(&parent_dir->dirents);
|
||||
|
||||
list_item_t *item = parent_dir->dirents.head;
|
||||
while (item) {
|
||||
dirent_t *dent = item->ptr;
|
||||
if (!strcmp(dent->name, name)) {
|
||||
list_remove(item);
|
||||
list_unlock(&parent_dir->dirents);
|
||||
dirent_dec_ref(dent);
|
||||
return 0;
|
||||
}
|
||||
item = item->next;
|
||||
}
|
||||
|
||||
list_unlock(&parent_dir->dirents);
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue