summaryrefslogtreecommitdiff
path: root/docs/application/gc.md
diff options
context:
space:
mode:
authornodist <kevin.comas.git@gmail.com>2026-06-08 20:44:04 -0400
committernodist <kevin.comas.git@gmail.com>2026-06-08 20:44:04 -0400
commitfaac96fff84c45acf20af0515e8fd43af32fdaca (patch)
tree3c7e6a11ef14fc8d9ed4ddde9d39dfe8158cad77 /docs/application/gc.md
parent168e070965aa2d98326b297d10339c4ad131c560 (diff)
add tracing step by step
Diffstat (limited to 'docs/application/gc.md')
-rw-r--r--docs/application/gc.md32
1 files changed, 29 insertions, 3 deletions
diff --git a/docs/application/gc.md b/docs/application/gc.md
index 7353db9..9364e12 100644
--- a/docs/application/gc.md
+++ b/docs/application/gc.md
@@ -5,8 +5,34 @@
## Object Definition
```c
-typedef struct _kpl_gc_count {
- _Atomic size_t ref_count;
+typedef struct _kpl_gc {
+ POOL_HEADER(_kpl_gc);
+ union {
+ _Atomic int32_t ref_count;
+ _Atomic bool mark;
+ } method;
kpl_any any;
-} kpl_gc_count;
+ pthread_mutex_t mutex;
+} kpl_gc;
+
+static _Atomic size_t marked_threads;
+
+static kpl_gc *old_gc_head, *gc_head, *gc_tail;
```
+
+## Counting
+
+`ref_count` starts at 1
+
+Each assign increments the reference count, each time it goes out of scope the reference count is decreased
+
+When `ref_count` hits 0, data is freed
+
+## Tracing
+
+1. Once triggered add a init task to the async queue
+2. This task moves the `gc_head` to the `old_gc_head` and sets the `gc_wait` to off for each thread
+3. Each thread will run down its queue queue marking found gc objects
+3. Once all have run and `marked_threads == available_threads` add a mark and sweep task to the async queue
+4. Async task goes down async queue and does final mark, then a sweep on the `old_gc_head` is done
+5. What remains on the `old_gc_head` is added to the gc tail