slab: rewrite slab allocator

This commit is contained in:
Matheus
2025-09-04 22:40:10 -03:00
parent 8cba07f65c
commit 2fa040096c
11 changed files with 500 additions and 261 deletions
+11 -3
View File
@@ -13,19 +13,20 @@ static scache_t *filecache;
cleanfile(f); \
}
static void ctor(scache_t *cache, void *obj) {
static bool ctor(scache_t *cache, void *obj) {
file_t *file = obj;
file->vnode = NULL;
MUTEX_INIT(&file->mutex);
file->refcount = 1;
file->offset = 0;
file->flags = 0;
file->mode = 0;
file->refcount = 1;
return true;
}
static file_t* newfile() {
if (filecache == NULL) {
filecache = slab_newcache(sizeof(file_t), 0, ctor, ctor);
filecache = slab_newcache(sizeof(file_t), 0, ctor, NULL);
__assert(filecache);
}
@@ -37,6 +38,13 @@ static void cleanfile(file_t *file) {
vfs_close(file->vnode, fileflagstovnodeflags(file->flags));
VOP_RELEASE(file->vnode);
}
file->vnode = NULL;
file->refcount = 1;
file->offset = 0;
file->flags = 0;
file->mode = 0;
MUTEX_INIT(&file->mutex);
slab_free(filecache, file);
}