aboutsummaryrefslogtreecommitdiff
path: root/include/kpl/env.h
diff options
context:
space:
mode:
authornodist <kevin.comas.git@gmail.com>2026-10-20 14:11:31 -0400
committernodist <kevin.comas.git@gmail.com>2026-10-20 14:11:31 -0400
commit689719e0a1f139e28e57a4df334d5fde354b3379 (patch)
tree2b5e0d0c4aced4886ff3c67729adceba45cac3b0 /include/kpl/env.h
parentbaa6f9cdea938c06435635f906b128f7940a59ec (diff)
config parse cli arguments
Diffstat (limited to 'include/kpl/env.h')
-rw-r--r--include/kpl/env.h43
1 files changed, 22 insertions, 21 deletions
diff --git a/include/kpl/env.h b/include/kpl/env.h
index 7806969..1e3d3d8 100644
--- a/include/kpl/env.h
+++ b/include/kpl/env.h
@@ -6,27 +6,33 @@
typedef enum : int32_t {
KPL_THREAD_DETERIMINE_COUNT = -1,
- KPL_THREAD_MAIN_ID = 0
+ KPL_THREAD_MAIN_ID = 0,
+ KPL_THEAD_THREAD_COUNT_MIN = 1,
+ KPL_THEAD_THREAD_COUNT_MAX = UINT16_MAX
} kpl_thread_enum;
typedef struct _kpl_thread {
- int32_t thread_id; // self id
+ uint16_t thread_id; // self id
kpl_memory_allocator memory_allocator;
+ kpl_object *gc_head, *gc_mark_head; // sweep if not marked or not in io pending
kpl_io_uring 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;
+ kpl_object_queue task_queue, error_queue; // traverse for gc marking
pthread_t pthread; // not used for main thread
sem_t sem; // wait when no task queue and io queue is empty
} kpl_thread;
-/*
- * All allocations must extend the KPL_OBJECT_HEADER
- * All objects are allocated through this
- */
-inline void *kpl_thread_object_allocate(kpl_thread *thread, int32_t size) {
- return kpl_memory_allocator_allocate(&thread->memory_allocator, size, thread->thread_id);
-}
+typedef enum : int32_t {
+ KPL_ENV_CONFIG_NO_ARGS = -1
+} kpl_env_enum;
+
+typedef enum : uint32_t {
+ KPL_ENV_FLAG_EMPTY = 0,
+ KPL_ENV_FLAG_RUN_MODULE = 1 << 0,
+ KPL_ENV_FLAG_RUN_EVAL = 1 << 1,
+ KPL_ENV_FLAG_RUN_REPL = 1 << 2
+} kpl_env_flags;
/*
* Life cycle:
@@ -39,22 +45,17 @@ inline void *kpl_thread_object_allocate(kpl_thread *thread, int32_t size) {
* kpl_env_free &env
*/
typedef struct _kpl_env {
+ uint32_t flags; // see kpl_env_flags for values
int32_t io_uring_queue_size_pow2; // the power of two to calculate the entries in the io_uring queue
int32_t thread_count; // -1 updates this value to max possible, 0 invalid, >= 1 for specific number
+ const char *kpl_entry; // file or string to be ran, not used for repl, pointer used to get kpl args namespace
_Atomic ssize_t total_priority; // the sum of the threads priority fields, application stops on zero
kpl_thread *threads; // 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;
+ // TODO namespace tree
+ // TODO module tree
} kpl_env; // kpl state, no globals, must be zero initialized
/*
- * All objects are returned by this
- */
-inline void kpl_env_object_return(kpl_env *env, void *object) {
- kpl_memory_allocator_return(&env->threads[((kpl_object*) object)->thread_id].memory_allocator, object);
-}
-
-/*
* Must match the type of c main return
* if code != KPL_EXIT_CODE_SUCCESS then return code
*/
@@ -66,12 +67,12 @@ typedef enum : int32_t {
/*
* Set up initial values before initialization
- * For defaults and/or directly setting without arguments, pass 0 to argc then fields can be updated directly
+ * For defaults and/or directly setting without arguments, pass -1 to argc then fields can be updated directly
*/
kpl_exit_code kpl_env_config(kpl_env *env, int32_t argc, char *argv[]);
/*
- * Initialize
+ * Initialize, read flags to create initial entry task
* env kpl_env_config must be called before this
*/
kpl_exit_code kpl_env_init(kpl_env *env);