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
+57
View File
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2026, Chloe M.
* Provided under the BSD-3 clause.
*
* Description: Object manager cache
* Author: Chloe M.
*/
#ifndef _OB_CACHE_H_
#define _OB_CACHE_H_ 1
#include <stdef.h>
#include <ob/object.h>
/*
* An object cache allows deallocated objects to be recycled without
* the overhead of true deallocation and reallocation.
*
* @First: First cache entry
* @Last: Last cache entry
* @EntryCount: Number of entires in the cache
*/
typedef struct {
ST_OBJECT *First;
ST_OBJECT *Last;
USIZE EntryCount;
} OBJECT_CACHE;
extern OBJECT_CACHE gObCache;
/*
* Initialize object cache
*
* @Cache: Object cache to initialize
*/
VOID ObInitCache(OBJECT_CACHE *Cache);
/*
* Reclaim object to cache if the reference count is
* zero.
*
* @Cache: Cache to reclaim to
* @Object: Object to reclaim
*/
VOID ObReclaimToCache(OBJECT_CACHE *Cache, ST_OBJECT *Object);
/*
* Pop an entry for a zeroed object from the cache
*
* @Cache: Cache to pop from
*
* Returns an entry on success, otherwise NULL on
* failure
*/
ST_OBJECT *ObPopFromCache(OBJECT_CACHE *Cache);
#endif /* !_OB_CACHE_H_ */