aboutsummaryrefslogtreecommitdiff
path: root/include/kpl/object.h
diff options
context:
space:
mode:
authornodist <kevin.comas.git@gmail.com>2026-11-02 10:12:28 -0500
committernodist <kevin.comas.git@gmail.com>2026-11-02 10:12:28 -0500
commitfaa937cb09cd01f4ea94f5d7722a20e9c1246df0 (patch)
tree39126c9269c30a8ce7c0d3f2fea7d93f55fa42be /include/kpl/object.h
parent25f0a58b850d85b990d811002038f0655d2676b5 (diff)
update gc every oject has pointer to gc object
Diffstat (limited to 'include/kpl/object.h')
-rw-r--r--include/kpl/object.h21
1 files changed, 16 insertions, 5 deletions
diff --git a/include/kpl/object.h b/include/kpl/object.h
index e6e2340..cdea84e 100644
--- a/include/kpl/object.h
+++ b/include/kpl/object.h
@@ -13,11 +13,16 @@ typedef enum : uint16_t {
// 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) \
+#define KPL_OBJECT_GC_HEADER(STRUCT_NAME) \
struct STRUCT_NAME *_Atomic queue_next; \
int32_t object_size; \
uint16_t thread_id, object_flags;
+// Each object can access the object_gc it is a child of
+#define KPL_OBJECT_HEADER(STRUCT_NAME) \
+ KPL_OBJECT_GC_HEADER(STRUCT_NAME); \
+ kpl_object_gc *object_gc_parent;
+
typedef struct _kpl_object {
KPL_OBJECT_HEADER(_kpl_object);
} kpl_object; // all kpl objects allocated by the kpl memory allocator extend this header
@@ -62,7 +67,7 @@ void *kpl_object_queue_dequeue(kpl_object_queue *object_queue);
* Any thread can mark
*/
typedef struct _kpl_object_gc {
- KPL_OBJECT_HEADER(_kpl_object_gc);
+ KPL_OBJECT_GC_HEADER(_kpl_object_gc);
struct _kpl_object_gc *gc_prev, *gc_next;
_Atomic bool gc_mark __attribute((aligned(8)));
kpl_class class;
@@ -82,15 +87,21 @@ typedef struct _kpl_object_error {
typedef kpl_object_error *kpl_task_fn(kpl_object_task *task, kpl_thread *thread);
/*
+ * Max variables per task, used a bit field to check if the variable can be garbage collected
+ */
+#define KPL_TASK_VARIABLES_MAX 56
+
+/*
* Coroutine state object
- * Can have up to 32 arguments/locals
+ * Can have up to KPL_TASK_VARIABLES_MAX 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_gc_mask
- uint32_t variables_gc_mask, io_flags; // set once then only read
+ _Atomic bool join_ready; // shares cache line with variables_gc_mask
+ uint64_t variables_gc_mask : KPL_TASK_VARIABLES_MAX; // set once then only read
int32_t io_res; // io_res and io_flags are set by io_uring complete
+ uint32_t io_flags;
kpl_object_task *join;
kpl_task_fn *task_fn;
kpl_result result;