aboutsummaryrefslogtreecommitdiffstats
path: root/include/nvgpu/list.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/nvgpu/list.h')
-rw-r--r--include/nvgpu/list.h104
1 files changed, 0 insertions, 104 deletions
diff --git a/include/nvgpu/list.h b/include/nvgpu/list.h
deleted file mode 100644
index 1608035..0000000
--- a/include/nvgpu/list.h
+++ /dev/null
@@ -1,104 +0,0 @@
1/*
2 * Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
21 */
22
23#ifndef NVGPU_LIST_H
24#define NVGPU_LIST_H
25#include <nvgpu/types.h>
26
27struct nvgpu_list_node {
28 struct nvgpu_list_node *prev;
29 struct nvgpu_list_node *next;
30};
31
32static inline void nvgpu_init_list_node(struct nvgpu_list_node *node)
33{
34 node->prev = node;
35 node->next = node;
36}
37
38static inline void nvgpu_list_add(struct nvgpu_list_node *new_node, struct nvgpu_list_node *head)
39{
40 new_node->next = head->next;
41 new_node->next->prev = new_node;
42 new_node->prev = head;
43 head->next = new_node;
44}
45
46static inline void nvgpu_list_add_tail(struct nvgpu_list_node *new_node, struct nvgpu_list_node *head)
47{
48 new_node->prev = head->prev;
49 new_node->prev->next = new_node;
50 new_node->next = head;
51 head->prev = new_node;
52}
53
54static inline void nvgpu_list_del(struct nvgpu_list_node *node)
55{
56 node->prev->next = node->next;
57 node->next->prev = node->prev;
58 nvgpu_init_list_node(node);
59}
60
61static inline bool nvgpu_list_empty(struct nvgpu_list_node *head)
62{
63 return head->next == head;
64}
65
66static inline void nvgpu_list_move(struct nvgpu_list_node *node, struct nvgpu_list_node *head)
67{
68 nvgpu_list_del(node);
69 nvgpu_list_add(node, head);
70}
71
72static inline void nvgpu_list_replace_init(struct nvgpu_list_node *old_node, struct nvgpu_list_node *new_node)
73{
74 new_node->next = old_node->next;
75 new_node->next->prev = new_node;
76 new_node->prev = old_node->prev;
77 new_node->prev->next = new_node;
78 nvgpu_init_list_node(old_node);
79}
80
81#define nvgpu_list_entry(ptr, type, member) \
82 type ## _from_ ## member(ptr)
83
84#define nvgpu_list_next_entry(pos, type, member) \
85 nvgpu_list_entry((pos)->member.next, type, member)
86
87#define nvgpu_list_first_entry(ptr, type, member) \
88 nvgpu_list_entry((ptr)->next, type, member)
89
90#define nvgpu_list_last_entry(ptr, type, member) \
91 nvgpu_list_entry((ptr)->prev, type, member)
92
93#define nvgpu_list_for_each_entry(pos, head, type, member) \
94 for (pos = nvgpu_list_first_entry(head, type, member); \
95 &pos->member != (head); \
96 pos = nvgpu_list_next_entry(pos, type, member))
97
98#define nvgpu_list_for_each_entry_safe(pos, n, head, type, member) \
99 for (pos = nvgpu_list_first_entry(head, type, member), \
100 n = nvgpu_list_next_entry(pos, type, member); \
101 &pos->member != (head); \
102 pos = n, n = nvgpu_list_next_entry(n, type, member))
103
104#endif /* NVGPU_LIST_H */