diff options
Diffstat (limited to 'include/kpl/object.h')
| -rw-r--r-- | include/kpl/object.h | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/include/kpl/object.h b/include/kpl/object.h index b7b1a33..b157719 100644 --- a/include/kpl/object.h +++ b/include/kpl/object.h @@ -4,7 +4,7 @@ #pragma once -typedef enum : uint8_t { +typedef enum : uint16_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_GC_PERSIST = 1 << 1 // Object is never swept by GC until program end @@ -16,10 +16,7 @@ typedef enum : uint8_t { #define KPL_OBJECT_HEADER(STRUCT_NAME) \ struct STRUCT_NAME *_Atomic queue_next; \ int32_t object_size; \ - uint16_t thread_id; \ - uint8_t object_flags; \ - _Atomic bool gc_mark; \ - struct STRUCT_NAME *gc_prev, *gc_next + uint16_t thread_id, object_flags; typedef struct _kpl_object { KPL_OBJECT_HEADER(_kpl_object); @@ -60,6 +57,18 @@ inline void kpl_object_queue_enqueue(kpl_object_queue *object_queue, void *objec void *kpl_object_queue_dequeue(kpl_object_queue *object_queue); /* + * All runtime objects are wrapped in the object_gc + * Only owner thread can use gc_prev and gc_next + * Any thread can mark + */ +typedef struct _kpl_object_gc { + KPL_OBJECT_HEADER(_kpl_object_gc); + struct _kpl_object_gc *gc_prev, *gc_next; + _Atomic bool gc_mark __attribute((aligned(8))); + kpl_class class; +} kpl_object_gc; + +/* * Class data is read only, cannot modify or race conditions can occur * The error stack can be modified across threads */ @@ -74,14 +83,16 @@ typedef kpl_object_error *kpl_task_fn(kpl_object_task *task, kpl_env *env); /* * Coroutine state object + * Can have up to 32 arguments/locals + * The variables_gc_mask is a bitmask, the set bit index represents the variable at the index is a kpl_object_gc */ typedef struct _kpl_object_task { KPL_OBJECT_HEADER(_kpl_object_task); - _Atomic bool join_ready __attribute__((aligned(4))); // shares cache line with variables_size - int32_t variables_size, io_res; // variables_size is set once then only read - uint32_t io_flags; // io_res and io_flags are set by io_uring complete + _Atomic bool join_ready __attribute__((aligned(4))); // shares cache line with variables_gc_mask + uint32_t variables_gc_mask, io_flags; // set once then only read + int32_t io_res; // io_res and io_flags are set by io_uring complete kpl_object_task *join; kpl_task_fn *task_fn; kpl_result result; - kpl_class variables[]; // a task has no distinction between an argument or a local, both live here + kpl_value64 variables[]; // a task has no distinction between an argument or a local, both live here } kpl_object_task; |
