|
|
867c1e |
From cd24f3be4bcb388fd6b4ed48fc9a076ef0e1cee9 Mon Sep 17 00:00:00 2001
|
|
|
867c1e |
From: Gerd Hoffmann <kraxel@redhat.com>
|
|
|
867c1e |
Date: Wed, 2 Oct 2013 07:00:13 +0200
|
|
|
867c1e |
Subject: [PATCH 1/8] Introduce and convert pmm code to use standard list helpers.
|
|
|
867c1e |
|
|
|
867c1e |
RH-Author: Gerd Hoffmann <kraxel@redhat.com>
|
|
|
867c1e |
Message-id: <1380697219-1860-2-git-send-email-kraxel@redhat.com>
|
|
|
867c1e |
Patchwork-id: 54628
|
|
|
867c1e |
O-Subject: [RHEL-7 seabios PATCH 1/7] Introduce and convert pmm code to use standard list helpers.
|
|
|
867c1e |
Bugzilla: 947051
|
|
|
867c1e |
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
|
|
|
867c1e |
RH-Acked-by: Bandan Das <bsd@redhat.com>
|
|
|
867c1e |
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
867c1e |
|
|
|
867c1e |
From: Kevin O'Connor <kevin@koconnor.net>
|
|
|
867c1e |
|
|
|
867c1e |
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
|
|
|
867c1e |
(cherry picked from commit e097a75ef0de08ad6d8660c41efe10c1133f1865)
|
|
|
867c1e |
|
|
|
867c1e |
[ rhel6: skip ppm.c changes ]
|
|
|
867c1e |
|
|
|
867c1e |
Conflicts:
|
|
|
867c1e |
src/pmm.c
|
|
|
867c1e |
---
|
|
|
867c1e |
src/list.h | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
867c1e |
src/types.h | 3 +++
|
|
|
867c1e |
2 files changed, 79 insertions(+)
|
|
|
867c1e |
create mode 100644 src/list.h
|
|
|
867c1e |
|
|
|
867c1e |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
867c1e |
---
|
|
|
867c1e |
src/list.h | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
867c1e |
src/types.h | 3 ++
|
|
|
867c1e |
2 files changed, 79 insertions(+), 0 deletions(-)
|
|
|
867c1e |
create mode 100644 src/list.h
|
|
|
867c1e |
|
|
|
867c1e |
diff --git a/src/list.h b/src/list.h
|
|
|
867c1e |
new file mode 100644
|
|
|
867c1e |
index 0000000..db7e962
|
|
|
867c1e |
--- /dev/null
|
|
|
867c1e |
+++ b/src/list.h
|
|
|
867c1e |
@@ -0,0 +1,76 @@
|
|
|
867c1e |
+#ifndef __LIST_H
|
|
|
867c1e |
+#define __LIST_H
|
|
|
867c1e |
+
|
|
|
867c1e |
+#include "types.h" // container_of
|
|
|
867c1e |
+
|
|
|
867c1e |
+
|
|
|
867c1e |
+/****************************************************************
|
|
|
867c1e |
+ * hlist - Double linked lists with a single pointer list head
|
|
|
867c1e |
+ ****************************************************************/
|
|
|
867c1e |
+
|
|
|
867c1e |
+struct hlist_node {
|
|
|
867c1e |
+ struct hlist_node *next, **pprev;
|
|
|
867c1e |
+};
|
|
|
867c1e |
+
|
|
|
867c1e |
+struct hlist_head {
|
|
|
867c1e |
+ struct hlist_node *first;
|
|
|
867c1e |
+};
|
|
|
867c1e |
+
|
|
|
867c1e |
+static inline int
|
|
|
867c1e |
+hlist_empty(const struct hlist_head *h)
|
|
|
867c1e |
+{
|
|
|
867c1e |
+ return !h->first;
|
|
|
867c1e |
+}
|
|
|
867c1e |
+
|
|
|
867c1e |
+static inline void
|
|
|
867c1e |
+hlist_del(struct hlist_node *n)
|
|
|
867c1e |
+{
|
|
|
867c1e |
+ struct hlist_node *next = n->next;
|
|
|
867c1e |
+ struct hlist_node **pprev = n->pprev;
|
|
|
867c1e |
+ *pprev = next;
|
|
|
867c1e |
+ if (next)
|
|
|
867c1e |
+ next->pprev = pprev;
|
|
|
867c1e |
+}
|
|
|
867c1e |
+
|
|
|
867c1e |
+static inline void
|
|
|
867c1e |
+hlist_add(struct hlist_node *n, struct hlist_node **pprev)
|
|
|
867c1e |
+{
|
|
|
867c1e |
+ struct hlist_node *next = *pprev;
|
|
|
867c1e |
+ n->pprev = pprev;
|
|
|
867c1e |
+ n->next = next;
|
|
|
867c1e |
+ if (next)
|
|
|
867c1e |
+ next->pprev = &n->next;
|
|
|
867c1e |
+ *pprev = n;
|
|
|
867c1e |
+}
|
|
|
867c1e |
+
|
|
|
867c1e |
+static inline void
|
|
|
867c1e |
+hlist_add_head(struct hlist_node *n, struct hlist_head *h)
|
|
|
867c1e |
+{
|
|
|
867c1e |
+ hlist_add(n, &h->first);
|
|
|
867c1e |
+}
|
|
|
867c1e |
+
|
|
|
867c1e |
+static inline void
|
|
|
867c1e |
+hlist_add_before(struct hlist_node *n, struct hlist_node *next)
|
|
|
867c1e |
+{
|
|
|
867c1e |
+ hlist_add(n, next->pprev);
|
|
|
867c1e |
+}
|
|
|
867c1e |
+
|
|
|
867c1e |
+static inline void
|
|
|
867c1e |
+hlist_add_after(struct hlist_node *n, struct hlist_node *prev)
|
|
|
867c1e |
+{
|
|
|
867c1e |
+ hlist_add(n, &prev->next);
|
|
|
867c1e |
+}
|
|
|
867c1e |
+
|
|
|
867c1e |
+#define hlist_for_each_entry(pos, head, member) \
|
|
|
867c1e |
+ for (pos = container_of((head)->first, typeof(*pos), member) \
|
|
|
867c1e |
+ ; pos != container_of(NULL, typeof(*pos), member) \
|
|
|
867c1e |
+ ; pos = container_of(pos->member.next, typeof(*pos), member))
|
|
|
867c1e |
+
|
|
|
867c1e |
+#define hlist_for_each_entry_safe(pos, pprev, head, member) \
|
|
|
867c1e |
+ for (pprev = &(head)->first \
|
|
|
867c1e |
+ ; *pprev \
|
|
|
867c1e |
+ && ({ pos=container_of((*pprev)->next, typeof(*pos), member); 1; }) \
|
|
|
867c1e |
+ ; pprev = &(*pprev)->next)
|
|
|
867c1e |
+
|
|
|
867c1e |
+
|
|
|
867c1e |
+#endif // list.h
|
|
|
867c1e |
diff --git a/src/types.h b/src/types.h
|
|
|
867c1e |
index 24b078e..e5ab4bf 100644
|
|
|
867c1e |
--- a/src/types.h
|
|
|
867c1e |
+++ b/src/types.h
|
|
|
867c1e |
@@ -121,6 +121,9 @@ extern void __force_link_error__only_in_16bit(void) __noreturn;
|
|
|
867c1e |
#define container_of(ptr, type, member) ({ \
|
|
|
867c1e |
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
|
|
|
867c1e |
(type *)( (char *)__mptr - offsetof(type,member) );})
|
|
|
867c1e |
+#define container_of_or_null(ptr, type, member) ({ \
|
|
|
867c1e |
+ const typeof( ((type *)0)->member ) *___mptr = (ptr); \
|
|
|
867c1e |
+ ___mptr ? container_of(___mptr, type, member) : NULL; })
|
|
|
867c1e |
|
|
|
867c1e |
#define likely(x) __builtin_expect(!!(x), 1)
|
|
|
867c1e |
#define unlikely(x) __builtin_expect(!!(x), 0)
|
|
|
867c1e |
--
|
|
|
867c1e |
1.7.1
|
|
|
867c1e |
|