[PATCH][2.5] Single linked lists for Linux

From: Peter Chubb (peter@chubb.wattle.id.au)
Date: Wed Sep 25 2002 - 19:14:19 EST


+
+/**
+ * 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
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Mon Sep 30 2002 - 22:00:24 EST