Module Name:    src
Committed By:   riastradh
Date:           Wed Jul 24 00:49:48 UTC 2013

Modified Files:
        src/sys/external/bsd/drm2/include/linux [riastradh-drm2]: list.h

Log Message:
Add initial draft of Linux list and hlist to <linux/list.h>.

Implemented in terms of TAILQ and LIST, respectively.
Not yet tested.


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.1 -r1.1.2.2 \
    src/sys/external/bsd/drm2/include/linux/list.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/external/bsd/drm2/include/linux/list.h
diff -u src/sys/external/bsd/drm2/include/linux/list.h:1.1.2.1 src/sys/external/bsd/drm2/include/linux/list.h:1.1.2.2
--- src/sys/external/bsd/drm2/include/linux/list.h:1.1.2.1	Wed Jul 24 00:33:12 2013
+++ src/sys/external/bsd/drm2/include/linux/list.h	Wed Jul 24 00:49:48 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: list.h,v 1.1.2.1 2013/07/24 00:33:12 riastradh Exp $	*/
+/*	$NetBSD: list.h,v 1.1.2.2 2013/07/24 00:49:48 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -32,4 +32,75 @@
 #ifndef _LINUX_LIST_H_
 #define _LINUX_LIST_H_
 
+#include <sys/null.h>
+#include <sys/queue.h>
+
+#include <linux/kernel.h>
+
+/*
+ * Doubly-linked lists.
+ */
+
+TAILQ_HEAD(list_head, list_node);
+struct list_node {
+	TAILQ_ENTRY(list_node) ln_entry;
+};
+
+static inline struct list_node *
+list_first(struct list_head *head)
+{
+	return TAILQ_FIRST(head);
+}
+
+static inline struct list_node *
+list_next(struct list_node *node)
+{
+	return TAILQ_NEXT(node, ln_entry);
+}
+
+#define	list_entry(PTR, TYPE, FIELD)	container_of(PTR, TYPE, FIELD)
+#define	list_for_each(VAR, HEAD)	TAILQ_FOREACH(VAR, HEAD, ln_entry)
+#define	list_for_each_safe(VAR, NEXT, HEAD)				\
+	TAILQ_FOREACH_SAFE(VAR, HEAD, ln_entry, NEXT)
+
+#define	list_for_each_entry(VAR, HEAD, FIELD)				\
+	for ((VAR) = ((TAILQ_FIRST((HEAD)) == NULL)? NULL :		\
+		    list_entry(TAILQ_FIRST((HEAD)), typeof(*(VAR)), FIELD)); \
+		(VAR) != NULL;						\
+		(VAR) = ((TAILQ_NEXT((VAR), FIELD) == NULL)? NULL :	\
+		    list_entry(TAILQ_NEXT((VAR), FIELD), typeof(*(VAR)), \
+			FIELD)))
+
+/*
+ * `H'ead-only/`H'ash-table doubly-linked lists.
+ */
+
+LIST_HEAD(hlist_head, hlist_node);
+struct hlist_node {
+	LIST_ENTRY(hlist_node) hln_entry;
+};
+
+static inline struct hlist_node *
+hlist_first(struct hlist_head *head)
+{
+	return LIST_FIRST(head);
+}
+
+static inline struct hlist_node *
+hlist_next(struct hlist_node *node)
+{
+	return LIST_NEXT(node, hln_entry);
+}
+
+#define	hlist_entry(PTR, TYPE, FIELD)	container_of(PTR, TYPE, FIELD)
+#define	hlist_for_each(VAR, HEAD)	LIST_FOREACH(VAR, HEAD, hln_entry)
+#define	hlist_for_each_safe(VAR, NEXT, HEAD)				\
+	LIST_FOREACH_SAFE(VAR, HEAD, hln_entry, NEXT)
+
+#define	hlist_for_each_entry(VAR, HLIST, HEAD, FIELD)			\
+	for ((HLIST) = LIST_FIRST((HEAD));				\
+		((HLIST) != NULL) &&					\
+		    ((VAR) = hlist_entry((HLIST), typeof(*(VAR)), FIELD), 1); \
+		(HLIST) = LIST_NEXT((HLIST), hln_entry))
+
 #endif  /* _LINUX_LIST_H_ */

Reply via email to