]> git.proxmox.com Git - mirror_lxc.git/blame - src/lxc/list.h
ovl_rsync: make sure to umount
[mirror_lxc.git] / src / lxc / list.h
CommitLineData
250b1eec
SG
1/*
2 * lxc: linux Container library
3 *
4 * (C) Copyright IBM Corp. 2007, 2008
5 *
6 * Authors:
7 * Daniel Lezcano <daniel.lezcano at free.fr>
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
f1a4a029
ÇO
24#ifndef __LXC_LIST_H
25#define __LXC_LIST_H
0ad19a3f 26
951cc719 27struct lxc_list {
0ad19a3f 28 void *elem;
951cc719
DL
29 struct lxc_list *next;
30 struct lxc_list *prev;
0ad19a3f 31};
32
951cc719 33#define lxc_init_list(l) { .next = l, .prev = l }
0ad19a3f 34
951cc719 35#define lxc_list_for_each(__iterator, __list) \
0ad19a3f 36 for (__iterator = (__list)->next; \
37 __iterator != __list; \
38 __iterator = __iterator->next)
39
9ebb03ad
DE
40#define lxc_list_for_each_safe(__iterator, __list, __next) \
41 for (__iterator = (__list)->next, __next = __iterator->next; \
42 __iterator != __list; \
43 __iterator = __next, __next = __next->next)
44
951cc719 45static inline void lxc_list_init(struct lxc_list *list)
0ad19a3f 46{
47 list->elem = NULL;
48 list->next = list->prev = list;
49}
50
951cc719 51static inline void lxc_list_add_elem(struct lxc_list *list, void *elem)
0ad19a3f 52{
53 list->elem = elem;
54}
55
951cc719 56static inline void *lxc_list_first_elem(struct lxc_list *list)
0ad19a3f 57{
58 return list->next->elem;
59}
60
bac89583
DL
61static inline void *lxc_list_last_elem(struct lxc_list *list)
62{
63 return list->prev->elem;
64}
65
951cc719 66static inline int lxc_list_empty(struct lxc_list *list)
0ad19a3f 67{
68 return list == list->next;
69}
70
951cc719
DL
71static inline void __lxc_list_add(struct lxc_list *new,
72 struct lxc_list *prev,
73 struct lxc_list *next)
0ad19a3f 74{
951cc719
DL
75 next->prev = new;
76 new->next = next;
77 new->prev = prev;
78 prev->next = new;
0ad19a3f 79}
80
951cc719 81static inline void lxc_list_add(struct lxc_list *head, struct lxc_list *list)
0ad19a3f 82{
951cc719
DL
83 __lxc_list_add(list, head, head->next);
84}
85
86static inline void lxc_list_add_tail(struct lxc_list *head,
87 struct lxc_list *list)
88{
89 __lxc_list_add(list, head->prev, head);
90}
91
92static inline void lxc_list_del(struct lxc_list *list)
93{
94 struct lxc_list *next, *prev;
0ad19a3f 95
96 next = list->next;
97 prev = list->prev;
98 next->prev = prev;
99 prev->next = next;
100}
101
9fc7f8c0
TA
102static inline int lxc_list_len(struct lxc_list *list)
103{
104 int i = 0;
105 struct lxc_list *iter;
106 lxc_list_for_each(iter, list) {
107 i++;
108 }
109
110 return i;
111}
112
0ad19a3f 113#endif