aboutsummaryrefslogtreecommitdiff
path: root/include/kpl/env.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/kpl/env.h')
-rw-r--r--include/kpl/env.h136
1 files changed, 0 insertions, 136 deletions
diff --git a/include/kpl/env.h b/include/kpl/env.h
deleted file mode 100644
index c4237fa..0000000
--- a/include/kpl/env.h
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * KPL environment objects
- */
-
-#pragma once
-
-typedef enum : int32_t {
- KPL_THREAD_DETERIMINE_COUNT = -1,
- 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 {
- uint16_t thread_id; // self id
- kpl_env *env; // access env
- kpl_memory_allocator memory_allocator;
- kpl_gc gc;
- kpl_io_uring io_uring;
- // TODO jit allocator
- _Atomic ssize_t priority; // io+running the total number of tasks in threads queue, lower is higher priority
- kpl_object_queue task_queue, error_queue; // traverse for gc marking
- pthread_t pthread; // not used for main thread
- sem_t sem; // wait when task queue and io queue is empty
-} kpl_thread;
-
-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_STOP = 1 << 0, // any thread can set, all threads check
- KPL_ENV_FLAG_HAS_ERROR = 1 << 1,
- KPL_ENV_FLAG_RUN_MODULE = 1 << 2,
- KPL_ENV_FLAG_RUN_EVAL = 1 << 3,
- KPL_ENV_FLAG_RUN_REPL = 1 << 4,
- KPL_ENV_FLAG_RUN_FUNCTION = 1 << 5
-} kpl_env_flags;
-
-/*
- * Life cycle:
- * kpl_env env = {};
- * kpl_env_config &env, argc, argv
- * kpl_env_init &env
- * add to the namespace tree
- * kpl_env_run &env
- * kpl_env_free &env
- */
-typedef struct _kpl_env {
- _Atomic uint32_t flags; // see kpl_env_flags for values, any thread can modify or check needs atomic
- 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
- union {
- const char *kpl_c_string_entry; // file or string, not used for repl, pointer used in kpl args namespace
- kpl_task_fn *kpl_fn_entry; // a task function, for a task with no variables, placed on main thread
- }; // only one entry point can be defined
- _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; // Trees of kpl_storage
- pthread_mutex_t module_tree_mutex;
- // TODO jit
-} kpl_env; // kpl state, no globals, must be zero initialized
-
-/*
- * Set up initial values before initialization
- * For defaults and/or directly setting without arguments, pass -1 to argc then fields can be updated directly
- * If not passing args, one of the RUN flags must be set
- */
-kpl_exit_code kpl_env_config(kpl_env *env, int32_t argc, char *argv[]);
-
-/*
- * 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);
-
-/*
- * Increase priority by one
- */
-inline void kpl_env_priority_increment(kpl_thread *thread) {
- thread->priority++;
- thread->env->total_priority++;
-}
-
-/*
- * Increase priority by amount
- */
-inline void kpl_env_priority_add(kpl_thread *thread, ssize_t amount) {
- thread->priority += amount;
- thread->env->total_priority += amount;
-}
-
-/*
- * Decrease priority by one
- */
-inline void kpl_env_priority_decrement(kpl_thread *thread) {
- thread->priority--;
- thread->env->total_priority--;
-}
-
-typedef enum : uint8_t {
- KPL_ENV_QUEUE_MODE_ASYNC = 0,
- KPL_ENV_QUEUE_MODE_SYNC = 1
-} kpl_env_queue_mode;
-
-/*
- * queue_mode ASYNC queues thread with lowest priority
- * queue_mode SYNC queues thread on threads[task->thread_id]
- */
-void kpl_env_queue_task(kpl_env *env, kpl_object_task *task, kpl_env_queue_mode queue_mode);
-
-/*
- * Run once, not re-enetrant
- * TODO RUN TASK AND IO ORDERING
- * Cleans Up each thread async
- */
-kpl_exit_code kpl_env_run(kpl_env *env);
-
-/*
- * Stops KPL, can be called on any task in KPL
- * Does not return just signals to all threads to stop, the return status will be from kpl_env_run
- */
-inline void kpl_env_stop(kpl_env *env) {
- env->flags |= KPL_ENV_FLAG_STOP;
-}
-
-/*
- * Run garbage collector
- */
-void kpl_env_gc(kpl_env *env);
-
-/*
- * Clean up
- */
-void kpl_env_free(kpl_env *env);