VCOM Linux Driver
Advantech Inc.
Loading...
Searching...
No Matches
advlist.h
Go to the documentation of this file.
1#ifndef _ADV_LIST_H
2#define _ADV_LIST_H
3
4struct list_head {
5 struct list_head *next, *prev;
6};
7
8#define LIST_HEAD_INIT(name) { &(name), &(name) }
9#define LIST_HEAD(name) \
10struct list_head name = LIST_HEAD_INIT(name)
11
12static inline void INIT_LIST_HEAD(struct list_head *head)
13{
14 head->next = head;
15 head->prev = head;
16}
17
18static inline int list_empty(const struct list_head *head)
19{
20 return head->next == head;
21}
22
23static void __list_add(struct list_head *new_lst,
24 struct list_head *prev,
25 struct list_head *next)
26{
27 next->prev = new_lst;
28 new_lst->next = next;
29 new_lst->prev = prev;
30 prev->next = new_lst;
31}
32
33static inline void list_add(struct list_head *new_lst,
34 struct list_head *head)
35{
36 __list_add(new_lst, head, head->next);
37}
38
39
40static inline void list_add_tail(struct list_head *new_lst, struct list_head *head)
41{
42 __list_add(new_lst, head->prev, head);
43}
44
45static void __list_del(struct list_head * prev,
46 struct list_head * next )
47{
48 next->prev = prev;
49 prev->next = next;
50}
51
52#define LIST_POISON1 0
53#define LIST_POISON2 0
54
55static inline void list_del(struct list_head * entry)
56{
57 __list_del(entry->prev,entry->next);
58 entry->next = LIST_POISON1;
59 entry->prev = LIST_POISON2;
60}
61
62#if __linux__ // or #if __GNUC__
63 #if __LP64__
64 #define ENVIRONMENT64
65 #pragma message("Linux 64bit")
66 #else
67 #define ENVIRONMENT32
68 #pragma message("Linux 32bit")
69 #endif
70#else
71 #if _WIN32
72 #define ENVIRONMENT32
73 #pragma message("Windows 32bit")
74 #else
75 #define ENVIRONMENT64
76 #pragma message("Windows 64bit")
77 #endif
78#endif // __linux__
79
80#ifdef ENVIRONMENT64
81 #define PTR_OFFSET (unsigned long long int)
82#else
83 #define PTR_OFFSET (unsigned long int)
84#endif // ENVIRONMENT64
85
86#define list_for_each(pos, head) \
87 for (pos = (head)->next; pos != (head); pos = pos->next)
88
89#define list_for_each_safe(pos, n, head) \
90 for (pos = (head)->next, n = pos->next; pos != (head); \
91 pos = n, n = pos->next)
92
93#define adv_offsetof(TYPE, MEMBER) (PTR_OFFSET &((TYPE *)0)->MEMBER)
94
95#define container_of(ptr, type, member) ({ \
96 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
97 (type *)( (char *)__mptr - adv_offsetof(type,member) );})
98
99#define list_entry(ptr,type,member) \
100 container_of(ptr, type, member)
101
102#endif
#define LIST_POISON2
Definition advlist.h:53
#define LIST_POISON1
Definition advlist.h:52
Definition advlist.h:4
struct list_head * next
Definition advlist.h:5
struct list_head * prev
Definition advlist.h:5