aboutsummaryrefslogtreecommitdiffstats
path: root/util/alevt/dllist.h
diff options
context:
space:
mode:
authoretobi <git@e-tobi.net>2013-09-03 09:48:45 +0200
committeretobi <git@e-tobi.net>2013-09-03 09:48:45 +0200
commit9fe4d4ea9c054e539ab679ed2e9c076c35beb69d (patch)
treeaffff927f15c8ae6c77890cc9564855efe2e51db /util/alevt/dllist.h
parent9a5228e0f2b898367b7943d294be58caf6ce8bb3 (diff)
downloadlinux-dvb-apps-upstream/1.1.1+rev1355.tar.gz
Imported Upstream version 1.1.1+rev1355upstream/1.1.1+rev1355
Diffstat (limited to 'util/alevt/dllist.h')
-rw-r--r--util/alevt/dllist.h55
1 files changed, 55 insertions, 0 deletions
diff --git a/util/alevt/dllist.h b/util/alevt/dllist.h
new file mode 100644
index 0000000..f925506
--- /dev/null
+++ b/util/alevt/dllist.h
@@ -0,0 +1,55 @@
+#ifndef DLLIST_H
+#define DLLIST_H
+
+
+struct dl_node
+{
+ struct dl_node *next;
+ struct dl_node *prev;
+};
+
+
+struct dl_head
+{
+ struct dl_node *first;
+ struct dl_node *null;
+ struct dl_node *last;
+};
+
+
+static inline struct dl_head * dl_init(struct dl_head *h)
+{
+ h->first = (struct dl_node *)&h->null;
+ h->null = 0;
+ h->last = (struct dl_node *)&h->first;
+ return h;
+}
+
+
+static inline struct dl_node * dl_remove(struct dl_node *n)
+{
+ n->prev->next = n->next;
+ n->next->prev = n->prev;
+ return n;
+}
+
+
+static inline struct dl_node *
+ dl_insert_after(struct dl_node *p, struct dl_node *n)
+{
+ n->next = p->next;
+ n->prev = p;
+ p->next = n;
+ n->next->prev = n;
+ return n;
+}
+
+#define dl_empty(h) ((h)->first->next == 0)
+#define dl_insert_before(p, n) dl_insert_after((p)->prev, (n))
+#define dl_insert_first(h, n) ({ struct dl_node *_n = (n); \
+ dl_insert_before((h)->first, _n); })
+#define dl_insert_last(h, n) ({ struct dl_node *_n = (n); \
+ dl_insert_after((h)->last, _n); })
+#define dl_remove_first(h) dl_remove((h)->first) // mustn't be empty!
+#define dl_remove_last(h) dl_remove((h)->last) // mustn't be empty!
+#endif