summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/application/buffer.md2
-rw-r--r--docs/application/gc.md12
-rw-r--r--docs/application/interface.md2
-rw-r--r--docs/application/io.md2
-rw-r--r--docs/application/namespace.md2
-rw-r--r--docs/application/pool.md5
-rw-r--r--docs/application/thread.md5
-rw-r--r--docs/application/type.md8
-rw-r--r--docs/type_system/gc.md35
-rw-r--r--docs/type_system/index.md2
-rw-r--r--docs/type_system/shared.md24
-rw-r--r--docs/type_system/task.md2
-rw-r--r--docs/type_system/var.md4
-rw-r--r--mkdocs.yml2
14 files changed, 64 insertions, 43 deletions
diff --git a/docs/application/buffer.md b/docs/application/buffer.md
index 230c2d6..f8dff41 100644
--- a/docs/application/buffer.md
+++ b/docs/application/buffer.md
@@ -9,7 +9,7 @@ typedef struct _kpl_buffer {
POOL_HEADER(_kpl_buffer);
uint32_t byte_length;
kpl_interface *interface;
- uint8_t bytes;
+ uint8_t bytes[];
} kpl_buffer;
```
diff --git a/docs/application/gc.md b/docs/application/gc.md
index e171a05..764285b 100644
--- a/docs/application/gc.md
+++ b/docs/application/gc.md
@@ -5,14 +5,19 @@
## 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 size_t gc_threads;
+static _Atomic int32_t gc_threads;
static pthread_mutex_t gc_head_mutex;
@@ -25,5 +30,6 @@ static kpl_gc *gc_head_sweep, *gc_head;
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 `gc_head_sweep` is done
-5. What remains on the `gc_head_sweep` is added to `gc_head`
+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/interface.md b/docs/application/interface.md
index 8a5dc69..da4f4bb 100644
--- a/docs/application/interface.md
+++ b/docs/application/interface.md
@@ -28,6 +28,8 @@ typedef bool kpl_any_eq_fn(const kpl_any a, const kpl_any b);
typedef ssize_t kpl_any_cmp_fn(const kpl_any a, const kpl_any b);
+typedef void kpl_any_gc_mark(kpl_any a);
+
typedef void kpl_any_free_fn(kpl_any a);
// TODO write
diff --git a/docs/application/io.md b/docs/application/io.md
index 7ac8dd8..301d0b4 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 df4dc59..70bbc2d 100644
--- a/docs/application/namespace.md
+++ b/docs/application/namespace.md
@@ -10,8 +10,6 @@ typedef struct _kpl_export {
kpl_type_ptr type;
} kpl_export;
-static queue *export_storage;
-
typedef struct _kpl_native_namespace {
POOL_HEADER(_kpl_native_namespace);
kpl_buffer *name;
diff --git a/docs/application/pool.md b/docs/application/pool.md
index f9baac6..ddbd3ee 100644
--- a/docs/application/pool.md
+++ b/docs/application/pool.md
@@ -11,9 +11,12 @@ typedef struct _kpl_pool_obj {
POOL_HEADER(_kpl_pool_obj);
} kpl_pool_obj;
+typedef void kpl_pool_on_fn(void *obj);
+
typedef strut {
- _Atomic size_t allocs;
+ _Atomic int32_t allocs;
kpl_pool_obj *root;
+ kpl_pool_on_fn *on_init, *on_free;
pthread_mutex_t mutex;
} kpl_pool;
diff --git a/docs/application/thread.md b/docs/application/thread.md
index 7e13d71..fd5bb5d 100644
--- a/docs/application/thread.md
+++ b/docs/application/thread.md
@@ -17,6 +17,7 @@ typedef struct _kpl_task {
kpl_group *state;
kpl_interface *ret_interface;
kpl_result ret;
+ _Atomic int32_t ref_count;
} kpl_task;
typedef struct {
@@ -27,9 +28,9 @@ typedef struct {
#define KPL_MAX_THREADS 64
-static uint16_t available_threads; // find with sched_getaffinity
+static int32_t available_threads; // find with sched_getaffinity
-static _Atomic uint16_t running_threads; // init to available_threads
+static _Atomic int32_t running_threads; // init to available_threads
static kpl_task *async_queue_head, *async_queue_tail;
diff --git a/docs/application/type.md b/docs/application/type.md
index 1967386..735d752 100644
--- a/docs/application/type.md
+++ b/docs/application/type.md
@@ -15,15 +15,15 @@ typedef struct {
static const kpl_type_ptr kpl_type_ptr_null = { UINT16_MAX, UINT16_MAX };
-typedef enum : uint8_t {
+typedef enum : uint16_t {
// ...
} kpl_type_template;
-typedef enum : uint8_t {
+typedef enum : uint16_t {
CONST = 1 << 0
EMPTY = 1 << 1,
REF = 1 << 2,
- SHARED = 1 << 3,
+ GC = 1 << 3
} kpl_type_flags;
typedef union {
@@ -33,7 +33,7 @@ typedef union {
typedef struct {
kpl_type_template template;
kpl_type_flags flags;
- _Atomic unt16_t ref_count;
+ _Atomic int32_t ref_count;
kpl_type_ptr self, prev, next, parent;
kpl_type_body body;
} kpl_type;
diff --git a/docs/type_system/gc.md b/docs/type_system/gc.md
new file mode 100644
index 0000000..3fcf88e
--- /dev/null
+++ b/docs/type_system/gc.md
@@ -0,0 +1,35 @@
+# Gc
+
+---
+
+Hold multiple references to the same object
+
+```text
+Gc[Type; GC_FLAGS]
+```
+
+# Alias
+
+```text
+Shared[Generic.T] `alias Gc[Generic.T; GC_FLAGS]
+```
+
+## `GC_FLAGS`
+
+### Lock Mutex
+
+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
+
+# Mutating
+
+```text
+x : Shared[Array] $ (1; 2; 3)
+^ x {[y]
+ y `push 4
+}
+`log x // Shared[Array[I64]] $ (1; 2; 3; 4)
+```
diff --git a/docs/type_system/index.md b/docs/type_system/index.md
index 8aadc98..3601459 100644
--- a/docs/type_system/index.md
+++ b/docs/type_system/index.md
@@ -66,7 +66,7 @@ Denotes that a field that does not resolve to anything
* #### [Ref](./ref.md)
-* #### [Shared](./shared.md)
+* #### [Gc](./gc.md)
## Function Templates
diff --git a/docs/type_system/shared.md b/docs/type_system/shared.md
deleted file mode 100644
index b6e9ded..0000000
--- a/docs/type_system/shared.md
+++ /dev/null
@@ -1,24 +0,0 @@
-# Shared
-
----
-
-```text
-
-Shared[TYPE]
-```
-
-# Use in Asynchronous Functions
-
-# Garbage Collection
-
-A tracing mark and sweep garbage collector is used
-
-# Mutating
-
-```text
-x : Shared[Array] $ (1; 2; 3)
-^ x {[y]
- y `push 4
-}
-`log x // Shared[Array[I64]] $ (1; 2; 3; 4)
-```
diff --git a/docs/type_system/task.md b/docs/type_system/task.md
index 33879b6..e0d9db3 100644
--- a/docs/type_system/task.md
+++ b/docs/type_system/task.md
@@ -5,7 +5,7 @@
A segment of code assigned to a process, task code can be recursive
```text
-Task[TYPE; FN]
+Task[TYPE]
```
## \`await
diff --git a/docs/type_system/var.md b/docs/type_system/var.md
index 1cab8ed..737263e 100644
--- a/docs/type_system/var.md
+++ b/docs/type_system/var.md
@@ -3,7 +3,7 @@
---
```text
-Var_class `alias Enum[Void; .arg; .local; .loop; .match]
+Var_class `alias Enum[Void; .arg; .local; .loop; .if; .match; .mutate]
-Var[Var_class; TYPE; SCOPE; VAR_IDENTIFIER]
+Var[Var_class; TYPE; Parent; VAR_IDENTIFIER]
```
diff --git a/mkdocs.yml b/mkdocs.yml
index f986333..370bce9 100644
--- a/mkdocs.yml
+++ b/mkdocs.yml
@@ -25,7 +25,7 @@ nav:
- Const: 'type_system/const.md'
- Empty: 'type_system/empty.md'
- Ref: 'type_system/ref.md'
- - Shared: 'type_system/shared.md'
+ - Gc: 'type_system/gc.md'
- Var: 'type_system/var.md'
- Function: 'type_system/function.md'
- Task: 'type_system/task.md'