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/object.h | |
| parent | baa6f9cdea938c06435635f906b128f7940a59ec (diff) | |
config parse cli arguments
Diffstat (limited to 'include/kpl/object.h')
| -rw-r--r-- | include/kpl/object.h | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/include/kpl/object.h b/include/kpl/object.h index 1f3ec04..1053348 100644 --- a/include/kpl/object.h +++ b/include/kpl/object.h @@ -4,11 +4,21 @@ #pragma once +typedef enum : uint8_t { + KPL_OBJECT_FLAGS_EMPTY = 0, + KPL_OBJECT_FLAGS_IO_PENDING = 1 << 0 // When io pending tasks will not be reachable by GC +} kpl_object_flags; + // for atomic linked list queue // size in bytes, index on the kpl_threads array +// Flags should only be set by owner thread #define KPL_OBJECT_HEADER(STRUCT_NAME) \ struct STRUCT_NAME *_Atomic queue_next; \ - int32_t object_size, thread_id + int32_t object_size; \ + uint16_t thread_id; \ + uint8_t object_flags; \ + _Atomic bool gc_mark; \ + struct STRUCT_NAME *gc_prev, *gc_next typedef struct _kpl_object { KPL_OBJECT_HEADER(_kpl_object); @@ -48,7 +58,18 @@ inline void kpl_object_queue_enqueue(kpl_object_queue *object_queue, void *objec */ void *kpl_object_queue_dequeue(kpl_object_queue *object_queue); -typedef void kpl_task_fn(kpl_object_task *task, kpl_env *env); +/* + * Class data is read only, cannot modify or race conditions can occur + * The error stack can be modified across threads + */ +typedef struct _kpl_object_error { + KPL_OBJECT_HEADER(_kpl_object_error); + kpl_object_queue error_stack; + kpl_class error_file, error_data; // Can be a reference to C code or KPL code + int32_t error_line; +} kpl_object_error; + +typedef kpl_object_error *kpl_task_fn(kpl_object_task *task, kpl_env *env); /* * Coroutine state object @@ -63,3 +84,16 @@ typedef struct _kpl_object_task { kpl_result result; kpl_class variables[]; // a task has no distinction between an argument or a local, both live here } kpl_object_task; + +/* + * KPL Object Mutex is a queue of tasks on an object + * Adding: Increment counter, then add task to task queue + * Removing: Remove from task queue, run task, then decrement counter + * Requires spin check when removing task due to space between counter adding and task adding + * If the counter value before was zero take control of the mutex + * The thread that controls the mutex runs each task until counter is zero + */ +typedef struct { + _Atomic int32_t lock_counter; + kpl_object_queue task_queue; +} kpl_object_mutex; |
