[RFC] list: add singly-linked list and singly-linked tail list

Previous thread: Re: [ANNOUNCE] linux-2.6.32.y-drm33.z by Luis R. Rodriguez on Thursday, April 29, 2010 - 10:12 am. (1 message)

Next thread: pull request: wireless-2.6 2010-04-30 by John W. Linville on Friday, April 30, 2010 - 11:08 am. (2 messages)
From: Changli Gao
Date: Thursday, April 29, 2010 - 10:36 pm

add singly-linked list and singly-linked tail list.

these two lists are also used widely in the kernel as doubly-linked list, so I
am trying to add some APIs for these two lists to eliminate the duplicate code.

Signed-off-by: Changli Gao <xiaosuo@gmail.com>
----
 include/linux/list.h |  186 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 186 insertions(+)
diff --git a/include/linux/list.h b/include/linux/list.h
index 8392884..048a579 100644
--- a/include/linux/list.h
+++ b/include/linux/list.h
@@ -706,4 +706,190 @@ static inline void hlist_move_list(struct hlist_head *old,
 		({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
 	     pos = n)
 
+/* singly-linked list */
+
+struct slist_head {
+	struct slist_head *next;
+};
+
+#define slist_entry(ptr, type, member) \
+	container_of(ptr, type, member)
+
+#define SLIST_HEAD_INIT { .next = NULL }
+#define SLIST_HEAD(name) struct slist_head name = SLIST_HEAD_INIT
+
+static inline void INIT_SLIST_HEAD(struct slist_head *h)
+{
+	h->next = NULL;
+}
+
+static inline bool slist_empty(struct slist_head *h)
+{
+	return h->next == NULL;
+}
+
+static inline void slist_push(struct slist_head *n, struct slist_head *h)
+{
+	n->next = h->next;
+	h->next = n;
+}
+
+static inline struct slist_head *slist_pop(struct slist_head *h)
+{
+	struct slist_head *n;
+
+	n = h->next;
+	if (n)
+		h->next = n->next;
+
+	return n;
+}
+
+static inline struct slist_head *slist_pop_init(struct slist_head *h)
+{
+	struct slist_head *n = slist_pop(h);
+
+	if (n)
+		INIT_SLIST_HEAD(n);
+
+	return n;
+}
+
+static inline void __slist_splice(struct slist_head *first,
+				  struct slist_head *to)
+{
+	struct slist_head **ptail;
+
+	for (ptail = &to->next; *ptail; ptail = &(*ptail)->next)
+		;
+	*ptail = first;
+}
+
+static inline void slist_splice_init(struct slist_head *from,
+				     struct slist_head *to)
+{
+
+	if (from->next != NULL) {
+		__slist_splice(from->next, ...
Previous thread: Re: [ANNOUNCE] linux-2.6.32.y-drm33.z by Luis R. Rodriguez on Thursday, April 29, 2010 - 10:12 am. (1 message)

Next thread: pull request: wireless-2.6 2010-04-30 by John W. Linville on Friday, April 30, 2010 - 11:08 am. (2 messages)