diff options
| author | nodist <kevin.comas.git@gmail.com> | 2026-06-11 12:08:10 -0400 |
|---|---|---|
| committer | nodist <kevin.comas.git@gmail.com> | 2026-06-11 12:08:10 -0400 |
| commit | 20a19f433956f063d8048f032aaf5dcce1d61e7c (patch) | |
| tree | c9720211c62e75a245c252c82f6353e5162fcb86 /docs/application | |
| parent | 51d055dc7e1a6edbaedb7ea80b1e678eff924fe0 (diff) | |
add algo for mutating shared object
Diffstat (limited to 'docs/application')
| -rw-r--r-- | docs/application/gc.md | 35 | ||||
| -rw-r--r-- | docs/application/index.md | 4 | ||||
| -rw-r--r-- | docs/application/io.md | 2 | ||||
| -rw-r--r-- | docs/application/namespace.md | 32 | ||||
| -rw-r--r-- | docs/application/pool.md | 2 | ||||
| -rw-r--r-- | docs/application/shared.md | 41 | ||||
| -rw-r--r-- | docs/application/thread.md | 9 | ||||
| -rw-r--r-- | docs/application/type.md | 7 |
8 files changed, 70 insertions, 62 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; |
