intel-gfx.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Lyude <lyude@redhat.com>
To: intel-gfx@lists.freedesktop.org
Subject: [RFC i-g-t v2 3/5] igt_aux: Add some list helpers from wayland
Date: Mon, 21 Nov 2016 13:43:36 -0500	[thread overview]
Message-ID: <1479753818-363-4-git-send-email-lyude@redhat.com> (raw)
In-Reply-To: <1479753818-363-1-git-send-email-lyude@redhat.com>

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@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

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  parent reply	other threads:[~2016-11-21 18:43 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-21 18:43 [RFC i-g-t v2 0/5] intel-gpu-tools: Add support for the Chamelium Lyude
2016-11-21 18:43 ` [RFC i-g-t v2 1/5] igt_aux: Add igt_skip_without_suspend_support() Lyude
2016-11-21 18:43 ` [RFC i-g-t v2 2/5] igt_aux: Add igt_set_autoresume_delay() Lyude
2016-11-21 18:43 ` Lyude [this message]
2016-11-21 18:43 ` [RFC i-g-t v2 4/5] igt_kms: Add helpers for watching for sysfs hotplug events Lyude
2016-11-21 18:43 ` [RFC i-g-t v2 5/5] Add support for hotplug testing with the Chamelium Lyude

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1479753818-363-4-git-send-email-lyude@redhat.com \
    --to=lyude@redhat.com \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).