Skip to contentSkip to conversation

[2.5] Single linked lists for Linux

PATCH In review Peter Chubb 4 participants 4 messages Sep 26, 2002 1 message not in the archive

lore
Share & tools
lore
#1 lore raw

PATCH 1/1 [2.5] Single linked lists for Linux

In reply to a message not in the archive

+
+/**
+ * slist_del - remove an entry from list
+ * @head: head to remove it from
+ * @entry: entry to be removed
+ */
+#define slist_del(_head, _entry) \
+do { \
+ (_head)->next = (_entry)->next; \
+ (_entry)->next = NULL; \
+}
+

This only works if head->next == entry otherwise you lose half your list. Also, none of this is SMP-safe.

I think you need something like this (but with locking!)

/*
* remove entry from list starting at head
* Return 0 if successful, non-zero otherwise.
*/
static inline int slist_del(struct slist *head, struct slist *entry)

{
	struct slist **p;
	for (p = &head->next; *p; p = &(*p)->next)
	    if (*p == entry) {
	       *p = entry->next;
	       entry->next = NULL;
	       return 0;
        }
        return -1;
}

Peter C

#2 lore raw
Quoted 4 lines · Peter Chubb

This only works if head->next == entry otherwise you lose half your list. Also, none of this is SMP-safe.

I think you need something like this (but with locking!)

Should you really be having locking in a primitive like that? That shouldn't be taken care of at that level.

Zwane

Signature · 1 line
function.linuxpower.ca
#3 lore raw
In reply to Peter Chubb
Quoted 4 lines · Peter Chubb

+#define slist_del(_head, _entry) \

This only works if head->next == entry otherwise you lose half your list. Also, none of this is SMP-safe.

Oh boy, this is the material bad jokes are made from ...

Q: How many lightweight patch managers does it take to do a
singly linked list list_del ?
A: 4, two to hold down the list head, one to chop off the tail
and another one to sweep the lost entries under the carpet.

Sorry, but I couldn't resist this one ;)

cheers,

Rik

Signature · 5 lines
Bravely reimplemented by the knights who say "NIH".

http://www.surriel.com/		http://distro.conectiva.com/

Spamtraps of the month:  [email protected] [email protected]
#4 lore raw
In reply to Peter Chubb

Hi,

Review

Quoted 10 lines · Peter Chubb
(quoted diff) +10 -0
+/**
+ * slist_del -	remove an entry from list
+ * @head:	head to remove it from
+ * @entry:	entry to be removed
+ */
+#define slist_del(_head, _entry)		\
+do {						\
+	(_head)->next = (_entry)->next;		\
+	(_entry)->next = NULL;			\
+}

What about

#define slist_del(_head) \

do {						\
	typeof(_head) _entry = (_head)->next;	\
	(_head)->next = _entry->next;		\
	_entry->next = NULL;			\
} while (0)
Quoted 1 line

static inline int slist_del(struct slist *head, struct slist *entry)

I don't want to inline (just like once, with list.h) because I want any type to match here...

Thunder

Signature · 1 line
assert(typeof((fool)->next) == typeof(fool));	/* wrong */