~ubuntu-branches/ubuntu/saucy/seabios/saucy-proposed

« back to all changes in this revision

Viewing changes to src/list.h

  • Committer: Package Import Robot
  • Author(s): Michael Tokarev
  • Date: 2013-07-08 21:34:44 UTC
  • mfrom: (1.1.7)
  • Revision ID: package-import@ubuntu.com-20130708213444-6ed9q23j39x143lu
Tags: 1.7.3-1
Multi-Arch: allowed

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef __LIST_H
 
2
#define __LIST_H
 
3
 
 
4
#include "types.h" // container_of
 
5
 
 
6
 
 
7
/****************************************************************
 
8
 * hlist - Double linked lists with a single pointer list head
 
9
 ****************************************************************/
 
10
 
 
11
struct hlist_node {
 
12
    struct hlist_node *next, **pprev;
 
13
};
 
14
 
 
15
struct hlist_head {
 
16
    struct hlist_node *first;
 
17
};
 
18
 
 
19
static inline int
 
20
hlist_empty(const struct hlist_head *h)
 
21
{
 
22
    return !h->first;
 
23
}
 
24
 
 
25
static inline void
 
26
hlist_del(struct hlist_node *n)
 
27
{
 
28
    struct hlist_node *next = n->next;
 
29
    struct hlist_node **pprev = n->pprev;
 
30
    *pprev = next;
 
31
    if (next)
 
32
        next->pprev = pprev;
 
33
}
 
34
 
 
35
static inline void
 
36
hlist_add(struct hlist_node *n, struct hlist_node **pprev)
 
37
{
 
38
    struct hlist_node *next = *pprev;
 
39
    n->pprev = pprev;
 
40
    n->next = next;
 
41
    if (next)
 
42
        next->pprev = &n->next;
 
43
    *pprev = n;
 
44
}
 
45
 
 
46
static inline void
 
47
hlist_add_head(struct hlist_node *n, struct hlist_head *h)
 
48
{
 
49
    hlist_add(n, &h->first);
 
50
}
 
51
 
 
52
static inline void
 
53
hlist_add_before(struct hlist_node *n, struct hlist_node *next)
 
54
{
 
55
    hlist_add(n, next->pprev);
 
56
}
 
57
 
 
58
static inline void
 
59
hlist_add_after(struct hlist_node *n, struct hlist_node *prev)
 
60
{
 
61
    hlist_add(n, &prev->next);
 
62
}
 
63
 
 
64
#define hlist_for_each_entry(pos, head, member)                         \
 
65
    for (pos = container_of((head)->first, typeof(*pos), member)        \
 
66
         ; pos != container_of(NULL, typeof(*pos), member)              \
 
67
         ; pos = container_of(pos->member.next, typeof(*pos), member))
 
68
 
 
69
#define hlist_for_each_entry_safe(pos, n, head, member)                 \
 
70
    for (pos = container_of((head)->first, typeof(*pos), member)        \
 
71
         ; pos != container_of(NULL, typeof(*pos), member)              \
 
72
             && ({ n = pos->member.next; 1; })                          \
 
73
         ; pos = container_of(n, typeof(*pos), member))
 
74
 
 
75
#define hlist_for_each_entry_pprev(pos, pprev, head, member)            \
 
76
    for (pprev = &(head)->first                                         \
 
77
         ; *pprev && ({ pos=container_of(*pprev, typeof(*pos), member); 1; }) \
 
78
         ; pprev = &(*pprev)->next)
 
79
 
 
80
 
 
81
#endif // list.h