]>
git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/ocf/tests/unit/tests/ocf_env/ocf_env_list.h
2 * Copyright(c) 2012-2018 Intel Corporation
3 * SPDX-License-Identifier: BSD-3-Clause-Clear
9 #define LIST_POISON1 ((void *)0x101)
10 #define LIST_POISON2 ((void *)0x202)
13 * List entry structure mimicking linux kernel based one.
16 struct list_head
*next
;
17 struct list_head
*prev
;
23 #define INIT_LIST_HEAD(l) { (l)->prev = l; (l)->next = l; }
26 * Add item to list head.
27 * @param it list entry to be added
28 * @param l1 list main node (head)
30 static inline void list_add(struct list_head
*it
, struct list_head
*l1
)
40 * Add item it to tail.
41 * @param it list entry to be added
42 * @param l1 list main node (head)
44 static inline void list_add_tail(struct list_head
*it
, struct list_head
*l1
)
54 * check if a list is empty (return true)
55 * @param l1 list main node (head)
57 static inline int list_empty(struct list_head
*l1
)
59 return l1
->next
== l1
;
63 * delete an entry from a list
64 * @param it list entry to be deleted
66 static inline void list_del(struct list_head
*it
)
68 it
->next
->prev
= it
->prev
;
69 it
->prev
->next
= it
->next
;
74 * @param list_head_i list head item, from which entry is extracted
75 * @param item_type type (struct) of list entry
76 * @param field_name name of list_head field within item_type
78 #define list_entry(list_head_i, item_type, field_name) \
79 (item_type *)(((void*)(list_head_i)) - offsetof(item_type, field_name))
81 #define list_first_entry(list_head_i, item_type, field_name) \
82 list_entry((list_head_i)->next, item_type, field_name)
85 * @param iterator uninitialized list_head pointer, to be used as iterator
86 * @param plist list head (main node)
88 #define list_for_each(iterator, plist) \
89 for (iterator = (plist)->next; \
90 (iterator)->next != (plist)->next; \
91 iterator = (iterator)->next)
94 * Safe version of list_for_each which works even if entries are deleted during
96 * @param iterator uninitialized list_head pointer, to be used as iterator
97 * @param q another uninitialized list_head, used as helper
98 * @param plist list head (main node)
101 * Algorithm handles situation, where q is deleted.
102 * consider in example 3 element list with header h:
104 * h -> 1 -> 2 -> 3 ->
111 #define list_for_each_safe(iterator, q, plist) \
112 for (iterator = (q = (plist)->next->next)->prev; \
113 (q) != (plist)->next; \
114 iterator = (q = (q)->next)->prev)
116 #define _list_entry_helper(item, head, field_name) \
117 list_entry(head, typeof(*item), field_name)
120 * Iterate over list entries.
121 * @param list pointer to list item (iterator)
122 * @param plist pointer to list_head item
123 * @param field_name name of list_head field in list entry
125 #define list_for_each_entry(item, plist, field_name) \
126 for (item = _list_entry_helper(item, (plist)->next, field_name); \
127 _list_entry_helper(item, (item)->field_name.next, field_name) !=\
128 _list_entry_helper(item, (plist)->next, field_name); \
129 item = _list_entry_helper(item, (item)->field_name.next, field_name))
132 * Safe version of list_for_each_entry which works even if entries are deleted
134 * @param list pointer to list item (iterator)
135 * @param q another pointer to list item, used as helper
136 * @param plist pointer to list_head item
137 * @param field_name name of list_head field in list entry
139 #define list_for_each_entry_safe(item, q, plist, field_name) \
140 for (item = _list_entry_helper(item, (plist)->next, field_name), \
141 q = _list_entry_helper(item, (item)->field_name.next, field_name); \
142 _list_entry_helper(item, (item)->field_name.next, field_name) != \
143 _list_entry_helper(item, (plist)->next, field_name); \
144 item = q, q = _list_entry_helper(q, (q)->field_name.next, field_name))