diff options
| author | nodist <kevin.comas.git@gmail.com> | 2026-10-06 17:13:01 -0400 |
|---|---|---|
| committer | nodist <kevin.comas.git@gmail.com> | 2026-10-06 17:13:01 -0400 |
| commit | 7bd050ccf74222e1b659f2fd6826a86e6afbcc94 (patch) | |
| tree | 30bae9ca5dd110f32cd4abb10d42ea4d872b4d82 /include/kpl/runtime.h | |
| parent | de65adbc1b2d1b3efdbe6a023bb7435f84b2f3a7 (diff) | |
basic tests
Diffstat (limited to 'include/kpl/runtime.h')
| -rw-r--r-- | include/kpl/runtime.h | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/include/kpl/runtime.h b/include/kpl/runtime.h new file mode 100644 index 0000000..2adf402 --- /dev/null +++ b/include/kpl/runtime.h @@ -0,0 +1,52 @@ +/* + * KPL allocators, io and threading + */ + +#pragma once + +#include "base.h" + +typedef enum : uint8_t { + KPL_MEMORY_ALLOCATOR_MIN_POW2 = 7, + KPL_MEMORY_ALLOCATOR_MAX_POW2 = 30 +} kpl_memory_allocator_enum; + +/* + * All allocations are rounded to the next power of two at lest to a min or error if over max + * Each power of two has a bucket in the memory pool for reuse + */ +typedef struct { +// TODO MEMORY ALLOCATOR +} kpl_memory_allocator; + +typedef enum : uint8_t { + KPL_MEMORY_POOL_COUNT = 31 +} kpl_memory_pool_enum; + +// TODO IO URING + +// TODO JIT ALLOCATOR + +typedef struct { + kpl_memory_allocator allocator; + kpl_object_queue memory_pools[KPL_MEMORY_POOL_COUNT]; // each index represents 2 ** INDEX size in bytes + // TODO io_uring + // TODO jit allocator + _Atomic ssize_t priority; // running + the total number of tasks in threads queue, lower is higher priority + kpl_object_queue task_queue; + pthread_t pthread; // not used for main thread + sem_t sem; // wait when no task queue and io queue is empty +} kpl_thread; + +typedef enum : int32_t { + KPL_THREAD_DETERIMINE_COUNT = -1, + KPL_THREAD_MAIN_ID = 0 +} kpl_thread_enum; + +typedef struct _kpl_env { + int32_t thread_count; // -1 updates this value to max possible, 0 invalid, >= 1 for specific number + _Atomic ssize_t total_priority; // the sum of the threads priority fields, application stops on zero + kpl_thread *thread_array; // 0 is main thread, >= 1 are spawned pthreads + kpl_tree *namespace_tree, *module_tree; // *namespace_tree lookups are thread safe, *module_tree needs mutex + pthread_mutex_t module_tree_mutex; +} kpl_env; // kpl state, no globals |
