lkml.org 
[lkml]   [2002]   [Aug]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: Generic list push/pop
On Sun, Aug 18, 2002 at 09:21:41PM +0200, Daniel Phillips wrote:
> I took a run at writing generic single-linked list push and pop macros, to be
> used in the form:

Dear gawd, I've gone blind.

How's this look?


Cheers,
Bill


struct slist
{
struct slist *next;
};


static inline void slist_add(struct slist *head, struct slist *elem)
{
elem->next = head->next;
head->next = elem;
}

#define slist_push(head, elem) slist_add(head, elem)

static inline struct slist *slist_pop(struct slist *head)
{
struct slist *elem = head->next;

if (elem) {
head->next = elem->next;
elem->next = NULL;
}
return elem;
}

static inline int slist_remove(struct slist *head, struct slist *elem)
{
struct slist *curr, *prev;

for (prev = head, curr = head->next; curr; prev = curr, curr = curr->next)
if (curr == head) {
prev->next = curr->next;
curr->next = NULL;
return 1;
}

return 0;
}
-
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/

\
 
 \ /
  Last update: 2005-03-22 13:28    [W:0.125 / U:2.672 seconds]
©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site