Blame as10k1/list.h

Packit 427e91
/* From linux kernel source */
Packit 427e91
Packit 427e91
Packit 427e91
#ifndef _LINUX_LIST_H
Packit 427e91
#define _LINUX_LIST_H
Packit 427e91
Packit 427e91
/*
Packit 427e91
 * Simple doubly linked list implementation.
Packit 427e91
 *
Packit 427e91
 * Some of the internal functions ("__xxx") are useful when
Packit 427e91
 * manipulating whole lists rather than single entries, as
Packit 427e91
 * sometimes we already know the next/prev entries and we can
Packit 427e91
 * generate better code by using them directly rather than
Packit 427e91
 * using the generic single-entry routines.
Packit 427e91
 */
Packit 427e91
Packit 427e91
struct list_head {
Packit 427e91
	struct list_head *next, *prev;
Packit 427e91
};
Packit 427e91
Packit 427e91
#define LIST_HEAD(name) \
Packit 427e91
	struct list_head name = { &name, &name }
Packit 427e91
Packit 427e91
#define INIT_LIST_HEAD(ptr) do { \
Packit 427e91
	(ptr)->next = (ptr); (ptr)->prev = (ptr); \
Packit 427e91
} while (0)
Packit 427e91
Packit 427e91
/*
Packit 427e91
 * Insert a new entry between two known consecutive entries. 
Packit 427e91
 *
Packit 427e91
 * This is only for internal list manipulation where we know
Packit 427e91
 * the prev/next entries already!
Packit 427e91
 */
Packit 427e91
static __inline__ void __list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
Packit 427e91
{
Packit 427e91
	next->prev = new;
Packit 427e91
	new->next = next;
Packit 427e91
	new->prev = prev;
Packit 427e91
	prev->next = new;
Packit 427e91
}
Packit 427e91
Packit 427e91
/*
Packit 427e91
 * Insert a new entry after the specified head..
Packit 427e91
 */
Packit 427e91
static __inline__ void list_add(struct list_head *new, struct list_head *head)
Packit 427e91
{
Packit 427e91
	__list_add(new, head, head->next);
Packit 427e91
}
Packit 427e91
Packit 427e91
/*
Packit 427e91
 * Insert a new entry before the specified head..
Packit 427e91
 */
Packit 427e91
static __inline__ void list_add_tail(struct list_head *new, struct list_head *head)
Packit 427e91
{
Packit 427e91
	__list_add(new, head->prev, head);
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
/*
Packit 427e91
 * Delete a list entry by making the prev/next entries
Packit 427e91
 * point to each other.
Packit 427e91
 *
Packit 427e91
 * This is only for internal list manipulation where we know
Packit 427e91
 * the prev/next entries already!
Packit 427e91
 */
Packit 427e91
static __inline__ void __list_del(struct list_head *prev, struct list_head *next)
Packit 427e91
{
Packit 427e91
	next->prev = prev;
Packit 427e91
	prev->next = next;
Packit 427e91
}
Packit 427e91
Packit 427e91
static __inline__ void list_del(struct list_head *entry)
Packit 427e91
{
Packit 427e91
	__list_del(entry->prev, entry->next);
Packit 427e91
}
Packit 427e91
Packit 427e91
static __inline__ int list_empty(struct list_head *head)
Packit 427e91
{
Packit 427e91
	return head->next == head;
Packit 427e91
}
Packit 427e91
Packit 427e91
#define list_entry(ptr, type, member) \
Packit 427e91
	((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
Packit 427e91
Packit 427e91
#define list_for_each(pos, head) \
Packit 427e91
        for (pos = (head)->next; pos != (head); pos = pos->next)
Packit 427e91
Packit 427e91
#endif