summaryrefslogtreecommitdiff
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
parent51d055dc7e1a6edbaedb7ea80b1e678eff924fe0 (diff)
add algo for mutating shared object
-rw-r--r--docs/application/gc.md35
-rw-r--r--docs/application/index.md4
-rw-r--r--docs/application/io.md2
-rw-r--r--docs/application/namespace.md32
-rw-r--r--docs/application/pool.md2
-rw-r--r--docs/application/shared.md41
-rw-r--r--docs/application/thread.md9
-rw-r--r--docs/application/type.md7
-rw-r--r--docs/type_system/function.md10
-rw-r--r--docs/type_system/index.md4
-rw-r--r--docs/type_system/namespace.md6
-rw-r--r--docs/type_system/shared.md6
-rw-r--r--docs/type_system/value.md2
-rw-r--r--mkdocs.yml2
14 files changed, 84 insertions, 78 deletions
diff --git a/docs/application/gc.md b/docs/application/gc.md
deleted file mode 100644
index 764285b..0000000
--- a/docs/application/gc.md
+++ /dev/null
@@ -1,35 +0,0 @@
-# Garbage Collection
-
----
-
-## Object Definition
-
-```c
-typedef enum : uint16_t {
- LOCK_MUTEX = 1 << 0,
-} kpl_gc_flags;
-
-typedef struct _kpl_gc {
- POOL_HEADER(_kpl_gc);
- _Atomic bool mark;
- int16_t flags;
- kpl_any any;
- pthread_mutex_t mutex;
-} kpl_gc;
-
-static _Atomic int32_t gc_threads;
-
-static pthread_mutex_t gc_head_mutex;
-
-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 `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. 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 `gc_head_sweep` is done
-6. What remains on the `gc_head_sweep` is added to `gc_head`
diff --git a/docs/application/index.md b/docs/application/index.md
index fcc1dad..ccde773 100644
--- a/docs/application/index.md
+++ b/docs/application/index.md
@@ -16,7 +16,7 @@
# ##### [Name](./name.md)
* ##### [Thread](./thread.md)
* ##### [Io](./io.md)
-* ##### [Gc](./gc.md)
+* ##### [Shared](./shared.md)
* ##### [Group](./group.md)
* ##### [Buffer](./buffer.md)
* ##### [Map](./map.md)
@@ -30,7 +30,7 @@
## Main
-### File
+### Module
### String/REPL
diff --git a/docs/application/io.md b/docs/application/io.md
index 301d0b4..9ab786c 100644
--- a/docs/application/io.md
+++ b/docs/application/io.md
@@ -2,4 +2,4 @@
---
-All Io is done through linux io_uring
+All Io is done through linux io uring
diff --git a/docs/application/namespace.md b/docs/application/namespace.md
index 70bbc2d..3dd6bfa 100644
--- a/docs/application/namespace.md
+++ b/docs/application/namespace.md
@@ -10,39 +10,39 @@ typedef struct _kpl_export {
kpl_type_ptr type;
} kpl_export;
-typedef struct _kpl_native_namespace {
- POOL_HEADER(_kpl_native_namespace);
+typedef struct _kpl_namespace_native {
+ POOL_HEADER(_kpl_namespace_native);
kpl_buffer *name;
kpl_export *exports;
-} kpl_native_namespace;
+} kpl_namespace_native;
-static kpl_native_namespace *native_namespace_head;
+static kpl_namespace_native *namespace_native_head;
-typedef struct _kpl_file_namespace {
- POOL_HEADER(_kpl_file_namespace);
+typedef struct _kpl_namespace_module {
+ POOL_HEADER(_kpl_namespace_module);
kpl_type_ptr ast;
kpl_queue *parents;
- kpl_buffer *file_name, *file_string;
+ kpl_buffer *module_name, *module_string;
kpl_export *exports;
kpl_task *task;
_Atomic int32_t children;
-} kpl_file_namespace;
+} kpl_namespace_module;
-static kpl_file_namespace *file_namespace_head;
+static kpl_namespace_module *namespace_module_head;
-typedef struct _kpl_string_namespace {
+typedef struct _kpl_namespace_string {
kpl_buffer *string;
kpl_task *task;
kpl_type_ptr ast;
_Atomic int32_t children;
-} kpl_string_namespace;
+} kpl_namespace_string;
```
-Each `NAMESPACE_IDENTIFIER` maps to `kpl_native_namespace*` or `kpl_file_namespace*` depending on `Namespace_class`
+Each `NAMESPACE_IDENTIFIER` maps to `kpl_namespace_native*` or `kpl_namespace_module*` depending on flags
## Lookup and Storage
-The native and namespace objects are stored as a tree under `native_namespace_head` and `file_namespace_head`
+The native and namespace objects are stored as a tree under `namespace_native_head` and `namespace_module_head`
The exports are stored under a tree for both the native and namespace objects
@@ -50,7 +50,7 @@ The exports are stored under a tree for both the native and namespace objects
## Native
-## File
+## Module
### Main
@@ -60,7 +60,7 @@ The exports are stored under a tree for both the native and namespace objects
# Updating
-## File
+## Module
### ``export`
@@ -70,6 +70,6 @@ The exports are stored under a tree for both the native and namespace objects
### ``use`
-## File
+## Module
### ``import`
diff --git a/docs/application/pool.md b/docs/application/pool.md
index ddbd3ee..8b57ee7 100644
--- a/docs/application/pool.md
+++ b/docs/application/pool.md
@@ -17,7 +17,7 @@ typedef strut {
_Atomic int32_t allocs;
kpl_pool_obj *root;
kpl_pool_on_fn *on_init, *on_free;
- pthread_mutex_t mutex;
+ pthread_spinlock_t lock;
} kpl_pool;
static kpl_pool_obj *kpl_pool_head;
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`
diff --git a/docs/application/thread.md b/docs/application/thread.md
index fd5bb5d..95bd450 100644
--- a/docs/application/thread.md
+++ b/docs/application/thread.md
@@ -11,13 +11,12 @@ typedef void kpl_task_fn(kpl_task *t);
typedef struct _kpl_task {
POOL_HEADER(_kpl_task);
- _Atomic bool join_ready;
- uint16_t worker_id;
+ _Atomic bool next_ready;
+ uint16_t thread_id;
kpl_task_fn *fn;
kpl_group *state;
kpl_interface *ret_interface;
kpl_result ret;
- _Atomic int32_t ref_count;
} kpl_task;
typedef struct {
@@ -41,6 +40,10 @@ static pthread_cond_t async_cond;
static kpl_thread threads[KPL_MAX_THREADS];
```
+## Initialization
+
+On the start of each thread, set the cpu affinity to its thread id
+
## Task State
```text
diff --git a/docs/application/type.md b/docs/application/type.md
index 03cc055..e462e6d 100644
--- a/docs/application/type.md
+++ b/docs/application/type.md
@@ -19,12 +19,11 @@ typedef enum : uint8_t {
// ...
} kpl_type_template;
-typedef enum : uint8_t {
+typedef enum {
CONST = 1 << 0,
EMPTY = 1 << 1,
REF = 1 << 2,
- SHARED = 1 << 3,
- LOCK = 1 << 4
+ SHARED = 1 << 3
} kpl_type_qualifiers;
typedef union {
@@ -33,7 +32,7 @@ typedef union {
typedef struct {
kpl_type_template template;
- kpl_type_qualifiers qualifiers;
+ uint8_t qualifiers;
uint16_t modifiers;
_Atomic int32_t ref_count;
kpl_type_ptr self, prev, next, parent;
diff --git a/docs/type_system/function.md b/docs/type_system/function.md
index d0fabc5..d8244a9 100644
--- a/docs/type_system/function.md
+++ b/docs/type_system/function.md
@@ -3,15 +3,19 @@
---
```text
-KIND : UNKNOWN | INCOMPLETE | NATIVE | TASK | PROCESS | GENERATOR | ITERATOR | CLOSURE | BOUND | REGEX
+INVOCATION : UNKNOWN | SYNC | ASYNC
-Function[[KIND] STATE; List; RETURN_TYPE; Collection[TYPE.SYMBOL]]
+CLASS : INCOMPLETE | NATIVE | TASK | PROCESS | GENERATOR | ITERATOR | CLOSURE | BOUND | REGEX
+
+FLAGS : INVOCATION | CLASS
+
+Function[[FLAGS] STATE; List; RETURN_TYPE; Collection[TYPE.SYMBOL]]
```
# Alias
```text
-Fn[Generic.T; Collection[TYPE.SYMBOL]] `alias Function[[KIND]; STATE; List; Generic.T; Collection[TYPE.SYMBOL]]
+Fn[Generic.T; Collection[TYPE.SYMBOL]] `alias Function[[FLAGS]; STATE; List; Generic.T; Collection[TYPE.SYMBOL]]
```
# Inline Definition
diff --git a/docs/type_system/index.md b/docs/type_system/index.md
index ae574d9..2d9e9c2 100644
--- a/docs/type_system/index.md
+++ b/docs/type_system/index.md
@@ -32,7 +32,7 @@ Template[[] Field; ...]
If a field in a template is not filed, one of these are required:
-### Any
+## Any
Denotes a field in a template that has not resolved
@@ -48,7 +48,7 @@ A list of types with shape of TYPE, only can have one collection per type
If using a collection the Collection[TYPE] must be the last type on the templates type list
-### Void
+## Void
Denotes that a field that does not resolve to anything
diff --git a/docs/type_system/namespace.md b/docs/type_system/namespace.md
index 9243280..9ae61ba 100644
--- a/docs/type_system/namespace.md
+++ b/docs/type_system/namespace.md
@@ -3,11 +3,9 @@
---
```text
-Namespace[[NATIVE | FILE] NAMESPACE_IDENTIFIER]
+Namespace[[NATIVE | MODULE] NAMESPACE_IDENTIFIER]
```
-A file with code
-
## Exports
### \`export
@@ -45,4 +43,4 @@ namespcae[name] // resolves to namespace[name.name]
### \`is_main
-Run this function if the file is not imported
+Run this function if the module is not imported
diff --git a/docs/type_system/shared.md b/docs/type_system/shared.md
index db8e6dc..2af408d 100644
--- a/docs/type_system/shared.md
+++ b/docs/type_system/shared.md
@@ -5,13 +5,9 @@
Hold multiple references to the same object
```text
-Shared[[LOCK] Type]
+Shared[[] Type]
```
-### `LOCK`
-
-The shared type has been detected across asynchronous tasks and needs to lock the mutex on mutation
-
# Garbage Collection
A tracing mark and sweep garbage collector is used
diff --git a/docs/type_system/value.md b/docs/type_system/value.md
index 683b1f2..5cfcf90 100644
--- a/docs/type_system/value.md
+++ b/docs/type_system/value.md
@@ -3,5 +3,5 @@
---
```text
-Value[[] TYPE; DATA]
+Value[[] TYPE; KPL_CLASS]
```
diff --git a/mkdocs.yml b/mkdocs.yml
index f220a9a..6a723a3 100644
--- a/mkdocs.yml
+++ b/mkdocs.yml
@@ -45,7 +45,7 @@ nav:
- Name: 'application/name.md'
- Thread: 'application/thread.md'
- Io: 'application/io.md'
- - Gc: 'application/gc.md'
+ - Shared: 'application/shared.md'
- Group: 'application/group.md'
- Buffer: 'application/buffer.md'
- Map: 'application/map.md'