MythTV  master
dllist.h
Go to the documentation of this file.
1 #ifndef DLLIST_H
2 #define DLLIST_H
3 
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7 
8 struct dl_node
9 {
10  struct dl_node *next;
11  struct dl_node *prev;
12 };
13 
14 struct dl_head
15 {
16  struct dl_node *first;
17  struct dl_node *null;
18  struct dl_node *last;
19 };
20 
21 static inline struct dl_head *
22 dl_init(struct dl_head *h)
23 {
24  h->first = (struct dl_node *)&h->null;
25  h->null = nullptr;
26  h->last = (struct dl_node *)&h->first;
27  return h;
28 }
29 
30 static inline struct dl_node *
31 dl_remove(struct dl_node *n)
32 {
33  n->prev->next = n->next;
34  n->next->prev = n->prev;
35  return n;
36 }
37 
38 static inline struct dl_node *
39 dl_insert_after(struct dl_node *p, struct dl_node *n)
40 {
41  n->next = p->next;
42  n->prev = p;
43  p->next = n;
44  n->next->prev = n;
45  return n;
46 }
47 
48 #define dl_empty(h) ((h)->first->next == nullptr)
49 #define dl_insert_before(p, n) dl_insert_after((p)->prev, (n))
50 #define dl_insert_first(h, n) ({ struct dl_node *_n = (n); \
51  dl_insert_before((h)->first, _n); })
52 #define dl_insert_last(h, n) ({ struct dl_node *_n = (n); \
53  dl_insert_after((h)->last, _n); })
54 #define dl_remove_first(h) dl_remove((h)->first) // mustn't be empty!
55 #define dl_remove_last(h) dl_remove((h)->last) // mustn't be empty!
56 
57 #ifdef __cplusplus
58 }
59 #endif
60 
61 #endif /* DLLIST_H */
62 
dl_head::first
struct dl_node * first
Definition: dllist.h:16
dl_node::prev
struct dl_node * prev
Definition: dllist.h:11
dl_head
Definition: dllist.h:15
dl_remove
static struct dl_node * dl_remove(struct dl_node *n)
Definition: dllist.h:31
dl_node::next
struct dl_node * next
Definition: dllist.h:10
dl_head::last
struct dl_node * last
Definition: dllist.h:18
hardwareprofile.config.p
p
Definition: config.py:33
dl_node
Definition: dllist.h:9
dl_init
static struct dl_head * dl_init(struct dl_head *h)
Definition: dllist.h:22
dl_head::null
struct dl_node * null
Definition: dllist.h:17
dl_insert_after
static struct dl_node * dl_insert_after(struct dl_node *p, struct dl_node *n)
Definition: dllist.h:39