Almost finished scheduler, switched to circular linked list

This commit is contained in:
ssimnb 2026-02-09 06:33:12 +01:00
parent edfbfdad14
commit 4c7ecb4012
10 changed files with 124 additions and 89 deletions

View file

@ -6,11 +6,12 @@
#include "vmm.h"
#include "page.h"
#include "slab.h"
#include "../scheduler/sched.h"
#include <kprint.h>
#include <neobbo.h>
#include <lock.h>
struct ma_kcache *caches = NULL;
struct ma_cache *caches = NULL;
atomic_flag caches_lock = ATOMIC_FLAG_INIT;
@ -65,7 +66,7 @@ uint64_t *_ma_slab_get_free_obj(struct ma_slab *slab){
}
kstatus _ma_alloc_slab(struct ma_kcache *kcache){
kstatus _ma_alloc_slab(struct ma_cache *kcache){
struct ma_slab *slab_structure = (struct ma_slab*)va_alloc_contigious_pages(1);
memset(slab_structure, 0, PAGE_SIZE);
@ -133,7 +134,7 @@ kstatus _ma_alloc_slab(struct ma_kcache *kcache){
void _ma_move_slab(struct ma_slab *slab, enum SLAB_STATE newstate){
struct ma_kcache *cache = slab->cache;
struct ma_cache *cache = slab->cache;
struct ma_slab *sb = 0;
switch (newstate) {
case FREE:
@ -265,11 +266,11 @@ void _ma_move_slab(struct ma_slab *slab, enum SLAB_STATE newstate){
}
struct ma_kcache *ma_cache_create(char *name, size_t size, uint32_t flags, void (*constructor)(void *, size_t), void (*destructor)(void *, size_t)){
struct ma_cache *ma_cache_create(char *name, size_t size, uint32_t flags, void (*constructor)(void *, size_t), void (*destructor)(void *, size_t)){
acquire_spinlock(&caches_lock);
struct ma_kcache *kcache = (struct ma_kcache*)va_alloc_contigious_pages(1);
struct ma_cache *kcache = (struct ma_cache*)va_alloc_contigious_pages(1);
memset(kcache, 0, 4096);
memcpy(kcache->name, name, 16);
@ -293,7 +294,7 @@ struct ma_kcache *ma_cache_create(char *name, size_t size, uint32_t flags, void
}
void *ma_cache_alloc(struct ma_kcache *kcache, uint32_t flags){
void *ma_cache_alloc(struct ma_cache *kcache, uint32_t flags){
acquire_spinlock(&kcache->lock);
@ -339,7 +340,7 @@ void *ma_cache_alloc(struct ma_kcache *kcache, uint32_t flags){
}
void cache_info(struct ma_kcache *cache){
void cache_info(struct ma_cache *cache){
kprintf("name: {s}\n", cache->name);
kprintf("objsize: {d}\n", cache->objsize);
kprintf("num: {d}\n", cache->num);
@ -454,3 +455,7 @@ kstatus ma_cache_dealloc(void *object){
return KERNEL_STATUS_SUCCESS;
}
extern struct ma_cache *thread_cache;
void create_base_caches(){
thread_cache = ma_cache_create("thread", sizeof(struct thread), 0, NULL, NULL);
}