aboutsummaryrefslogtreecommitdiff
path: root/include/kpl
diff options
context:
space:
mode:
authornodist <kevin.comas.git@gmail.com>2026-09-28 16:15:39 -0400
committernodist <kevin.comas.git@gmail.com>2026-09-28 16:15:39 -0400
commit2e908a7be31558cc98a9f0e97556e49ee5748c16 (patch)
tree3c8d8a7123d46b5e2b8f6a5c9943faf4c64c2efd /include/kpl
parent9a82127c476bf99556bbc69e181025afcba19d26 (diff)
inline some queue fns
Diffstat (limited to 'include/kpl')
-rw-r--r--include/kpl/code.h4
-rw-r--r--include/kpl/io.h4
-rw-r--r--include/kpl/macro.h2
-rw-r--r--include/kpl/process.h15
-rw-r--r--include/kpl/queue.h20
-rw-r--r--include/kpl/system.h8
-rw-r--r--include/kpl/type.h19
7 files changed, 50 insertions, 22 deletions
diff --git a/include/kpl/code.h b/include/kpl/code.h
index fb44f86..1902c42 100644
--- a/include/kpl/code.h
+++ b/include/kpl/code.h
@@ -7,8 +7,8 @@
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_POW2_DEFAULT = 7,
+ KPL_CONFIG_CODE_QUEUE_POW2_MAX = 10,
} kpl_config_code_queue_pow;
typedef struct {
diff --git a/include/kpl/io.h b/include/kpl/io.h
index 514f2d4..a1b4b3f 100644
--- a/include/kpl/io.h
+++ b/include/kpl/io.h
@@ -19,3 +19,7 @@ typedef struct {
kpl_config_io *config_io;
// TODO
} kpl_io;
+
+bool kpl_io_init(kpl_io *io);
+
+void kpl_io_free(kpl_io *io);
diff --git a/include/kpl/macro.h b/include/kpl/macro.h
index cdcaa1f..e0b59e5 100644
--- a/include/kpl/macro.h
+++ b/include/kpl/macro.h
@@ -11,3 +11,5 @@
#define KPL_PRINT_TODO(MESSAGE) _KPL_PRINT_(LIGHT_YELLOW, MESSAGE)
#define KPL_PRINT_ERROR(MESSAGE) _KPL_PRINT_(LIGHT_RED, MESSAGE)
+
+#define KPL_PAGE_SIZE_ROUND(SIZE) ((SIZE + (getpagesize() - 1)) & ~(getpagesize() - 1))
diff --git a/include/kpl/process.h b/include/kpl/process.h
index 7d13daf..528365a 100644
--- a/include/kpl/process.h
+++ b/include/kpl/process.h
@@ -22,23 +22,11 @@ typedef struct {
int8_t count, ring_pool_entries_pow2[KPL_CONFIG_THREAD_RING_POOL_COUNT];
} kpl_config_thread;
-typedef struct _kpl_env kpl_env;
-
-typedef void kpl_task_fn(kpl_task *task, kpl_env *env);
-
-typedef struct _kpl_task {
- struct _kpl_task *_Atomic next, *join;
- // TODO
- kpl_result result;
- int32_t thread_id;
- _Atomic bool join_ready;
-} kpl_task;
-
typedef struct {
int32_t thread_id;
+ _Atomic ssize_t priority;
kpl_env *env;
kpl_task_queue task_queue;
- _Atomic ssize_t priority;
// TODO
sem_t sem;
pthread_t pthread;
@@ -46,7 +34,6 @@ typedef struct {
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
index 977a32d..0107434 100644
--- a/include/kpl/queue.h
+++ b/include/kpl/queue.h
@@ -5,8 +5,6 @@
#include "kpl/macro.h"
-typedef struct _kpl_task kpl_task;
-
typedef struct {
kpl_task *_Atomic head, *tail;
struct {
@@ -14,9 +12,17 @@ typedef struct {
} dummy;
} kpl_task_queue;
-void kpl_task_queue_init(kpl_task_queue *task_queue);
+inline void kpl_task_queue_init(kpl_task_queue *task_queue) {
+ __atomic_store_n(&task_queue->dummy.next, NULL, __ATOMIC_RELAXED);
+ __atomic_store_n(&task_queue->head, &task_queue->dummy, __ATOMIC_RELAXED);
+ task_queue->tail = (kpl_task*) &task_queue->dummy;
+}
-void kpl_task_queue_add(kpl_task_queue *task_queue, kpl_task *task);
+inline void kpl_task_queue_add(kpl_task_queue *task_queue, kpl_task *task) {
+ __atomic_store_n(&task->next, NULL, __ATOMIC_RELAXED);
+ kpl_task *head = __atomic_exchange_n(&task_queue->head, task, __ATOMIC_SEQ_CST);
+ __atomic_store_n(&head->next, task, __ATOMIC_RELEASE);
+}
kpl_task *kpl_task_queue_next(kpl_task_queue *task_queue);
@@ -31,14 +37,16 @@ typedef struct {
} kpl_ring_queue_item;
typedef struct {
- size_t items_mask;
+ size_t mmap_size, items_mask;
_Atomic ssize_t head_index, tail_index;
kpl_ring_queue_item *items;
} kpl_ring_queue;
bool kpl_ring_queue_init(kpl_ring_queue *ring_queue, int8_t size_pow2);
-void kpl_ring_queue_free(kpl_ring_queue *ring_queue);
+inline void kpl_ring_queue_free(kpl_ring_queue *ring_queue) {
+ munmap(ring_queue->items, ring_queue->mmap_size);
+}
bool kpl_ring_queue_add(kpl_ring_queue *ring_queue, void *data);
diff --git a/include/kpl/system.h b/include/kpl/system.h
index 3f897ab..2d1ec48 100644
--- a/include/kpl/system.h
+++ b/include/kpl/system.h
@@ -11,3 +11,11 @@
#include <ctype.h>
#include <pthread.h>
#include <semaphore.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#include <sys/uio.h>
+#include <linux/fs.h>
+#include <linux/io_uring.h>
diff --git a/include/kpl/type.h b/include/kpl/type.h
index b068080..5003cf0 100644
--- a/include/kpl/type.h
+++ b/include/kpl/type.h
@@ -32,3 +32,22 @@ typedef struct {
kpl_value value;
int64_t tag;
} kpl_result;
+
+typedef struct _kpl_task kpl_task;
+
+typedef struct _kpl_env kpl_env;
+
+typedef void kpl_task_fn(kpl_task *task, kpl_env *env);
+
+typedef struct _kpl_task {
+ struct _kpl_task *_Atomic next, *join;
+ kpl_task_fn *task_fn;
+ int32_t io_res;
+ uint32_t io_flags;
+ int32_t thread_id;
+ _Atomic bool canceled __attribute__((aligned(4))), join_ready __attribute__((aligned(8)));
+ kpl_result result;
+ // TODO TASK ARGUMENTS
+} kpl_task;
+
+