My Project
Main Page
Classes
Files
File List
File Members
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Pages
include
sw_list.h
Go to the documentation of this file.
1
/*
2
* OpenVirtualization:
3
* For additional details and support contact
[email protected]
.
4
* Additional documentation can be found at www.openvirtualization.org
5
*
6
* Copyright (C) 2010-2014 SierraWare
7
*
8
* This library is free software; you can redistribute it and/or
9
* modify it under the terms of the GNU General Public License
10
* as published by the Free Software Foundation; either version 2
11
* of the License, or (at your option) any later version.
12
*
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
17
*
18
* You should have received a copy of the GNU General Public License
19
* along with this program; if not, write to the Free Software
20
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
*
22
*/
23
/*
24
* OpenVirtualization:
25
* For additional details and support contact
[email protected]
.
26
* Additional documentation can be found at www.openvirtualization.org
27
*
28
* Copyright (C) 2011 SierraWare
29
*
30
* This library is free software; you can redistribute it and/or
31
* modify it under the terms of the GNU General Public License
32
* as published by the Free Software Foundation; either version 2
33
* of the License, or (at your option) any later version.
34
*
35
* This program is distributed in the hope that it will be useful,
36
* but WITHOUT ANY WARRANTY; without even the implied warranty of
37
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38
* GNU General Public License for more details.
39
*
40
* You should have received a copy of the GNU General Public License
41
* along with this program; if not, write to the Free Software
42
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
43
*
44
* list declrations
45
*/
46
47
#ifndef __LIB_LIST_H__
48
#define __LIB_LIST_H__
49
50
#define LIST_POISON_PREV 0xDEADBEEF
51
#define LIST_POISON_NEXT 0xFADEBABE
52
56
struct
list
{
57
struct
list
*
next
, *
prev
;
58
};
59
60
#define INIT_HEAD(__lname) { &(__lname), &(__lname) }
61
#define LIST_HEAD(_lname) struct list _lname = INIT_HEAD(_lname)
62
#define INIT_LIST_HEAD(ptr) do { \
63
(ptr)->next = ptr; (ptr)->prev = ptr; \
64
}while (0);
65
66
#define list_entry(ptr, type, member) \
67
((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
68
69
#define list_for_each(curr, head) \
70
for (curr = (head)->next; curr != head; curr = (curr)->next)
71
72
#define list_for_each_entry(ptr, head ,member) \
73
for(ptr = list_entry((head)->next, __typeof__(*ptr), member); \
74
&ptr->member != (head); \
75
ptr = list_entry(ptr->member.next , __typeof__(*ptr), member))\
76
77
86
#define list_for_each_entry_safe(pos, n, head, member) \
87
for (pos = list_entry((head)->next, typeof(*pos), member), \
88
n = list_entry(pos->member.next, typeof(*pos), member); \
89
&pos->member != (head); \
90
pos = n, n = list_entry(n->member.next, typeof(*n), member))
91
99
static
inline
void
__list_add(
struct
list
*
prev
,
100
struct
list
*
next
,
struct
list
*
new
)
101
{
102
new
->prev =
prev
;
103
new
->
next
=
next
;
104
prev->
next
=
new
;
105
next->
prev
=
new
;
106
}
107
115
static
inline
void
list_add(
struct
list
*
head
,
struct
list
*
new
)
116
{
117
__list_add(head, head->
next
,
new
);
118
}
119
126
static
inline
void
list_add_tail(
struct
list
*tnode,
struct
list
*
new
)
127
{
128
__list_add(tnode->
prev
, tnode,
new
);
129
}
130
138
static
inline
void
__list_del(
struct
list
*node,
139
struct
list
*
prev
,
struct
list
*
next
)
140
{
141
prev->
next
= node->
next
;
142
next->
prev
= node->
prev
;
143
node->
next
= (
void
*)
LIST_POISON_NEXT
;
144
node->
prev
= (
void
*)
LIST_POISON_PREV
;
145
}
146
154
static
inline
void
list_del(
struct
list
*node)
155
{
156
__list_del(node, node->
prev
, node->
next
);
157
}
158
166
static
inline
struct
list
*list_pop_tail(
struct
list
*
head
)
167
{
168
struct
list
*dnode = head->
prev
;
169
list_del(head->
prev
);
170
return
dnode;
171
}
172
180
static
inline
struct
list
*list_pop(
struct
list
*
head
)
181
{
182
struct
list
*dnode = head->
next
;
183
list_del(head->
next
);
184
return
dnode;
185
}
186
194
static
inline
int
list_empty(
struct
list
*
head
)
195
{
196
return
(head->
next
== head);
197
}
198
199
#endif
/* __LIB_LIST_H__ */
LIST_POISON_NEXT
#define LIST_POISON_NEXT
Definition:
sw_list.h:51
list::prev
struct list * prev
Definition:
sw_list.h:57
LIST_POISON_PREV
#define LIST_POISON_PREV
Definition:
sw_list.h:50
list
Definition:
sw_list.h:56
list::next
struct list * next
Definition:
sw_list.h:57
head
struct list head
Definition:
sw_buddy.h:36
Generated on Thu Sep 25 2014 16:32:38 for My Project by
1.8.6