aboutsummaryrefslogtreecommitdiff
path: root/src/list.h
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2013-06-08 21:49:12 -0400
committerKevin O'Connor <kevin@koconnor.net>2013-06-08 21:49:12 -0400
commite097a75ef0de08ad6d8660c41efe10c1133f1865 (patch)
treef18d8a2e75e71279aadcdb22e1d411b68447d4ed /src/list.h
parentd0d82a31fe8b6248c3b610109320b401d944128c (diff)
downloadseabios-hppa-e097a75ef0de08ad6d8660c41efe10c1133f1865.zip
seabios-hppa-e097a75ef0de08ad6d8660c41efe10c1133f1865.tar.gz
seabios-hppa-e097a75ef0de08ad6d8660c41efe10c1133f1865.tar.bz2
Introduce and convert pmm code to use standard list helpers.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src/list.h')
-rw-r--r--src/list.h76
1 files changed, 76 insertions, 0 deletions
diff --git a/src/list.h b/src/list.h
new file mode 100644
index 0000000..db7e962
--- /dev/null
+++ b/src/list.h
@@ -0,0 +1,76 @@
+#ifndef __LIST_H
+#define __LIST_H
+
+#include "types.h" // container_of
+
+
+/****************************************************************
+ * hlist - Double linked lists with a single pointer list head
+ ****************************************************************/
+
+struct hlist_node {
+ struct hlist_node *next, **pprev;
+};
+
+struct hlist_head {
+ struct hlist_node *first;
+};
+
+static inline int
+hlist_empty(const struct hlist_head *h)
+{
+ return !h->first;
+}
+
+static inline void
+hlist_del(struct hlist_node *n)
+{
+ struct hlist_node *next = n->next;
+ struct hlist_node **pprev = n->pprev;
+ *pprev = next;
+ if (next)
+ next->pprev = pprev;
+}
+
+static inline void
+hlist_add(struct hlist_node *n, struct hlist_node **pprev)
+{
+ struct hlist_node *next = *pprev;
+ n->pprev = pprev;
+ n->next = next;
+ if (next)
+ next->pprev = &n->next;
+ *pprev = n;
+}
+
+static inline void
+hlist_add_head(struct hlist_node *n, struct hlist_head *h)
+{
+ hlist_add(n, &h->first);
+}
+
+static inline void
+hlist_add_before(struct hlist_node *n, struct hlist_node *next)
+{
+ hlist_add(n, next->pprev);
+}
+
+static inline void
+hlist_add_after(struct hlist_node *n, struct hlist_node *prev)
+{
+ hlist_add(n, &prev->next);
+}
+
+#define hlist_for_each_entry(pos, head, member) \
+ for (pos = container_of((head)->first, typeof(*pos), member) \
+ ; pos != container_of(NULL, typeof(*pos), member) \
+ ; pos = container_of(pos->member.next, typeof(*pos), member))
+
+#define hlist_for_each_entry_safe(pos, pprev, head, member) \
+ for (pprev = &(head)->first \
+ ; *pprev \
+ && ({ pos=container_of((*pprev)->next, typeof(*pos), member); 1; }) \
+ ; pprev = &(*pprev)->next)
+
+
+#endif // list.h