diff options
| -rw-r--r-- | docs/application/error.md | 4 | ||||
| -rw-r--r-- | docs/application/index.md | 2 | ||||
| -rw-r--r-- | docs/application/map.md | 6 | ||||
| -rw-r--r-- | docs/application/memory.md | 50 | ||||
| -rw-r--r-- | docs/application/namespace.md | 6 | ||||
| -rw-r--r-- | docs/application/native.md | 2 | ||||
| -rw-r--r-- | docs/application/pool.md | 35 | ||||
| -rw-r--r-- | docs/application/queue.md | 4 | ||||
| -rw-r--r-- | docs/application/shared.md | 6 | ||||
| -rw-r--r-- | docs/application/thread.md | 3 | ||||
| -rw-r--r-- | docs/application/union.md | 4 | ||||
| -rw-r--r-- | mkdocs.yml | 2 |
12 files changed, 70 insertions, 54 deletions
diff --git a/docs/application/error.md b/docs/application/error.md index dcf0a34..77a97cb 100644 --- a/docs/application/error.md +++ b/docs/application/error.md @@ -6,9 +6,9 @@ ```c typedef struct _kpl_error { - KPL_POOL_HEADER(_kpl_error); - int32_t line; + KPL_SLAB_HEADER(_kpl_error); char *file, *function; kpl_class class; + int32_t line; } kpl_error; ``` diff --git a/docs/application/index.md b/docs/application/index.md index f15f0a0..21ca20f 100644 --- a/docs/application/index.md +++ b/docs/application/index.md @@ -12,7 +12,7 @@ * ##### [Interface](./interface.md) * ##### [Type](./type.md) -* ##### [Pool](./pool.md) +* ##### [Memory](./memory.md) # ##### [Name](./name.md) * ##### [Thread](./thread.md) * ##### [Io](./io.md) diff --git a/docs/application/map.md b/docs/application/map.md index f2400a6..fd412e5 100644 --- a/docs/application/map.md +++ b/docs/application/map.md @@ -6,15 +6,15 @@ ```c typedef struct _kpl_map_bucket { - KPL_POOL_HEADER(_kpl_map_bucket); + KPL_SLAB_HEADER(_kpl_map_bucket); kpl_any key, value; } kpl_map_bucket; typedef struct _kpl_map { KPL_POOL_HEADER(_kpl_map); - int32_t length; + uint32_t length; kpl_interface *key_interface, *value_interface; - kpl_map_bucket *buckets[]; kpl_map_bucket *head, *tail; + kpl_map_bucket *buckets[]; } kpl_map; ``` diff --git a/docs/application/memory.md b/docs/application/memory.md new file mode 100644 index 0000000..8340141 --- /dev/null +++ b/docs/application/memory.md @@ -0,0 +1,50 @@ +# Memory Pool + +--- + +## Object Definitions + +```c +#define KPL_SLAB_HEADER(STRUCT) struct STRUCT *prev, *next; + +typedef struct _kpl_slab_obj { + KPL_SLAB_HEADER(_kpl_slab_obj); +} kpl_slab_obj; + +typedef struct _kpl_slab { + size_t array_index; + struct _kpl_slab *next; + uint8_t array[]; +} kpl_slab_alloc; + +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; + +#define KPL_POOL_HEADER(STRUCT) KPL_SLAB_HEADER(STRUCT); uint32_t obj_byte_size + +typedef struct _kpl_pool_obj { + KPL_POOL_HEADER(_kpl_pool_obj); +} 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; +``` + +## Pool Object Size + +The max size of an object in the pool is 2 \*\* 32 + +This allows for 4 aligned bytes after the `POOL_HEADER` macro + +## List Management + +## Tree Management diff --git a/docs/application/namespace.md b/docs/application/namespace.md index 3dd6bfa..96d9045 100644 --- a/docs/application/namespace.md +++ b/docs/application/namespace.md @@ -6,12 +6,12 @@ ```c typedef struct _kpl_export { - POOL_HEADER(_kpl_export); + SLAB_HEADER(_kpl_export); kpl_type_ptr type; } kpl_export; typedef struct _kpl_namespace_native { - POOL_HEADER(_kpl_namespace_native); + SLAB_HEADER(_kpl_namespace_native); kpl_buffer *name; kpl_export *exports; } kpl_namespace_native; @@ -19,7 +19,7 @@ typedef struct _kpl_namespace_native { static kpl_namespace_native *namespace_native_head; typedef struct _kpl_namespace_module { - POOL_HEADER(_kpl_namespace_module); + SLAB_HEADER(_kpl_namespace_module); kpl_type_ptr ast; kpl_queue *parents; kpl_buffer *module_name, *module_string; diff --git a/docs/application/native.md b/docs/application/native.md index 523de66..9d4b917 100644 --- a/docs/application/native.md +++ b/docs/application/native.md @@ -4,7 +4,7 @@ ```c typedef struct _kpl_native { - KPL_POOL_HEADER(_kpl_native); + KPL_SLAB_HEADER(_kpl_native); kpl_class class; } kpl_native; ``` diff --git a/docs/application/pool.md b/docs/application/pool.md deleted file mode 100644 index 3fc3e79..0000000 --- a/docs/application/pool.md +++ /dev/null @@ -1,35 +0,0 @@ -# Memory Pool - ---- - -## Object Definitions - -```c -#define KPL_POOL_HEADER(STRUCT) struct STRUCT *prev, *next; uint32_t obj_byte_size - -typedef struct _kpl_pool_obj { - KPL_POOL_HEADER(_kpl_pool_obj); -} kpl_pool_obj; - -typedef void kpl_pool_on_fn(void *obj); - -typedef strut { - uint32_t min_obj_size; - _Atomic size_t alloc_byte_size; - kpl_pool_obj *root; - kpl_pool_on_fn *on_init, *on_free; - pthread_mutex_t root_mutex; -} kpl_pool; - -static kpl_pool_obj *kpl_pool_head; -``` - -## Object Size - -The max size of an object in the pool is 2 \*\* 32 - -This allows for 4 aligned bytes after the `POOL_HEADER` macro - -## List Management - -## Tree Management diff --git a/docs/application/queue.md b/docs/application/queue.md index cab2e0b..a04461e 100644 --- a/docs/application/queue.md +++ b/docs/application/queue.md @@ -6,12 +6,12 @@ ```c typedef struct _kpl_queue_item { - KPL_POOL_HEADER(_kpl_queue_item); + KPL_SLAB_HEADER(_kpl_queue_item); kpl_any any; } kpl_queue_item; typedef struct _kpl_queue { - KPL_POOL_HEADER(_kpl_queue); + KPL_SLAB_HEADER(_kpl_queue); uint32_t length; kpl_interface *interface; kpl_pool_any *head, *tail; diff --git a/docs/application/shared.md b/docs/application/shared.md index b666684..bed94d2 100644 --- a/docs/application/shared.md +++ b/docs/application/shared.md @@ -6,10 +6,10 @@ ```c typedef struct _kpl_shared { - KPL_POOL_HEADER(_kpl_shared); - _Atomic bool mutating; - bool mark; + KPL_SLAB_HEADER(_kpl_shared); void *data; kpl_atomic_queue queue; + _Atomic bool mutating; + bool mark; } kpl_shared; ``` diff --git a/docs/application/thread.md b/docs/application/thread.md index 06410e6..231b0fe 100644 --- a/docs/application/thread.md +++ b/docs/application/thread.md @@ -78,6 +78,7 @@ iterator : arguments, locals, iterator functions, iterator function index # Example ```c +// gcc -std=gnu99 -Wall -Wextra -O2 -fhardened -fno-omit-frame-pointer -o thread_queue thread_queue.c #define _GNU_SOURCE #include <stdlib.h> #include <stdio.h> @@ -311,7 +312,7 @@ void *task_loop(void *arg) { void task_run() { for (int32_t thread_id = 1; thread_id < avaiable_threads; thread_id++) pthread_create(&threads[thread_id].thread, NULL, task_loop, (void*) (intptr_t) thread_id); - task_loop(0); + task_loop(MAIN_THREAD); for (int32_t thread_id = 1; thread_id < avaiable_threads; thread_id++) pthread_join(threads[thread_id].thread, NULL); } diff --git a/docs/application/union.md b/docs/application/union.md index 0032c0d..fa19e6d 100644 --- a/docs/application/union.md +++ b/docs/application/union.md @@ -6,8 +6,8 @@ ```c typedef struct _kpl_union { - KPL_POOL_HEADER(_kpl_union); - uint32_t tag; + KPL_SLAB_HEADER(_kpl_union); kpl_class class; + uint32_t tag; } kpl_union; ``` @@ -41,7 +41,7 @@ nav: - Runtime: 'application/index.md' - Interface: 'application/interface.md' - Type: 'application/type.md' - - Pool: 'application/pool.md' + - Memory: 'application/memory.md' - Name: 'application/name.md' - Thread: 'application/thread.md' - Io: 'application/io.md' |
