Deleted Added
full compact
xge-list.h (171095) xge-list.h (173139)
1/*-
2 * Copyright (c) 2002-2007 Neterion, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
1/*-
2 * Copyright (c) 2002-2007 Neterion, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: head/sys/dev/nxge/include/xge-list.h 171095 2007-06-29 22:47:18Z sam $
26 * $FreeBSD: head/sys/dev/nxge/include/xge-list.h 173139 2007-10-29 14:19:32Z rwatson $
27 */
28
27 */
28
29/*
30 * FileName : xge-list.h
31 *
32 * Description: Generic bi-directional linked list implementation
33 *
34 * Created: 14 May 2004
35 */
36
37#ifndef XGE_LIST_H
38#define XGE_LIST_H
39
40#include <dev/nxge/include/xge-debug.h>
41
42__EXTERN_BEGIN_DECLS
43
44/**

--- 26 unchanged lines hidden (view full) ---

71 * header: first element of the list (head)
72 *
73 * Determine whether the bi-directional list is empty. Return '1' in
74 * case of 'empty'.
75 * See also: xge_list_t{}.
76 */
77static inline int xge_list_is_empty(xge_list_t *header)
78{
29#ifndef XGE_LIST_H
30#define XGE_LIST_H
31
32#include <dev/nxge/include/xge-debug.h>
33
34__EXTERN_BEGIN_DECLS
35
36/**

--- 26 unchanged lines hidden (view full) ---

63 * header: first element of the list (head)
64 *
65 * Determine whether the bi-directional list is empty. Return '1' in
66 * case of 'empty'.
67 * See also: xge_list_t{}.
68 */
69static inline int xge_list_is_empty(xge_list_t *header)
70{
79 xge_assert(header != NULL);
71 xge_assert(header != NULL);
80
72
81 return header->next == header;
73 return header->next == header;
82}
83
84/**
85 * xge_list_first_get - Return the first item from the linked list.
86 * header: first element of the list (head)
87 *
88 * Returns the next item from the header.
89 * Returns NULL if the next item is header itself
90 * See also: xge_list_remove(), xge_list_insert(), xge_list_t{}.
91 */
92static inline xge_list_t *xge_list_first_get(xge_list_t *header)
93{
94 xge_assert(header != NULL);
95 xge_assert(header->next != NULL);
96 xge_assert(header->prev != NULL);
97
98 if(header->next == header)
74}
75
76/**
77 * xge_list_first_get - Return the first item from the linked list.
78 * header: first element of the list (head)
79 *
80 * Returns the next item from the header.
81 * Returns NULL if the next item is header itself
82 * See also: xge_list_remove(), xge_list_insert(), xge_list_t{}.
83 */
84static inline xge_list_t *xge_list_first_get(xge_list_t *header)
85{
86 xge_assert(header != NULL);
87 xge_assert(header->next != NULL);
88 xge_assert(header->prev != NULL);
89
90 if(header->next == header)
99 return NULL;
91 return NULL;
100 else
92 else
101 return header->next;
93 return header->next;
102}
103
104/**
105 * xge_list_remove - Remove the specified item from the linked list.
106 * item: element of the list
107 *
108 * Remove item from a list.
109 * See also: xge_list_insert(), xge_list_t{}.

--- 16 unchanged lines hidden (view full) ---

126 * new_item: new element of the list
127 * prev_item: element of the list after which the new element is
128 * inserted
129 *
130 * Insert new item (new_item) after given item (prev_item).
131 * See also: xge_list_remove(), xge_list_insert_before(), xge_list_t{}.
132 */
133static inline void xge_list_insert (xge_list_t *new_item,
94}
95
96/**
97 * xge_list_remove - Remove the specified item from the linked list.
98 * item: element of the list
99 *
100 * Remove item from a list.
101 * See also: xge_list_insert(), xge_list_t{}.

--- 16 unchanged lines hidden (view full) ---

118 * new_item: new element of the list
119 * prev_item: element of the list after which the new element is
120 * inserted
121 *
122 * Insert new item (new_item) after given item (prev_item).
123 * See also: xge_list_remove(), xge_list_insert_before(), xge_list_t{}.
124 */
125static inline void xge_list_insert (xge_list_t *new_item,
134 xge_list_t *prev_item)
126 xge_list_t *prev_item)
135{
136 xge_assert(new_item != NULL);
137 xge_assert(prev_item != NULL);
138 xge_assert(prev_item->next != NULL);
139
140 new_item->next = prev_item->next;
141 new_item->prev = prev_item;
142 prev_item->next->prev = new_item;
143 prev_item->next = new_item;
144}
145
146/**
147 * xge_list_insert_before - Insert a new item before the specified item.
148 * new_item: new element of the list
149 * next_item: element of the list after which the new element is inserted
150 *
151 * Insert new item (new_item) before given item (next_item).
152 */
153static inline void xge_list_insert_before (xge_list_t *new_item,
127{
128 xge_assert(new_item != NULL);
129 xge_assert(prev_item != NULL);
130 xge_assert(prev_item->next != NULL);
131
132 new_item->next = prev_item->next;
133 new_item->prev = prev_item;
134 prev_item->next->prev = new_item;
135 prev_item->next = new_item;
136}
137
138/**
139 * xge_list_insert_before - Insert a new item before the specified item.
140 * new_item: new element of the list
141 * next_item: element of the list after which the new element is inserted
142 *
143 * Insert new item (new_item) before given item (next_item).
144 */
145static inline void xge_list_insert_before (xge_list_t *new_item,
154 xge_list_t *next_item)
146 xge_list_t *next_item)
155{
156 xge_assert(new_item != NULL);
157 xge_assert(next_item != NULL);
158 xge_assert(next_item->next != NULL);
159
160 new_item->next = next_item;
161 new_item->prev = next_item->prev;
162 next_item->prev->next = new_item;
163 next_item->prev = new_item;
164}
165
166#define xge_list_for_each(_p, _h) \
167 for (_p = (_h)->next, xge_os_prefetch(_p->next); _p != (_h); \
147{
148 xge_assert(new_item != NULL);
149 xge_assert(next_item != NULL);
150 xge_assert(next_item->next != NULL);
151
152 new_item->next = next_item;
153 new_item->prev = next_item->prev;
154 next_item->prev->next = new_item;
155 next_item->prev = new_item;
156}
157
158#define xge_list_for_each(_p, _h) \
159 for (_p = (_h)->next, xge_os_prefetch(_p->next); _p != (_h); \
168 _p = _p->next, xge_os_prefetch(_p->next))
160 _p = _p->next, xge_os_prefetch(_p->next))
169
170#define xge_list_for_each_safe(_p, _n, _h) \
161
162#define xge_list_for_each_safe(_p, _n, _h) \
171 for (_p = (_h)->next, _n = _p->next; _p != (_h); \
172 _p = _n, _n = _p->next)
163 for (_p = (_h)->next, _n = _p->next; _p != (_h); \
164 _p = _n, _n = _p->next)
173
174#ifdef __GNUC__
175/**
176 * xge_container_of - Given a member, return the containing structure.
165
166#ifdef __GNUC__
167/**
168 * xge_container_of - Given a member, return the containing structure.
177 * @ptr: the pointer to the member.
178 * @type: the type of the container struct this is embedded in.
179 * @member: the name of the member within the struct.
169 * @ptr: the pointer to the member.
170 * @type: the type of the container struct this is embedded in.
171 * @member: the name of the member within the struct.
180 *
181 * Cast a member of a structure out to the containing structure.
182 */
172 *
173 * Cast a member of a structure out to the containing structure.
174 */
183#define xge_container_of(ptr, type, member) ({ \
184 __typeof( ((type *)0)->member ) *__mptr = (ptr); \
185 (type *)(void *)( (char *)__mptr - ((size_t) &((type *)0)->member) );})
175#define xge_container_of(ptr, type, member) ({ \
176 __typeof( ((type *)0)->member ) *__mptr = (ptr); \
177 (type *)(void *)( (char *)__mptr - ((size_t) &((type *)0)->member) );})
186#else
187/* type unsafe version */
188#define xge_container_of(ptr, type, member) \
178#else
179/* type unsafe version */
180#define xge_container_of(ptr, type, member) \
189 ((type*)(void*)((char*)(ptr) - ((size_t) &((type *)0)->member)))
181 ((type*)(void*)((char*)(ptr) - ((size_t) &((type *)0)->member)))
190#endif
191
192/**
193 * xge_offsetof - Offset of the member in the containing structure.
182#endif
183
184/**
185 * xge_offsetof - Offset of the member in the containing structure.
194 * @t: struct name.
195 * @m: the name of the member within the struct.
186 * @t: struct name.
187 * @m: the name of the member within the struct.
196 *
197 * Return the offset of the member @m in the structure @t.
198 */
199#define xge_offsetof(t, m) ((size_t) (&((t *)0)->m))
200
201__EXTERN_END_DECLS
202
203#endif /* XGE_LIST_H */
188 *
189 * Return the offset of the member @m in the structure @t.
190 */
191#define xge_offsetof(t, m) ((size_t) (&((t *)0)->m))
192
193__EXTERN_END_DECLS
194
195#endif /* XGE_LIST_H */