File size: 966 Bytes
29f097e
32b4893
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/* SPDX-License-Identifier: LicenseRef-Sovereign-Leviathan-SL-AGPL3-001
 * Copyright (C) 2026 SNAPKITTYWEST / Sovereign Kernel Project
 * CLONE_GATE: sparse-router-formal::deque
 */

#ifndef SPARSE_ROUTER_DEQUE_H
#define SPARSE_ROUTER_DEQUE_H

#include "types.h"

static inline bool deque_push(work_deque_t *d, const task_t *t) {
    if (d->count >= DEQUE_CAPACITY) return false;
    d->tasks[d->tail] = *t;
    d->tail = (d->tail + 1) % DEQUE_CAPACITY;
    d->count++;
    return true;
}

static inline bool deque_pop(work_deque_t *d, task_t *out) {
    if (d->count == 0) return false;
    d->count--;
    d->tail = (d->tail == 0) ? DEQUE_CAPACITY - 1 : d->tail - 1;
    *out = d->tasks[d->tail];
    return true;
}

static inline bool deque_steal(work_deque_t *d, task_t *out) {
    if (d->count == 0) return false;
    *out = d->tasks[d->head];
    d->head = (d->head + 1) % DEQUE_CAPACITY;
    d->count--;
    return true;
}

#endif /* SPARSE_ROUTER_DEQUE_H */