Blame maemo/list.h

Packit 675970
#ifndef __LIST_H
Packit 675970
#define __LIST_H
Packit 675970
Packit 675970
/* This file is from Linux Kernel (include/linux/list.h) 
Packit 675970
 * and modified by simply removing hardware prefetching of list items. 
Packit 675970
 * Here by copyright, credits attributed to wherever they belong.
Packit 675970
 * Kulesh Shanmugasundaram (kulesh [squiggly] isis.poly.edu)
Packit 675970
 */
Packit 675970
Packit 675970
/*
Packit 675970
 * Simple doubly linked list implementation.
Packit 675970
 *
Packit 675970
 * Some of the internal functions ("__xxx") are useful when
Packit 675970
 * manipulating whole lists rather than single entries, as
Packit 675970
 * sometimes we already know the next/prev entries and we can
Packit 675970
 * generate better code by using them directly rather than
Packit 675970
 * using the generic single-entry routines.
Packit 675970
 */
Packit 675970
Packit 675970
struct list_head {
Packit 675970
	struct list_head *next, *prev;
Packit 675970
};
Packit 675970
Packit 675970
#define LIST_HEAD_INIT(name) { &(name), &(name) }
Packit 675970
Packit 675970
#define LIST_HEAD(name) \
Packit 675970
	struct list_head name = LIST_HEAD_INIT(name)
Packit 675970
Packit 675970
#define INIT_LIST_HEAD(ptr) do { \
Packit 675970
	(ptr)->next = (ptr); (ptr)->prev = (ptr); \
Packit 675970
} while (0)
Packit 675970
Packit 675970
/*
Packit 675970
 * Insert a new entry between two known consecutive entries. 
Packit 675970
 *
Packit 675970
 * This is only for internal list manipulation where we know
Packit 675970
 * the prev/next entries already!
Packit 675970
 */
Packit 675970
static inline void __list_add(struct list_head *new,
Packit 675970
			      struct list_head *prev,
Packit 675970
			      struct list_head *next)
Packit 675970
{
Packit 675970
	next->prev = new;
Packit 675970
	new->next = next;
Packit 675970
	new->prev = prev;
Packit 675970
	prev->next = new;
Packit 675970
}
Packit 675970
Packit 675970
/**
Packit 675970
 * list_add - add a new entry
Packit 675970
 * @new: new entry to be added
Packit 675970
 * @head: list head to add it after
Packit 675970
 *
Packit 675970
 * Insert a new entry after the specified head.
Packit 675970
 * This is good for implementing stacks.
Packit 675970
 */
Packit 675970
static inline void list_add(struct list_head *new, struct list_head *head)
Packit 675970
{
Packit 675970
	__list_add(new, head, head->next);
Packit 675970
}
Packit 675970
Packit 675970
/**
Packit 675970
 * list_add_tail - add a new entry
Packit 675970
 * @new: new entry to be added
Packit 675970
 * @head: list head to add it before
Packit 675970
 *
Packit 675970
 * Insert a new entry before the specified head.
Packit 675970
 * This is useful for implementing queues.
Packit 675970
 */
Packit 675970
static inline void list_add_tail(struct list_head *new, struct list_head *head)
Packit 675970
{
Packit 675970
	__list_add(new, head->prev, head);
Packit 675970
}
Packit 675970
Packit 675970
/*
Packit 675970
 * Delete a list entry by making the prev/next entries
Packit 675970
 * point to each other.
Packit 675970
 *
Packit 675970
 * This is only for internal list manipulation where we know
Packit 675970
 * the prev/next entries already!
Packit 675970
 */
Packit 675970
static inline void __list_del(struct list_head *prev, struct list_head *next)
Packit 675970
{
Packit 675970
	next->prev = prev;
Packit 675970
	prev->next = next;
Packit 675970
}
Packit 675970
Packit 675970
/**
Packit 675970
 * list_del - deletes entry from list.
Packit 675970
 * @entry: the element to delete from the list.
Packit 675970
 * Note: list_empty on entry does not return true after this, the entry is in an undefined state.
Packit 675970
 */
Packit 675970
static inline void list_del(struct list_head *entry)
Packit 675970
{
Packit 675970
	__list_del(entry->prev, entry->next);
Packit 675970
	entry->next = (void *) 0;
Packit 675970
	entry->prev = (void *) 0;
Packit 675970
}
Packit 675970
Packit 675970
/**
Packit 675970
 * list_del_init - deletes entry from list and reinitialize it.
Packit 675970
 * @entry: the element to delete from the list.
Packit 675970
 */
Packit 675970
static inline void list_del_init(struct list_head *entry)
Packit 675970
{
Packit 675970
	__list_del(entry->prev, entry->next);
Packit 675970
	INIT_LIST_HEAD(entry); 
Packit 675970
}
Packit 675970
Packit 675970
/**
Packit 675970
 * list_move - delete from one list and add as another's head
Packit 675970
 * @list: the entry to move
Packit 675970
 * @head: the head that will precede our entry
Packit 675970
 */
Packit 675970
static inline void list_move(struct list_head *list, struct list_head *head)
Packit 675970
{
Packit 675970
        __list_del(list->prev, list->next);
Packit 675970
        list_add(list, head);
Packit 675970
}
Packit 675970
Packit 675970
/**
Packit 675970
 * list_move_tail - delete from one list and add as another's tail
Packit 675970
 * @list: the entry to move
Packit 675970
 * @head: the head that will follow our entry
Packit 675970
 */
Packit 675970
static inline void list_move_tail(struct list_head *list,
Packit 675970
				  struct list_head *head)
Packit 675970
{
Packit 675970
        __list_del(list->prev, list->next);
Packit 675970
        list_add_tail(list, head);
Packit 675970
}
Packit 675970
Packit 675970
/**
Packit 675970
 * list_empty - tests whether a list is empty
Packit 675970
 * @head: the list to test.
Packit 675970
 */
Packit 675970
static inline int list_empty(struct list_head *head)
Packit 675970
{
Packit 675970
	return head->next == head;
Packit 675970
}
Packit 675970
Packit 675970
static inline void __list_splice(struct list_head *list,
Packit 675970
				 struct list_head *head)
Packit 675970
{
Packit 675970
	struct list_head *first = list->next;
Packit 675970
	struct list_head *last = list->prev;
Packit 675970
	struct list_head *at = head->next;
Packit 675970
Packit 675970
	first->prev = head;
Packit 675970
	head->next = first;
Packit 675970
Packit 675970
	last->next = at;
Packit 675970
	at->prev = last;
Packit 675970
}
Packit 675970
Packit 675970
/**
Packit 675970
 * list_splice - join two lists
Packit 675970
 * @list: the new list to add.
Packit 675970
 * @head: the place to add it in the first list.
Packit 675970
 */
Packit 675970
static inline void list_splice(struct list_head *list, struct list_head *head)
Packit 675970
{
Packit 675970
	if (!list_empty(list))
Packit 675970
		__list_splice(list, head);
Packit 675970
}
Packit 675970
Packit 675970
/**
Packit 675970
 * list_splice_init - join two lists and reinitialise the emptied list.
Packit 675970
 * @list: the new list to add.
Packit 675970
 * @head: the place to add it in the first list.
Packit 675970
 *
Packit 675970
 * The list at @list is reinitialised
Packit 675970
 */
Packit 675970
static inline void list_splice_init(struct list_head *list,
Packit 675970
				    struct list_head *head)
Packit 675970
{
Packit 675970
	if (!list_empty(list)) {
Packit 675970
		__list_splice(list, head);
Packit 675970
		INIT_LIST_HEAD(list);
Packit 675970
	}
Packit 675970
}
Packit 675970
Packit 675970
/**
Packit 675970
 * list_entry - get the struct for this entry
Packit 675970
 * @ptr:	the &struct list_head pointer.
Packit 675970
 * @type:	the type of the struct this is embedded in.
Packit 675970
 * @member:	the name of the list_struct within the struct.
Packit 675970
 */
Packit 675970
#define list_entry(ptr, type, member) \
Packit 675970
	((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
Packit 675970
Packit 675970
/**
Packit 675970
 * list_for_each	-	iterate over a list
Packit 675970
 * @pos:	the &struct list_head to use as a loop counter.
Packit 675970
 * @head:	the head for your list.
Packit 675970
 */
Packit 675970
#define list_for_each(pos, head) \
Packit 675970
	for (pos = (head)->next; pos != (head); \
Packit 675970
        	pos = pos->next)
Packit 675970
/**
Packit 675970
 * list_for_each_prev	-	iterate over a list backwards
Packit 675970
 * @pos:	the &struct list_head to use as a loop counter.
Packit 675970
 * @head:	the head for your list.
Packit 675970
 */
Packit 675970
#define list_for_each_prev(pos, head) \
Packit 675970
	for (pos = (head)->prev; pos != (head); \
Packit 675970
        	pos = pos->prev)
Packit 675970
        	
Packit 675970
/**
Packit 675970
 * list_for_each_safe	-	iterate over a list safe against removal of list entry
Packit 675970
 * @pos:	the &struct list_head to use as a loop counter.
Packit 675970
 * @n:		another &struct list_head to use as temporary storage
Packit 675970
 * @head:	the head for your list.
Packit 675970
 */
Packit 675970
#define list_for_each_safe(pos, n, head) \
Packit 675970
	for (pos = (head)->next, n = pos->next; pos != (head); \
Packit 675970
		pos = n, n = pos->next)
Packit 675970
Packit 675970
/**
Packit 675970
 * list_for_each_entry	-	iterate over list of given type
Packit 675970
 * @pos:	the type * to use as a loop counter.
Packit 675970
 * @head:	the head for your list.
Packit 675970
 * @member:	the name of the list_struct within the struct.
Packit 675970
 */
Packit 675970
#define list_for_each_entry(pos, head, member)				\
Packit 675970
	for (pos = list_entry((head)->next, typeof(*pos), member);	\
Packit 675970
	     &pos->member != (head); 					\
Packit 675970
	     pos = list_entry(pos->member.next, typeof(*pos), member))
Packit 675970
Packit 675970
/**
Packit 675970
 * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
Packit 675970
 * @pos:	the type * to use as a loop counter.
Packit 675970
 * @n:		another type * to use as temporary storage
Packit 675970
 * @head:	the head for your list.
Packit 675970
 * @member:	the name of the list_struct within the struct.
Packit 675970
 */
Packit 675970
#define list_for_each_entry_safe(pos, n, head, member)			\
Packit 675970
	for (pos = list_entry((head)->next, typeof(*pos), member),	\
Packit 675970
		n = list_entry(pos->member.next, typeof(*pos), member);	\
Packit 675970
	     &pos->member != (head); 					\
Packit 675970
	     pos = n, n = list_entry(n->member.next, typeof(*n), member))
Packit 675970
Packit 675970
Packit 675970
#endif