summaryrefslogtreecommitdiffstats
path: root/include/slab.h
diff options
context:
space:
mode:
authorJon Santmyer <jon@jonsantmyer.com>2024-05-22 13:00:41 -0400
committerJon Santmyer <jon@jonsantmyer.com>2024-05-22 13:00:41 -0400
commitace65b453151845bc361f21f3e5b651c35f9f126 (patch)
tree262ebd29b0ca1d8584f0b6f1efa7a00d9f4f3e43 /include/slab.h
parentf004c1ade8d617a82cea2fe249434cccb47a2358 (diff)
downloadjove-kernel-ace65b453151845bc361f21f3e5b651c35f9f126.tar.gz
jove-kernel-ace65b453151845bc361f21f3e5b651c35f9f126.tar.bz2
jove-kernel-ace65b453151845bc361f21f3e5b651c35f9f126.zip
massive refactor for mp and organizationHEADmaster
Diffstat (limited to 'include/slab.h')
-rw-r--r--include/slab.h44
1 files changed, 44 insertions, 0 deletions
diff --git a/include/slab.h b/include/slab.h
new file mode 100644
index 0000000..04d42e4
--- /dev/null
+++ b/include/slab.h
@@ -0,0 +1,44 @@
+#ifndef JOVE_MEMORY_SLAB_H
+#define JOVE_MEMORY_SLAB_H 1
+
+#include <stdint.h>
+#include <stddef.h>
+#include <stdbool.h>
+
+#define SLABCACHE_NAME_LIMIT 32
+typedef struct slab_cache
+{
+ char name[SLABCACHE_NAME_LIMIT];
+
+ struct slab *list_free;
+ struct slab *list_partial;
+ struct slab *list_full;
+
+ size_t obj_count;
+ size_t obj_size;
+ size_t obj_capacity;
+
+ size_t slab_pages;
+} slab_cache_t;
+
+typedef struct slab
+{
+ struct slab *prev;
+ struct slab *next;
+ void *slab_base;
+ void *obj_base;
+
+ size_t free_count;
+ int free_index;
+ uintptr_t free[];
+} slab_t;
+
+void slabcache_new(slab_cache_t *cache, char *name, size_t objsize);
+
+void* slab_alloc(slab_cache_t *cache);
+void slab_free(slab_cache_t *cache, void *ptr);
+
+void* slab_get(slab_cache_t *cache, size_t index);
+void slab_set(slab_cache_t *cache, size_t index, void *data);
+
+#endif