diff options
Diffstat (limited to 'docs/application')
| -rw-r--r-- | docs/application/index.md | 11 | ||||
| -rw-r--r-- | docs/application/interface.md | 46 | ||||
| -rw-r--r-- | docs/application/pool.md | 10 | ||||
| -rw-r--r-- | docs/application/testing.md | 17 | ||||
| -rw-r--r-- | docs/application/thread.md (renamed from docs/application/process.md) | 47 | ||||
| -rw-r--r-- | docs/application/type.md | 7 |
6 files changed, 131 insertions, 7 deletions
diff --git a/docs/application/index.md b/docs/application/index.md index b9a5e0b..3809ac9 100644 --- a/docs/application/index.md +++ b/docs/application/index.md @@ -2,10 +2,19 @@ --- +## Requirements + +* Linux X64 +* GNU Make +* GCC with -std=gnu99 -fhardened + ## Sections +* ##### [Interface](./interface.md) +* ##### [Type](./type.md) * ##### [Pool](./pool.md) -* ##### [Process](./process.md) +* ##### [Thread](./thread.md) +* ##### [Testing](./testing.md) ## Invocation diff --git a/docs/application/interface.md b/docs/application/interface.md new file mode 100644 index 0000000..1493aff --- /dev/null +++ b/docs/application/interface.md @@ -0,0 +1,46 @@ +# Interface + +--- + +General definitions used throughout the code + +## Object Definitions + +```c +typedef union { + bool b; + uint8_t u8; + uint16_t u16; + uint32_t u32; + uint64_t u64; + int8_t i8; + int16_t i16; + int32_t i32; + int64_t i64; + float f32; + double f64; + void *ptr; +} kpl_any; + +typedef size_t kpl_any_hash_fn(const kpl_any a); + +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 int32_t kpl_any_print_fn(const kpl_any a, FILE *file, size_t idnt, uint32_t print_opts); + +typedef void kpl_any_free_fn(kpl_any a); + +typedef struct { + kpl_any_hash_fn *hash_fn; + kpl_any_eq_fn *eq_fn; + kpl_any_cmp_fn *cmp_fn; + kpl_any_print_fn *print_fn; + kpl_any_free_fn *free_fn; +} kpl_any_interace; + +typedef struct { + any value, info; +} kpl_result; +``` diff --git a/docs/application/pool.md b/docs/application/pool.md index dc7c1e3..b4c5913 100644 --- a/docs/application/pool.md +++ b/docs/application/pool.md @@ -1,3 +1,13 @@ # Memory Pool --- + +## Object Definitions + +```c +#define POOL_HEADER(STRUCT) struct STRUCT *prev, *next; uint32_t obj_size + +typedef struct _kpl_pool_obj { + POOL_HEADER(_kpl_pool_obj); +} kpl_pool_obj; +``` diff --git a/docs/application/testing.md b/docs/application/testing.md new file mode 100644 index 0000000..8657bf0 --- /dev/null +++ b/docs/application/testing.md @@ -0,0 +1,17 @@ +# Testing + +--- + +## Macros + +```c +TEST(NAME) { + // TEST BODY +} + +ASSERT(CONDITION) + +FAIL() +``` + +## Object Definitions diff --git a/docs/application/process.md b/docs/application/thread.md index 2934201..04d9c98 100644 --- a/docs/application/process.md +++ b/docs/application/thread.md @@ -1,7 +1,39 @@ -# Processes +# Threads --- +## Object Definitions + +```c +typedef struct _kpl_task kpl_task; + +typedef void kpl_task_fn(kpl_task *t); + +#ifndef KPL_TASK_STATE_SIZE +#define KPL_TASK_STATE_SIZE 20 +#endif + +typedef struct _kpl_task { + POOL_HEADER(kpl_task); + _Atomic bool join_ready; + uint16_t worker_id; + kpl_any state[KPL_TASK_STATE_SIZE]; + kpl_result ret; + kpl_task_fn *fn; +} kpl_task; + +typedef struct { + kpl_task *head, *tail; + pthread_t thread; +} kpl_thread; + +#define KPL_PROCESSES $(nproc) + +kpl_thread kpl_worker[KPL_PROCESSES] = {}; + +_Atomic uint16_t kpl_worker_running = KPL_PROCESSES; +``` + ## Per Process Task Queue ## Asynchronous Task Queue @@ -14,6 +46,10 @@ # Running +Main thread is kpl_worker[0], threads are started after that + +## Joining + # Example ```c @@ -119,7 +155,6 @@ void task_queue_sync(task *t, int32_t worker_id) { worker[worker_id].tail = worker[worker_id].tail->next = t; else worker[worker_id].head = worker[worker_id].tail = t; - return; } void task_ready_queue(task *t) { @@ -172,7 +207,7 @@ void *task_loop(void *arg) { } running--; if (!running) { - for (intptr_t worker_id = 1; worker_id < PROCESSES; worker_id++) + for (intptr_t worker_id = 0; worker_id < PROCESSES; worker_id++) pthread_cond_signal(&task_async_queue_cond); break; } @@ -199,11 +234,11 @@ fib : Fn[n] $ ( ? { n <= 0 { 0 } n < 2 { 1 } - { + (fib `call n - 1; fib `call n - 2) } + { + (fib `sync n - 1; fib `sync n - 2) } } v : Vector[`fork_type fib] $ () - @ 1 .. I { v `push fib `fork FIB } - @ v {[fib_task] `print "fib(%) = %\n" `format (FIB; `join fib_task) } + @ 1 .. I { v `push fib `async FIB } + @ v {[fib_task] `print "fib(%) = %\n" `format (FIB; `wait fib_task) } `print "Complete\n" ) */ diff --git a/docs/application/type.md b/docs/application/type.md new file mode 100644 index 0000000..4cc2fc8 --- /dev/null +++ b/docs/application/type.md @@ -0,0 +1,7 @@ +# Type + +--- + +## Object Definitions + +## Allocator |
