diff options
| author | nodist <kevin.comas.git@gmail.com> | 2026-09-23 12:32:31 -0400 |
|---|---|---|
| committer | nodist <kevin.comas.git@gmail.com> | 2026-09-23 12:32:31 -0400 |
| commit | 07af98f3a5a54a8736109ed031d3177508943299 (patch) | |
| tree | 032427fabed19c59349c51ce842517e6895a33b8 /include/kpl/queue.h | |
| parent | d93466b950ff760a1dd7fd0c2d8ae72c8f1ee0b5 (diff) | |
add task queues
Diffstat (limited to 'include/kpl/queue.h')
| -rw-r--r-- | include/kpl/queue.h | 40 |
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); |
