diff options
Diffstat (limited to 'docs/application/gc.md')
| -rw-r--r-- | docs/application/gc.md | 23 |
1 files changed, 7 insertions, 16 deletions
diff --git a/docs/application/gc.md b/docs/application/gc.md index ff538ee..e171a05 100644 --- a/docs/application/gc.md +++ b/docs/application/gc.md @@ -7,32 +7,23 @@ ```c typedef struct _kpl_gc { POOL_HEADER(_kpl_gc); - union { - _Atomic int32_t ref_count; - _Atomic bool mark; - } method; + _Atomic bool mark; kpl_any any; pthread_mutex_t mutex; } kpl_gc; static _Atomic size_t gc_threads; -static kpl_gc *old_gc_head, *gc_head; -``` - -## Counting - -`ref_count` starts at 1 +static pthread_mutex_t gc_head_mutex; -Each assign increments the `ref_count`, each time it goes out of scope the `ref_count` is decreased - -When `ref_count` hits 0, data is freed +static kpl_gc *gc_head_sweep, *gc_head; +``` ## 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 +2. This task moves the `gc_head` to the `gc_head_sweep` 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 `gc_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 `gc_head` +4. Async task goes down async queue and does final mark, then a sweep on the `gc_head_sweep` is done +5. What remains on the `gc_head_sweep` is added to `gc_head` |
