summaryrefslogtreecommitdiff
path: root/docs/application/shared.md
diff options
context:
space:
mode:
authornodist <kevin.comas.git@gmail.com>2026-06-11 12:08:10 -0400
committernodist <kevin.comas.git@gmail.com>2026-06-11 12:08:10 -0400
commit20a19f433956f063d8048f032aaf5dcce1d61e7c (patch)
treec9720211c62e75a245c252c82f6353e5162fcb86 /docs/application/shared.md
parent51d055dc7e1a6edbaedb7ea80b1e678eff924fe0 (diff)
add algo for mutating shared object
Diffstat (limited to 'docs/application/shared.md')
-rw-r--r--docs/application/shared.md41
1 files changed, 41 insertions, 0 deletions
diff --git a/docs/application/shared.md b/docs/application/shared.md
new file mode 100644
index 0000000..753bd82
--- /dev/null
+++ b/docs/application/shared.md
@@ -0,0 +1,41 @@
+# Shared
+
+---
+
+## Object Definition
+
+```c
+typedef struct _kpl_shared {
+ POOL_HEADER(_kpl_shared);
+ _Atomic bool mutating;
+ bool mark;
+ kpl_class class;
+ kpl_task *queue_head, queue_tail;
+ pthread_spinlock_t lock;
+} kpl_shared;
+
+static _Atomic int32_t shared_threads;
+
+static pthread_mutex_t shared_head_mutex;
+
+static kpl_shared *shared_head_sweep, *shared_head;
+```
+
+## Tracing
+
+1. Once triggered add a init task to the async queue
+2. This task moves the `shared_head` to the `shared_head_sweep` and sets the `shared_wait` to off for each thread
+3. Each thread will run down its queue queue marking found shared objects
+3. Once all have run and `shared_threads == available_threads` add a mark and sweep task to the async queue
+4. The async queue is moved to a temp queue and as each item on the tmep queue is marked it is moved back to the async queue
+5. A sweep on the `shared_head_sweep` is done
+6. What remains on the `shared_head_sweep` is added to `shared_head`
+
+## Mutating
+
+1. Check if state of `mutating`
+ 1. If false, set to true and add the task to the `async_queue_head`
+ 2. Once complete lock `lock` and check the `queue_head`
+ 3. If empty set the state of `mutating` to false
+ 4. Else queue the next task
+2. If the state of `mutating` is true add the task to `queue_tail`