summaryrefslogtreecommitdiff
path: root/src/std/mem.h
diff options
context:
space:
mode:
authorOmniscient <omniscient.oce@gmail.com>2024-05-17 13:50:33 +1000
committerOmniscient <omniscient.oce@gmail.com>2024-05-17 13:50:33 +1000
commit519329e98467d0cdcc39720cef0f69c9936b6d55 (patch)
tree2837063ce51984dee00c6e2194e6f58ba189e8d8 /src/std/mem.h
parent9df999df385b74be5096218d206dd39988784237 (diff)
pool tests and try get macro working
Diffstat (limited to 'src/std/mem.h')
-rw-r--r--src/std/mem.h24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/std/mem.h b/src/std/mem.h
index eef97a0..26da778 100644
--- a/src/std/mem.h
+++ b/src/std/mem.h
@@ -54,6 +54,28 @@ void_pool void_pool_create(arena* a, u64 capacity, u64 entry_size);
void void_pool_free_all(void_pool* pool);
bool void_pool_is_empty(void_pool* pool);
bool void_pool_is_full(void_pool* pool);
-void* void_pool_get(u32 raw_handle);
+void* void_pool_get(void_pool* pool, u32 raw_handle);
+void* void_pool_alloc(void_pool* pool, u32* out_raw_handle);
+void void_pool_dealloc(void_pool* pool, u32 raw_handle);
// TODO: macro that lets us specialise
+
+/* typedef struct Name##_handle Name##_handle; \ */
+#define TYPED_POOL(T, Name) \
+ typedef struct Name##_pool { \
+ void_pool inner; \
+ } Name##_pool; \
+ \
+ static Name##_pool Name##_pool_create(arena* a, u64 cap, u64 entry_size) { \
+ void_pool p = void_pool_create(a, cap, entry_size); \
+ return (Name##_pool){ .inner = p }; \
+ } \
+ static inline T* Name##_pool_get(Name##_pool* pool, Name##_handle handle) { \
+ return (T*)void_pool_get(&pool->inner, handle.raw); \
+ } \
+ static inline T* Name##_pool_alloc(Name##_pool* pool, Name##_handle* out_handle) { \
+ return (T*)void_pool_alloc(&pool->inner, &out_handle->raw); \
+ } \
+ static inline void Name##_pool_dealloc(Name##_pool* pool, Name##_handle handle) { \
+ void_pool_dealloc(&pool->inner, handle.raw); \
+ }\