Skip to contentSkip to conversation

add list_del_head function

PATCH In review Tobias DiPasquale 2 participants 3 messages Nov 20, 2004 – Nov 22, 2004

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 add list_del_head function

Hi all,

I was working with some queues the other day and I noticed that there was a list_add_tail() function in list.h, but no list_del_head() function. This struck me as a little odd, so I went ahead and implemented one in order to complete full queue functionality. The patch below was generated against pristine 2.6.9 kernel.org kernel sources and is attached to this email.

Please CC me on any replies, as I'm not subscribed to LKML. Thanks :)

Name: Add list_del_head for full queue functionality
Status: Tested

Signature · 2 lines
[ Tobias DiPasquale ]
0x636f6465736c696e67657240676d61696c2e636f6d
include/linux/list.h +15 -0
diff -Nrup linux-2.6.9/include/linux/list.h linux/include/linux/list.h
@@ -166,6 +166,21 @@ static inline void list_del(struct list_
 }
 
 /**
+ * list_del_head - deletes first entry from list.
+ * @entry: return parameter; will contain former head of list on return.
+ * @head: head of list from which to delete.
+ *
+ * This function is useful for implementing queues. Caller must ensure
+ * the list is not empty before calling this function. On return, entry
+ * will point to the former head of the list.
+ */
+static inline void list_del_head(struct list_head **entry, struct list_head *head)
+{
+	*entry = head->next;
+	list_del(head->next);
+}
+
+/**
  * list_del_rcu - deletes entry from list without re-initialization
  * @entry: the element to delete from the list.
  *
#1 lore raw
Quoted 8 lines · Tobias DiPasquale

Hi all,

I was working with some queues the other day and I noticed that there was a list_add_tail() function in list.h, but no list_del_head() function. This struck me as a little odd, so I went ahead and implemented one in order to complete full queue functionality. The patch below was generated against pristine 2.6.9 kernel.org kernel sources and is attached to this email.

Generally patches like this have little merrit unless accompanied by another patch converting several obvious pieces of kernel code to use it.

Also I find the interface awkward and different from the other list functions.

	entry = list_del_head(list);

would have been much nicer.

Signature · 1 line
Jens Axboe
#2 lore raw
Quoted 10 lines · Jens Axboe

Generally patches like this have little merrit unless accompanied by another patch converting several obvious pieces of kernel code to use it.

Also I find the interface awkward and different from the other list functions.

        entry = list_del_head(list);

would have been much nicer.

Ok I'll do both things and resubmit. Thanks for getting back to me :)

Signature · 2 lines
[ Tobias DiPasquale ]
0x636f6465736c696e67657240676d61696c2e636f6d