aboutsummaryrefslogtreecommitdiff
path: root/include/kpl/queue.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/kpl/queue.h')
-rw-r--r--include/kpl/queue.h40
1 files changed, 40 insertions, 0 deletions
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);