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 #ifdef __cplusplus
26  h->null = nullptr;
27 #else
28  h->null = NULL;
29 #endif
30  h->last = (struct dl_node *)&h->first;
31  return h;
32 }
33 
34 static inline struct dl_node *
35 dl_remove(struct dl_node *n)
36 {
37  n->prev->next = n->next;
38  n->next->prev = n->prev;
39  return n;
40 }
41 
42 static inline struct dl_node *
43 dl_insert_after(struct dl_node *p, struct dl_node *n)
44 {
45  n->next = p->next;
46  n->prev = p;
47  p->next = n;
48  n->next->prev = n;
49  return n;
50 }
51 
52 #define dl_empty(h) ((h)->first->next == 0)
53 #define dl_insert_before(p, n) dl_insert_after((p)->prev, (n))
54 #define dl_insert_first(h, n) ({ struct dl_node *_n = (n); \
55  dl_insert_before((h)->first, _n); })
56 #define dl_insert_last(h, n) ({ struct dl_node *_n = (n); \
57  dl_insert_after((h)->last, _n); })
58 #define dl_remove_first(h) dl_remove((h)->first) // mustn't be empty!
59 #define dl_remove_last(h) dl_remove((h)->last) // mustn't be empty!
60 
61 #ifdef __cplusplus
62 }
63 #endif
64 
65 #endif /* DLLIST_H */
66 
#define NULL
Definition: H264Parser.h:62
struct dl_node * first
Definition: dllist.h:16
static struct dl_node * dl_remove(struct dl_node *n)
Definition: dllist.h:35
Definition: dllist.h:14
static struct dl_head * dl_init(struct dl_head *h)
Definition: dllist.h:22
struct dl_node * last
Definition: dllist.h:18
struct dl_node * prev
Definition: dllist.h:11
struct dl_node * null
Definition: dllist.h:17
Definition: dllist.h:8
struct dl_node * next
Definition: dllist.h:10
static struct dl_node * dl_insert_after(struct dl_node *p, struct dl_node *n)
Definition: dllist.h:43