diff options
| author | nodist <kevin.comas.git@gmail.com> | 2026-10-20 14:11:31 -0400 |
|---|---|---|
| committer | nodist <kevin.comas.git@gmail.com> | 2026-10-20 14:11:31 -0400 |
| commit | 689719e0a1f139e28e57a4df334d5fde354b3379 (patch) | |
| tree | 2b5e0d0c4aced4886ff3c67729adceba45cac3b0 /include/kpl/allocate.h | |
| parent | baa6f9cdea938c06435635f906b128f7940a59ec (diff) | |
config parse cli arguments
Diffstat (limited to 'include/kpl/allocate.h')
| -rw-r--r-- | include/kpl/allocate.h | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/include/kpl/allocate.h b/include/kpl/allocate.h new file mode 100644 index 0000000..ee24d72 --- /dev/null +++ b/include/kpl/allocate.h @@ -0,0 +1,35 @@ +/* + * KPL object allocators helpers + */ + +#pragma once + +/* + * All allocations must extend the KPL_OBJECT_HEADER + * All objects are allocated through this + */ +inline void *kpl_object_allocate(kpl_thread *thread, int32_t size) { + kpl_object *obj = kpl_memory_allocator_allocate(&thread->memory_allocator, size, thread->thread_id); + if (!obj) + return NULL; + obj->object_flags = KPL_OBJECT_FLAGS_EMPTY; + __atomic_clear(&obj->gc_mark, __ATOMIC_RELAXED); + obj->gc_prev = obj->gc_next = NULL; + obj->gc_next = thread->gc_head; + if (thread->gc_head) + thread->gc_head->gc_prev = obj; + thread->gc_head = obj; + return obj; +} + +/* + * All objects are returned by this + */ +inline void kpl_object_return(kpl_env *env, void *object) { + kpl_object *obj = object; + if (obj->gc_prev) + obj->gc_prev->gc_next = obj->gc_next; + if (obj->gc_next) + obj->gc_next->gc_prev = obj->gc_prev; + kpl_memory_allocator_return(&env->threads[obj->thread_id].memory_allocator, object); +} |
