[2.5] Single linked lists for Linux
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/1 [2.5] Single linked lists for Linux
+
+/**
+ * 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
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
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]
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 */