]> git.proxmox.com Git - mirror_ovs.git/blame - lib/list.h
netdev-linux, netdev-bsd: Make access to AF_INET socket thread-safe.
[mirror_ovs.git] / lib / list.h
CommitLineData
064af421 1/*
e0edde6f 2 * Copyright (c) 2008, 2009, 2010, 2011 Nicira, Inc.
064af421 3 *
a14bc59f
BP
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:
064af421 7 *
a14bc59f
BP
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
064af421
BP
15 */
16#ifndef LIST_H
17#define LIST_H 1
18
19/* Doubly linked list. */
20
21#include <stdbool.h>
22#include <stddef.h>
23#include "util.h"
24
25/* Doubly linked list head or element. */
847c7448 26struct list {
064af421
BP
27 struct list *prev; /* Previous list element. */
28 struct list *next; /* Next list element. */
847c7448 29};
064af421
BP
30
31#define LIST_INITIALIZER(LIST) { LIST, LIST }
32
33void list_init(struct list *);
b3907fbc 34void list_poison(struct list *);
064af421
BP
35
36/* List insertion. */
37void list_insert(struct list *, struct list *);
38void list_splice(struct list *before, struct list *first, struct list *last);
39void list_push_front(struct list *, struct list *);
40void list_push_back(struct list *, struct list *);
41void list_replace(struct list *, const struct list *);
42void list_moved(struct list *);
43
44/* List removal. */
45struct list *list_remove(struct list *);
46struct list *list_pop_front(struct list *);
47struct list *list_pop_back(struct list *);
48
49/* List elements. */
0574c613
BP
50struct list *list_front(const struct list *);
51struct list *list_back(const struct list *);
064af421
BP
52
53/* List properties. */
54size_t list_size(const struct list *);
55bool list_is_empty(const struct list *);
dc1539ae
BP
56bool list_is_singleton(const struct list *);
57bool list_is_short(const struct list *);
064af421 58
4e8e4213 59#define LIST_FOR_EACH(ITER, MEMBER, LIST) \
772ec52b 60 for (ASSIGN_CONTAINER(ITER, (LIST)->next, MEMBER); \
4e8e4213 61 &(ITER)->MEMBER != (LIST); \
772ec52b 62 ASSIGN_CONTAINER(ITER, (ITER)->MEMBER.next, MEMBER))
1f3c5efc
JR
63#define LIST_FOR_EACH_CONTINUE(ITER, MEMBER, LIST) \
64 for (ASSIGN_CONTAINER(ITER, (ITER)->MEMBER.next, MEMBER); \
65 &(ITER)->MEMBER != (LIST); \
66 ASSIGN_CONTAINER(ITER, (ITER)->MEMBER.next, MEMBER))
4e8e4213 67#define LIST_FOR_EACH_REVERSE(ITER, MEMBER, LIST) \
772ec52b 68 for (ASSIGN_CONTAINER(ITER, (LIST)->prev, MEMBER); \
4e8e4213 69 &(ITER)->MEMBER != (LIST); \
772ec52b 70 ASSIGN_CONTAINER(ITER, (ITER)->MEMBER.prev, MEMBER))
1f3c5efc
JR
71#define LIST_FOR_EACH_REVERSE_CONTINUE(ITER, MEMBER, LIST) \
72 for (ASSIGN_CONTAINER(ITER, (ITER)->MEMBER.prev, MEMBER); \
73 &(ITER)->MEMBER != (LIST); \
74 ASSIGN_CONTAINER(ITER, (ITER)->MEMBER.prev, MEMBER))
33e191a0
AW
75#define LIST_FOR_EACH_SAFE(ITER, NEXT, MEMBER, LIST) \
76 for (ASSIGN_CONTAINER(ITER, (LIST)->next, MEMBER); \
77 (&(ITER)->MEMBER != (LIST) \
78 ? ASSIGN_CONTAINER(NEXT, (ITER)->MEMBER.next, MEMBER), 1 \
79 : 0); \
772ec52b 80 (ITER) = (NEXT))
064af421
BP
81
82#endif /* list.h */