[Intel-gfx] [RFC i-g-t v2 3/5] igt_aux: Add some list helpers from wayland
Lyude
lyude at redhat.com
Mon Nov 21 18:43:36 UTC 2016
Since we're going to be using lists for keeping track of EDIDs we've
allocated on the chamelium, add some generic list helpers from the
wayland project.
Signed-off-by: Lyude <lyude at redhat.com>
Changes since v1:
- Rename list helpers to be more like those from the Linux kernel
---
lib/igt_aux.c | 27 +++++++++++++++++++++++++++
lib/igt_aux.h | 38 ++++++++++++++++++++++++++++++++++++++
2 files changed, 65 insertions(+)
diff --git a/lib/igt_aux.c b/lib/igt_aux.c
index 67432c6..6e44218 100644
--- a/lib/igt_aux.c
+++ b/lib/igt_aux.c
@@ -1343,3 +1343,30 @@ double igt_stop_siglatency(struct igt_mean *result)
return mean;
}
+
+void igt_list_init(struct igt_list *igt_list)
+{
+ igt_list->prev = igt_list;
+ igt_list->next = igt_list;
+}
+
+void igt_list_add(struct igt_list *igt_list, struct igt_list *elm)
+{
+ elm->prev = igt_list;
+ elm->next = igt_list->next;
+ igt_list->next = elm;
+ elm->next->prev = elm;
+}
+
+void igt_list_del(struct igt_list *elm)
+{
+ elm->prev->next = elm->next;
+ elm->next->prev = elm->prev;
+ elm->next = NULL;
+ elm->prev = NULL;
+}
+
+bool igt_list_empty(const struct igt_list *igt_list)
+{
+ return igt_list->next == igt_list;
+}
diff --git a/lib/igt_aux.h b/lib/igt_aux.h
index 7cee901..c021e3a 100644
--- a/lib/igt_aux.h
+++ b/lib/igt_aux.h
@@ -267,4 +267,42 @@ double igt_stop_siglatency(struct igt_mean *result);
void igt_set_module_param(const char *name, const char *val);
void igt_set_module_param_int(const char *name, int val);
+/*
+ * This list data structure is a verbatim copy from wayland-util.h from the
+ * Wayland project; except that wl_ prefix has been removed.
+ */
+
+struct igt_list {
+ struct igt_list *prev;
+ struct igt_list *next;
+};
+
+void igt_list_init(struct igt_list *list);
+void igt_list_add(struct igt_list *list, struct igt_list *elm);
+void igt_list_del(struct igt_list *elm);
+bool igt_list_empty(const struct igt_list *list);
+
+#ifdef __GNUC__
+#define container_of(ptr, sample, member) \
+ (__typeof__(sample))((char *)(ptr) - \
+ ((char *)&(sample)->member - (char *)(sample)))
+#else
+#define container_of(ptr, sample, member) \
+ (void *)((char *)(ptr) - \
+ ((char *)&(sample)->member - (char *)(sample)))
+#endif
+
+#define igt_list_for_each(pos, head, member) \
+ for (pos = 0, pos = container_of((head)->next, pos, member); \
+ &pos->member != (head); \
+ pos = container_of(pos->member.next, pos, member))
+
+#define igt_list_for_each_safe(pos, tmp, head, member) \
+ for (pos = 0, tmp = 0, \
+ pos = container_of((head)->next, pos, member), \
+ tmp = container_of((pos)->member.next, tmp, member); \
+ &pos->member != (head); \
+ pos = tmp, \
+ tmp = container_of(pos->member.next, tmp, member))
+
#endif /* IGT_AUX_H */
--
2.7.4
More information about the Intel-gfx
mailing list