2002-09-26 00:12:16

by Peter Chubb

[permalink] [raw]
Subject: [PATCH][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


2002-09-26 00:21:08

by Zwane Mwaikambo

[permalink] [raw]
Subject: Re: [PATCH][2.5] Single linked lists for Linux

On Thu, 26 Sep 2002, Peter Chubb wrote:

> 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
--
function.linuxpower.ca

2002-09-26 00:30:41

by Rik van Riel

[permalink] [raw]
Subject: Re: [PATCH][2.5] Single linked lists for Linux

On Thu, 26 Sep 2002, Peter Chubb wrote:

> +#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
--
Bravely reimplemented by the knights who say "NIH".

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

Spamtraps of the month: [email protected] [email protected]


2002-09-26 06:36:26

by Thunder from the hill

[permalink] [raw]
Subject: Re: [PATCH][2.5] Single linked lists for Linux

Hi,

On Thu, 26 Sep 2002, Peter Chubb wrote:
> +/**
> + * 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)

> 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
--
assert(typeof((fool)->next) == typeof(fool)); /* wrong */