-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathqueue.h
More file actions
43 lines (37 loc) · 1.62 KB
/
queue.h
File metadata and controls
43 lines (37 loc) · 1.62 KB
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
37
38
39
40
41
42
43
/*
* Lists and queues.
*
* Relevant OSes provide BSD-originated sys/queue.h, so just use it here, with
* a few extensions.
*/
#pragma once
#include <sys/queue.h>
#include "catomic.h"
/*
* Atomically insert a new list head
*/
#define SLIST_INSERT_HEAD_ATOMIC(head, elm, field) ({ \
typeof(elm) old_slh_first; \
do { \
/* Grab the current head and make the new element point to it */ \
(elm)->field.sle_next = catomic_read(&(head)->slh_first); \
old_slh_first = (elm)->field.sle_next; \
\
/* Repeat until slh_first matches old_slh_first at the time of cmpxchg */ \
} while (catomic_cmpxchg(&(head)->slh_first, old_slh_first, (elm)) != \
old_slh_first); \
old_slh_first; })
/*
* Atomically move the list into 'dest' leaving 'src' empty
*/
#define SLIST_MOVE_ATOMIC(dest, src) do { \
(dest)->slh_first = catomic_xchg(&(src)->slh_first, NULL); \
} while (0)
/*
* Read the current list head with consume
*/
#define SLIST_FIRST_RCU(head) catomic_rcu_read(&(head)->slh_first)
#define LIST_FOREACH_SAFE(elm, head, field, tmp_elm) \
for ((elm) = ((head)->lh_first); \
(elm) && ((tmp_elm) = LIST_NEXT((elm), field), 1); \
(elm) = (tmp_elm))