aboutsummaryrefslogtreecommitdiff
path: root/include/kpl
diff options
context:
space:
mode:
authornodist <kevin.comas.git@gmail.com>2026-09-23 12:32:31 -0400
committernodist <kevin.comas.git@gmail.com>2026-09-23 12:32:31 -0400
commit07af98f3a5a54a8736109ed031d3177508943299 (patch)
tree032427fabed19c59349c51ce842517e6895a33b8 /include/kpl
parentd93466b950ff760a1dd7fd0c2d8ae72c8f1ee0b5 (diff)
add task queues
Diffstat (limited to 'include/kpl')
-rw-r--r--include/kpl/code.h25
-rw-r--r--include/kpl/io.h13
-rw-r--r--include/kpl/process.h32
-rw-r--r--include/kpl/queue.h40
-rw-r--r--include/kpl/system.h1
5 files changed, 92 insertions, 19 deletions
diff --git a/include/kpl/code.h b/include/kpl/code.h
new file mode 100644
index 0000000..fb44f86
--- /dev/null
+++ b/include/kpl/code.h
@@ -0,0 +1,25 @@
+
+#pragma once
+
+// Queues and trees for code life cycle
+
+#include "kpl/queue.h"
+
+typedef enum : int8_t {
+ KPL_CONFIG_CODE_QUEUE_POW2_MIN = 4,
+ KPL_CONFIG_CODE_QUEUE_POW2_DEFAULT = 6,
+ KPL_CONFIG_CODE_QUEUE_POW2_MAX = 8,
+} kpl_config_code_queue_pow;
+
+typedef struct {
+ int8_t queue_pow2;
+} kpl_config_code;
+
+// TODO namespace tree
+
+// TODO module tree
+
+typedef struct {
+ kpl_config_code *config_code;
+ kpl_ring_queue code_queue;
+} kpl_code;
diff --git a/include/kpl/io.h b/include/kpl/io.h
index 9a85d1f..514f2d4 100644
--- a/include/kpl/io.h
+++ b/include/kpl/io.h
@@ -5,16 +5,17 @@
#include "kpl/macro.h"
-typedef enum : int32_t {
- KPL_IO_QUEUE_POW_MIN = 4,
- KPL_IO_QUEUE_POW_DEFAULT = 10,
- KPL_IO_QUEUE_POW_MAX = 16
+typedef enum : int8_t {
+ KPL_CONFIG_IO_QUEUE_POW2_MIN = 4,
+ KPL_CONFIG_IO_QUEUE_POW2_DEFAULT = 10,
+ KPL_CONFIG_IO_QUEUE_POW2_MAX = 16
} kpl_io_queue_pow_options;
typedef struct {
- int32_t queue_pow;
+ int8_t queue_pow2;
} kpl_config_io;
typedef struct {
-
+ kpl_config_io *config_io;
+ // TODO
} kpl_io;
diff --git a/include/kpl/process.h b/include/kpl/process.h
index d46fd2f..b47e122 100644
--- a/include/kpl/process.h
+++ b/include/kpl/process.h
@@ -3,14 +3,25 @@
// Kpl threads, allocators, atomic queues and garbage collection
-#include "kpl/macro.h"
+#include "kpl/queue.h"
+
+typedef enum : int8_t {
+ KPL_CONFIG_THREAD_COUNT_AFFINITY = -1,
+ KPL_CONFIG_THREAD_COUNT_MAX = 127
+} kpl_config_thread_count;
+
+typedef enum : uint8_t {
+ KPL_CONFIG_THREAD_RING_POOL_COUNT = 28,
+ KPL_CONFIG_THREAD_RING_POOL_MIN_OBJECT_SIZE_POW2 = 5,
+ KPL_CONFIG_THREAD_RING_POOL_MAX_OBJECT_SIZE_POW2 = 27,
+ KPL_CONFIG_THREAD_RING_POOL_MIN_RING_SIZE_POW2 = 6,
+ KPL_CONFIG_THREAD_RING_POOL_MAX_RING_SIZE_POW2 = 20
+} kpl_config_thread_ring_pool;
typedef struct {
- int32_t count;
+ int8_t count, ring_pool_entries_pow2[KPL_CONFIG_THREAD_RING_POOL_COUNT];
} kpl_config_thread;
-typedef struct _kpl_task kpl_task;
-
typedef struct _kpl_env kpl_env;
typedef void kpl_task_fn(kpl_task *task, kpl_env *env);
@@ -24,21 +35,16 @@ typedef struct _kpl_task {
} kpl_task;
typedef struct {
- kpl_task *_Atomic head, *_Atomic tail;
- struct {
- kpl_task *_Atomic next;
- } dummy;
-} kpl_task_queue;
-
-typedef struct {
kpl_task_queue task_queue;
_Atomic ssize_t priority;
// TODO
- sem_t spin_counter;
- pthread_t thread;
+ sem_t sem;
+ pthread_t pthread;
} kpl_thread;
typedef struct {
+ kpl_config_thread *config_thread;
_Atomic ssize_t total_priority;
kpl_thread *threads;
+ kpl_ring_queue memory_pool[KPL_CONFIG_THREAD_RING_POOL_COUNT];
} kpl_process;
diff --git a/include/kpl/queue.h b/include/kpl/queue.h
new file mode 100644
index 0000000..3d77e13
--- /dev/null
+++ b/include/kpl/queue.h
@@ -0,0 +1,40 @@
+
+#pragma once
+
+// KPL atomic queues
+
+#include "kpl/macro.h"
+
+typedef struct _kpl_task kpl_task;
+
+typedef struct {
+ kpl_task *_Atomic head, *tail;
+ struct {
+ kpl_task *_Atomic next;
+ } dummy;
+} kpl_task_queue;
+
+void kpl_task_queue_init(kpl_task_queue *task_queue);
+
+void kpl_task_queue_add(kpl_task_queue *task_queue, kpl_task *task);
+
+kpl_task *kpl_task_queue_next(kpl_task_queue *task_queue);
+
+typedef struct {
+ _Atomic ssize_t index;
+ void *data;
+} kpl_ring_queue_item;
+
+typedef struct {
+ size_t items_mask;
+ _Atomic ssize_t head_index, tail_index;
+ kpl_ring_queue_item *items;
+} kpl_ring_queue;
+
+void kpl_ring_queue_init(kpl_ring_queue *ring_queue, int8_t size_pow);
+
+void kpl_ring_queue_free(kpl_ring_queue *ring_queue);
+
+bool kpl_ring_queue_add(kpl_ring_queue *ring_queue, void *data);
+
+void *kpl_ring_queue_next(kpl_ring_queue *ring_queue);
diff --git a/include/kpl/system.h b/include/kpl/system.h
index 201c1b6..3f897ab 100644
--- a/include/kpl/system.h
+++ b/include/kpl/system.h
@@ -8,5 +8,6 @@
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
+#include <ctype.h>
#include <pthread.h>
#include <semaphore.h>