2 * Copyright 2005 Timo Hirvonen
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
28 /* this usually points to the list head */
31 /* these point to the list item, for simple lists data2 is usually NULL */
36 static inline void iter_init(struct iter
*iter
)
43 static inline void iter_head(struct iter
*iter
)
49 static inline int iters_equal(struct iter
*a
, struct iter
*b
)
51 return a
->data0
== b
->data0
&&
52 a
->data1
== b
->data1
&&
56 static inline int iter_is_head(struct iter
*iter
)
58 return iter
->data0
!= NULL
&&
59 iter
->data1
== NULL
&&
63 static inline int iter_is_null(struct iter
*iter
)
65 return iter
->data0
== NULL
&&
66 iter
->data1
== NULL
&&
70 static inline int iter_is_empty(struct iter
*iter
)
72 return iter
->data0
== NULL
|| (iter
->data1
== NULL
&& iter
->data2
== NULL
);
75 #define GENERIC_ITER_PREV(FUNC, TYPE, MEMBER) \
76 int FUNC(struct iter *iter) \
78 struct list_head *head = iter->data0; \
79 TYPE *e = iter->data1; \
81 BUG_ON(iter->data2); \
85 /* head, get last */ \
86 if (head->prev == head) { \
87 /* empty, iter points to the head already */ \
90 iter->data1 = container_of(head->prev, TYPE, MEMBER); \
93 if (e->MEMBER.prev == head) { \
97 iter->data1 = container_of(e->MEMBER.prev, TYPE, MEMBER); \
101 #define GENERIC_ITER_NEXT(FUNC, TYPE, MEMBER) \
102 int FUNC(struct iter *iter) \
104 struct list_head *head = iter->data0; \
105 TYPE *e = iter->data1; \
107 BUG_ON(iter->data2); \
111 /* head, get first */ \
112 if (head->next == head) { \
113 /* empty, iter points to the head already */ \
116 iter->data1 = container_of(head->next, TYPE, MEMBER); \
119 if (e->MEMBER.next == head) { \
120 iter->data1 = NULL; \
123 iter->data1 = container_of(e->MEMBER.next, TYPE, MEMBER); \