Commit | Line | Data |
---|---|---|
9f36eaed MJ |
1 | /* SPDX-License-Identifier: GPL-2.0 |
2 | * | |
f934e302 MD |
3 | * wrapper/list.h |
4 | * | |
5 | * wrapper around linux/list.h. | |
6 | * | |
7 | * Copyright (C) 2015 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
8 | * | |
f934e302 MD |
9 | * This wrapper code is derived from Linux 3.19.2 include/linux/list.h |
10 | * and include/linux/rculist.h, hence the GPLv2 license applied to this | |
11 | * file. | |
12 | */ | |
13 | ||
9f36eaed MJ |
14 | #ifndef _LTTNG_WRAPPER_LIST_H |
15 | #define _LTTNG_WRAPPER_LIST_H | |
16 | ||
f934e302 MD |
17 | #include <linux/list.h> |
18 | #include <linux/rculist.h> | |
19 | ||
ac5d8d00 MD |
20 | /* |
21 | * return the first or the next element in an RCU protected hlist | |
22 | */ | |
23 | #define lttng_hlist_first_rcu(head) (*((struct hlist_node __rcu **)(&(head)->first))) | |
24 | #define lttng_hlist_next_rcu(node) (*((struct hlist_node __rcu **)(&(node)->next))) | |
25 | #define lttng_hlist_pprev_rcu(node) (*((struct hlist_node __rcu **)((node)->pprev))) | |
26 | ||
f934e302 MD |
27 | #define lttng_hlist_entry_safe(ptr, type, member) \ |
28 | ({ typeof(ptr) ____ptr = (ptr); \ | |
29 | ____ptr ? hlist_entry(____ptr, type, member) : NULL; \ | |
30 | }) | |
31 | ||
32 | /** | |
33 | * lttng_hlist_for_each_entry - iterate over list of given type | |
34 | * @pos: the type * to use as a loop cursor. | |
35 | * @head: the head for your list. | |
36 | * @member: the name of the hlist_node within the struct. | |
37 | */ | |
38 | #define lttng_hlist_for_each_entry(pos, head, member) \ | |
39 | for (pos = lttng_hlist_entry_safe((head)->first, typeof(*(pos)), member);\ | |
40 | pos; \ | |
41 | pos = lttng_hlist_entry_safe((pos)->member.next, typeof(*(pos)), member)) | |
42 | ||
43 | /** | |
44 | * lttng_hlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry | |
45 | * @pos: the type * to use as a loop cursor. | |
46 | * @n: another &struct hlist_node to use as temporary storage | |
47 | * @head: the head for your list. | |
48 | * @member: the name of the hlist_node within the struct. | |
49 | */ | |
50 | #define lttng_hlist_for_each_entry_safe(pos, n, head, member) \ | |
51 | for (pos = lttng_hlist_entry_safe((head)->first, typeof(*pos), member);\ | |
52 | pos && ({ n = pos->member.next; 1; }); \ | |
53 | pos = lttng_hlist_entry_safe(n, typeof(*pos), member)) | |
54 | ||
f934e302 | 55 | #endif /* _LTTNG_WRAPPER_LIST_H */ |