stos: ob: Add object cache groundwork

Signed-off-by: Chloe M. <chloe@mensia.org>
This commit is contained in:
Chloe M.
2026-06-25 17:50:43 +00:00
parent 70f58b193f
commit bc11f9b58f
5 changed files with 155 additions and 1 deletions
+69
View File
@@ -0,0 +1,69 @@
/*
* Copyright (c) 2026, Chloe M.
* Provided under the BSD-3 clause.
*
* Description: Object manager cache
* Author: Chloe M.
*/
#include <ob/cache.h>
#include <string.h>
VOID
ObReclaimToCache(OBJECT_CACHE *Cache, ST_OBJECT *Object)
{
ST_OBJECT *Last;
if (Cache == NULL || Object == NULL) {
return;
}
/* Can only reclaim when refcount hits zero */
if (Object->RefCount != 0) {
return;
}
/* Insert the object */
Object->CacheNext = NULL;
if (Cache->First == NULL || Cache->Last == NULL) {
Cache->First = Object;
Cache->Last = Object;
} else {
Last = Cache->Last;
Last->CacheNext = Object;
Cache->Last = Object;
}
++Cache->EntryCount;
}
VOID
ObInitCache(OBJECT_CACHE *Cache)
{
if (Cache == NULL) {
return;
}
Cache->EntryCount = 0;
Cache->First = NULL;
Cache->Last = NULL;
}
ST_OBJECT *
ObPopFromCache(OBJECT_CACHE *Cache)
{
ST_OBJECT *First;
if (Cache == NULL) {
return NULL;
}
First = Cache->First;
if (First == NULL) {
return NULL;
}
Cache->First = First->CacheNext;
RtlMemSet(First, 0, sizeof(*First));
return First;
}
+3
View File
@@ -7,6 +7,7 @@
*/
#include <ob/object.h>
#include <ob/cache.h>
#include <ex/trace.h>
#include <ke/knot.h>
@@ -15,12 +16,14 @@
/* Globals */
static ST_OBJECT *RootDirectory;
OBJECT_CACHE gObCache;
VOID
ObInitManager(VOID)
{
ST_STATUS Status;
ObInitCache(&gObCache);
Status = ObCreateDirectory(
"/",
&RootDirectory
+15
View File
@@ -8,6 +8,7 @@
#include <ob/object.h>
#include <ex/pool.h>
#include <ob/cache.h>
#include <string.h>
ST_STATUS
@@ -84,3 +85,17 @@ ObCreateObject(const CHAR *Name, OBJECT_TYPE Type, VOID *Data, ST_OBJECT **Resul
*Result = Object;
return STATUS_SUCCESS;
}
VOID
ObReclaimObject(ST_OBJECT *Object)
{
if (Object == NULL) {
return;
}
/* TODO: Decrement this atomically */
Object->RefCount -= 1;
if (Object->RefCount == 0) {
ObReclaimToCache(&gObCache, Object);
}
}