2 * Copyright (c) 2008, 2009, 2010 Nicira Networks.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 /* Doubly linked list. */
25 /* Doubly linked list head or element. */
27 struct list *prev; /* Previous list element. */
28 struct list *next; /* Next list element. */
31 #define LIST_INITIALIZER(LIST) { LIST, LIST }
33 void list_init(struct list *);
36 void list_insert(struct list *, struct list *);
37 void list_splice(struct list *before, struct list *first, struct list *last);
38 void list_push_front(struct list *, struct list *);
39 void list_push_back(struct list *, struct list *);
40 void list_replace(struct list *, const struct list *);
41 void list_moved(struct list *);
44 struct list *list_remove(struct list *);
45 struct list *list_pop_front(struct list *);
46 struct list *list_pop_back(struct list *);
49 struct list *list_front(struct list *);
50 struct list *list_back(struct list *);
52 /* List properties. */
53 size_t list_size(const struct list *);
54 bool list_is_empty(const struct list *);
56 #define LIST_FOR_EACH(ITER, STRUCT, MEMBER, LIST) \
57 for (ITER = CONTAINER_OF((LIST)->next, STRUCT, MEMBER); \
58 &(ITER)->MEMBER != (LIST); \
59 ITER = CONTAINER_OF((ITER)->MEMBER.next, STRUCT, MEMBER))
60 #define LIST_FOR_EACH_REVERSE(ITER, STRUCT, MEMBER, LIST) \
61 for (ITER = CONTAINER_OF((LIST)->prev, STRUCT, MEMBER); \
62 &(ITER)->MEMBER != (LIST); \
63 ITER = CONTAINER_OF((ITER)->MEMBER.prev, STRUCT, MEMBER))
64 #define LIST_FOR_EACH_SAFE(ITER, NEXT, STRUCT, MEMBER, LIST) \
65 for (ITER = CONTAINER_OF((LIST)->next, STRUCT, MEMBER); \
66 (NEXT = CONTAINER_OF((ITER)->MEMBER.next, STRUCT, MEMBER), \
67 &(ITER)->MEMBER != (LIST)); \