From 7964cf08ac807ac9e7b6d579a25321a23adc9139 Mon Sep 17 00:00:00 2001 From: nodist Date: Tue, 16 Jun 2026 12:42:41 -0400 Subject: new layout by dependecy graph --- docs/application/index.md | 9 +++++---- docs/application/memory.md | 10 +++++----- docs/application/mutex.md | 23 +++++++++++++++++++++++ docs/application/namespace.md | 2 +- docs/application/shared.md | 14 +------------- docs/language/ownership.md | 2 +- docs/type_system/const.md | 2 +- docs/type_system/empty.md | 4 ++-- docs/type_system/ref.md | 2 +- docs/type_system/select.md | 6 +++--- docs/type_system/shared.md | 10 +++++----- mkdocs.yml | 9 +++++---- 12 files changed, 53 insertions(+), 40 deletions(-) create mode 100644 docs/application/mutex.md diff --git a/docs/application/index.md b/docs/application/index.md index 21ca20f..be3d621 100644 --- a/docs/application/index.md +++ b/docs/application/index.md @@ -11,20 +11,21 @@ # Sections * ##### [Interface](./interface.md) -* ##### [Type](./type.md) -* ##### [Memory](./memory.md) -# ##### [Name](./name.md) * ##### [Thread](./thread.md) +* ##### [Mutex](./mutex.md) +* ##### [Memory](./memory.md) * ##### [Io](./io.md) +* ##### [Name](./name.md) * ##### [Shared](./shared.md) +* ##### [Type](./type.md) * ##### [Group](./group.md) * ##### [Buffer](./buffer.md) * ##### [Map](./map.md) * ##### [Queue](./queue.md) * ##### [Union](./union.md) * ##### [Native](./native.md) -* ##### [Error](./error.md) * ##### [Namespace](./namespace.md) +* ##### [Error](./error.md) * ##### [Testing](./testing.md) # Invocation diff --git a/docs/application/memory.md b/docs/application/memory.md index 2689b62..eda866f 100644 --- a/docs/application/memory.md +++ b/docs/application/memory.md @@ -20,9 +20,9 @@ typedef struct _kpl_slab { typedef struct { uint32_t object_size, array_size; _Atomic size_t slab_length; - kpl_slab *root; - kpl_slab_obj *pool; - pthread_mutex_t slab_pool_mutex; + kpl_slab *slab; + kpl_slab_obj *head; + kpl_mutex mutex; } kpl_slab; #define KPL_POOL_HEADER(STRUCT) KPL_SLAB_HEADER(STRUCT); uint32_t obj_byte_size @@ -34,8 +34,8 @@ typedef struct _kpl_pool_obj { typedef strut { uint32_t min_obj_size; _Atomic size_t alloc_byte_size; - kpl_pool_obj *root; - pthread_mutex_t root_mutex; + kpl_pool_obj *head; + kpl_mutex mutex; } kpl_pool; ``` diff --git a/docs/application/mutex.md b/docs/application/mutex.md new file mode 100644 index 0000000..999f5dc --- /dev/null +++ b/docs/application/mutex.md @@ -0,0 +1,23 @@ +# Mutex + +--- + +## Object Definitions + +```c +typedef struct { + kpl_atomic_queue queue; + _Atomic int32_t lock; +} kpl_mutex; +``` + +## Usage + +1. Before adding to the `queue` do `value = lock++` +2. Add to the queue +3. If `value` is `0` the thread does an async schedule of the mutex task, otherwise the thread moves on + +### Mutex Task + +1. Get task from `queue` and run task +2. After task completion, do `value = --lock`, stop if `value` is `0`, otherwise repeat diff --git a/docs/application/namespace.md b/docs/application/namespace.md index 96d9045..ab38d3f 100644 --- a/docs/application/namespace.md +++ b/docs/application/namespace.md @@ -20,11 +20,11 @@ static kpl_namespace_native *namespace_native_head; typedef struct _kpl_namespace_module { SLAB_HEADER(_kpl_namespace_module); - kpl_type_ptr ast; kpl_queue *parents; kpl_buffer *module_name, *module_string; kpl_export *exports; kpl_task *task; + kpl_type_ptr ast; _Atomic int32_t children; } kpl_namespace_module; diff --git a/docs/application/shared.md b/docs/application/shared.md index b2760c5..95616c9 100644 --- a/docs/application/shared.md +++ b/docs/application/shared.md @@ -8,21 +8,9 @@ typedef struct _kpl_shared { KPL_SLAB_HEADER(_kpl_shared); void *data; - kpl_atomic_queue queue; - _Atomic uint32_t lock; + kpl_mutex mutex; bool mark; } kpl_shared; ``` -## Mutating - -1. Before adding to the `queue` do `value = lock++` -2. Add to the queue -3. If `value` is `0` the thread does an async schedule of the mutator task, otherwise the thread moves on - -### Mutator Task - -1. Get task from `queue` and run task -2. After task completion, do `value = --lock`, stop if `value` is `0`, otherwise repeat - ## Garbage Collection diff --git a/docs/language/ownership.md b/docs/language/ownership.md index 490363f..db48c6a 100644 --- a/docs/language/ownership.md +++ b/docs/language/ownership.md @@ -19,7 +19,7 @@ References are automatically taken if the function signature specifies ref ```text -inc_push_to_ref : ([Ref.x; y] +inc_push_to_ref : ([`ref x; y] x `push y + 1 ) int_array : Array[I64] $ () diff --git a/docs/type_system/const.md b/docs/type_system/const.md index cb9cd74..2d818de 100644 --- a/docs/type_system/const.md +++ b/docs/type_system/const.md @@ -5,5 +5,5 @@ Cannot be changed or mutated ```text -Const[[] TYPE] +`const ``` diff --git a/docs/type_system/empty.md b/docs/type_system/empty.md index 09869d6..08b0977 100644 --- a/docs/type_system/empty.md +++ b/docs/type_system/empty.md @@ -5,7 +5,7 @@ Container type can be null ```text -Empty[[] TYPE] +`empty ``` ## Use with `Option` Union @@ -17,7 +17,7 @@ make_array : ([yes] `nome } ) -v : make_array(...) // Empty[Array[I64]] $ .none OR Empty[Array[I64]] $ (.some : (1; 2; 3)) +v : make_array(...) // `empty Array[I64] $ .none OR `empty Array[I64] $ (.some : (1; 2; 3)) # v { .some {[x] `log x } // Array[I64] $ (1; 2; 3) .none { ... } diff --git a/docs/type_system/ref.md b/docs/type_system/ref.md index a856e72..e47367f 100644 --- a/docs/type_system/ref.md +++ b/docs/type_system/ref.md @@ -3,7 +3,7 @@ --- ```text -Ref[[] TYPE] +`ref ``` A reference, cannot be assigned diff --git a/docs/type_system/select.md b/docs/type_system/select.md index b2f8f61..979e9d1 100644 --- a/docs/type_system/select.md +++ b/docs/type_system/select.md @@ -5,15 +5,15 @@ A symbol associated with a type ```text -Select[[SINGLE | MULTIPLE] Type; Collection[.symbol : Const[Value]]] +Select[[SINGLE | MULTIPLE] Type; Collection[.symbol : `const Value]] ``` # Alias ```text -Enum[Generic.T; Collection[.symbol : Const[Value]]] `alias Select[[SINGLE]; Generic.T; Collection[.symbol : Const[Value]]] +Enum[Generic.T; Collection[.symbol : `const Value]] `alias Select[[SINGLE]; Generic.T; Collection[.symbol : `const Value]] -Mask[Generic.T; Collection[.symbol : Const[Value]]] `alias Select[[MULTIPLE]; Generic.T; Collection[.symbol : Const[Value]]] +Mask[Generic.T; Collection[.symbol : `const Value]] `alias Select[[MULTIPLE]; Generic.T; Collection[.symbol : `const Value]] ``` ## Definition Example diff --git a/docs/type_system/shared.md b/docs/type_system/shared.md index d1d3f07..9ddef26 100644 --- a/docs/type_system/shared.md +++ b/docs/type_system/shared.md @@ -5,7 +5,7 @@ Hold multiple references to the same object ```text -Shared[[] Type] +`shared ``` # Garbage Collection @@ -15,11 +15,11 @@ A tracing mark and sweep garbage collector is used # Mutating ```text -x : Shared[Array] $ (1; 2; 3) +x : `shared Array $ (1; 2; 3) ^ x {[y] y `push 4 } -`log x // Shared[Array[I64]] $ (1; 2; 3; 4) +`log x // `shared Array[I64] $ (1; 2; 3; 4) ``` # Operators @@ -31,8 +31,8 @@ x : Shared[Array] $ (1; 2; 3) ### Example sharing data between two shared objects ```text -x : Shared $ 1 -y : Shared $ 0 +x : `shared 1 +y : `shared 0 z : ^ x {[x] x } ^ y {[y] y : z } diff --git a/mkdocs.yml b/mkdocs.yml index ba06564..5a20b4b 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -40,18 +40,19 @@ nav: - Application: - Runtime: 'application/index.md' - Interface: 'application/interface.md' - - Type: 'application/type.md' - - Memory: 'application/memory.md' - - Name: 'application/name.md' - Thread: 'application/thread.md' + - Mutex: 'application/mutex.md' + - Memory: 'application/memory.md' - Io: 'application/io.md' + - Name: 'application/name.md' - Shared: 'application/shared.md' + - Type: 'application/type.md' - Group: 'application/group.md' - Buffer: 'application/buffer.md' - Map: 'application/map.md' - Queue: 'application/queue.md' - Union: 'application/union.md' - Native: 'application/native.md' - - Error: 'application/error.md' - Namespace: 'application/namespace.md' + - Error: 'application/error.md' - Testing: 'application/testing.md' -- cgit v1.2.3