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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
/* Public domain. */
#ifndef _LINUX_LLIST_H
#define _LINUX_LLIST_H
#include <sys/atomic.h>
struct llist_node {
struct llist_node *next;
};
struct llist_head {
struct llist_node *first;
};
#define llist_entry(ptr, type, member) \
((ptr) ? container_of(ptr, type, member) : NULL)
static inline struct llist_node *
llist_del_all(struct llist_head *head)
{
return atomic_swap_ptr(&head->first, NULL);
}
static inline struct llist_node *
llist_del_first(struct llist_head *head)
{
struct llist_node *first, *next;
do {
first = head->first;
if (first == NULL)
return NULL;
next = first->next;
} while (atomic_cas_ptr(&head->first, first, next) != first);
return first;
}
static inline bool
llist_add(struct llist_node *new, struct llist_head *head)
{
struct llist_node *first;
do {
new->next = first = head->first;
} while (atomic_cas_ptr(&head->first, first, new) != first);
return (first == NULL);
}
static inline void
init_llist_head(struct llist_head *head)
{
head->first = NULL;
}
static inline bool
llist_empty(struct llist_head *head)
{
return (head->first == NULL);
}
#define llist_for_each_entry_safe(pos, n, node, member) \
for (pos = llist_entry((node), __typeof(*pos), member); \
pos != NULL && \
(n = llist_entry(pos->member.next, __typeof(*pos), member), pos); \
pos = n)
#endif
|