]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - include/hlist.h
xfs: fix off-by-one error in xfs_rtalloc_query_range
[thirdparty/xfsprogs-dev.git] / include / hlist.h
CommitLineData
c40bdaa2
DC
1/*
2 * double-linked hash list with single head implementation taken from linux
3 * kernel headers as of 2.6.38-rc1.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18#ifndef __HLIST_H__
19#define __HLIST_H__
20
21struct hlist_node {
22 struct hlist_node *next;
23 struct hlist_node **pprev;
24};
25struct hlist_head {
26 struct hlist_node *first;
27};
28
29#define HLIST_HEAD_INIT { .first = NULL }
30static inline void INIT_HLIST_NODE(struct hlist_node *h)
31{
32 h->next = NULL;
33 h->pprev = NULL;
34}
35
36static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
37{
38 struct hlist_node *first = h->first;
39 n->next = first;
40 if (first)
41 first->pprev = &n->next;
42 h->first = n;
43 n->pprev = &h->first;
44}
45
46static inline void __hlist_del(struct hlist_node *n)
47{
48 struct hlist_node *next = n->next;
49 struct hlist_node **pprev = n->pprev;
50 *pprev = next;
51 if (next)
52 next->pprev = pprev;
53}
54
55static inline void hlist_del(struct hlist_node *n)
56{
57 __hlist_del(n);
58}
59
60#define hlist_entry(ptr, type, member) ({ \
61 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
62 (type *)( (char *)__mptr - offsetof(type,member) );})
63
64
65#define hlist_for_each(pos, head) \
66 for (pos = (head)->first; pos; pos = pos->next)
67
68#define hlist_for_each_entry(tpos, pos, head, member) \
69 for (pos = (head)->first; \
70 pos && ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
71 pos = pos->next)
72
73
74#endif /* __LIST_H__ */