4 * @brief Extra handy list utils.
6 * @author Yury Georgievskiy. CERN AB/CO.
10 * Can be used by the driver and in the user space.
12 * @version 1.0 ygeorgie 15/05/2008 Creation date.
14 #ifndef _LIST_EXTRA_H_INCLUDE_
15 #define _LIST_EXTRA_H_INCLUDE_
17 #if defined (__linux__) && defined(__KERNEL__)
19 #include <linux/kernel.h>
20 #include <linux/list.h>
21 #include <linux/version.h>
24 #if !defined(__KERNEL__) && !defined(__LYNXOS)
25 /* for user-space only */
29 //!< A way to declare list in a header file
30 #define DECLARE_GLOB_LIST_HEAD(list_name) \
31 _DECL struct list_head list_name _INIT(LIST_HEAD_INIT(list_name))
34 * list_capacity - how many elements in the list
36 * @head: the list to test.
38 static inline int list_capacity(struct list_head
*head
)
41 struct list_head
*at
= head
;
43 while (at
->next
!= head
) {
52 * list_next - pointer to the next element in the list
54 * @head: current list element
56 static inline struct list_head
* list_next(struct list_head
*head
)
63 * list_prev - pointer to the previous element in the list
65 * @head: current list element
67 static inline struct list_head
* list_prev(struct list_head
*head
)
74 * list_idx - get element of the list
76 * @head: the list in question
77 * @idx: list element index (starting from 0) to get
79 static inline struct list_head
* list_idx(struct list_head
*head
, int idx
)
82 struct list_head
*at
= NULL
;
84 list_for_each(at
, head
) {
93 * list_free_all_safe - delete and free all elements safe from the list
95 * All list elements should be allocated entities only!
97 * @head: the head for your list
98 * @type: the type of the struct this is embedded in
99 * @member: the name of the list_struct within the struct
101 #define list_free_all_safe(head, type, member) \
104 struct list_head *__list, *__safe; \
106 list_for_each_safe(__list, __safe, head) { \
107 __element = list_entry(__list, type, member); \
108 list_del(&__element->member); \
114 #ifndef list_last_entry
115 #define list_last_entry(ptr, type, member) \
116 list_entry((ptr)->prev, type, member)
119 #endif /* _LIST_EXTRA_H_INCLUDE_ */