diff options
Diffstat (limited to 'include/kpl/queue.h')
| -rw-r--r-- | include/kpl/queue.h | 20 |
1 files changed, 14 insertions, 6 deletions
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); |
