Blame include/list.h

Packit c5a612
#ifndef _LINUX_LIST_H
Packit c5a612
#define _LINUX_LIST_H
Packit c5a612
Packit c5a612
#include <stddef.h>
Packit c5a612
Packit c5a612
#define prefetch(x)	((void)0)
Packit c5a612
Packit c5a612
#define LIST_POISON1	((void *)0x12345678)
Packit c5a612
#define LIST_POISON2	((void *)0x87654321)
Packit c5a612
Packit c5a612
/*
Packit c5a612
 * Simple doubly linked list implementation.
Packit c5a612
 *
Packit c5a612
 * Some of the internal functions ("__xxx") are useful when
Packit c5a612
 * manipulating whole lists rather than single entries, as
Packit c5a612
 * sometimes we already know the next/prev entries and we can
Packit c5a612
 * generate better code by using them directly rather than
Packit c5a612
 * using the generic single-entry routines.
Packit c5a612
 */
Packit c5a612
Packit c5a612
struct list_head {
Packit c5a612
	struct list_head *next, *prev;
Packit c5a612
};
Packit c5a612
Packit c5a612
#define LIST_HEAD_INIT(name) { &(name), &(name) }
Packit c5a612
Packit c5a612
#define LIST_HEAD(name) \
Packit c5a612
	struct list_head name = LIST_HEAD_INIT(name)
Packit c5a612
Packit c5a612
static inline void init_list_head(struct list_head *list)
Packit c5a612
{
Packit c5a612
	list->next = list;
Packit c5a612
	list->prev = list;
Packit c5a612
}
Packit c5a612
Packit c5a612
/*
Packit c5a612
 * Insert a new entry between two known consecutive entries.
Packit c5a612
 *
Packit c5a612
 * This is only for internal list manipulation where we know
Packit c5a612
 * the prev/next entries already!
Packit c5a612
 */
Packit c5a612
static inline void __list_add(struct list_head *new,
Packit c5a612
			      struct list_head *prev,
Packit c5a612
			      struct list_head *next)
Packit c5a612
{
Packit c5a612
	next->prev = new;
Packit c5a612
	new->next = next;
Packit c5a612
	new->prev = prev;
Packit c5a612
	prev->next = new;
Packit c5a612
}
Packit c5a612
Packit c5a612
/**
Packit c5a612
 * list_add - add a new entry
Packit c5a612
 * @new: new entry to be added
Packit c5a612
 * @head: list head to add it after
Packit c5a612
 *
Packit c5a612
 * Insert a new entry after the specified head.
Packit c5a612
 * This is good for implementing stacks.
Packit c5a612
 */
Packit c5a612
static inline void list_add(struct list_head *new, struct list_head *head)
Packit c5a612
{
Packit c5a612
	__list_add(new, head, head->next);
Packit c5a612
}
Packit c5a612
Packit c5a612
Packit c5a612
/**
Packit c5a612
 * list_add_tail - add a new entry
Packit c5a612
 * @new: new entry to be added
Packit c5a612
 * @head: list head to add it before
Packit c5a612
 *
Packit c5a612
 * Insert a new entry before the specified head.
Packit c5a612
 * This is useful for implementing queues.
Packit c5a612
 */
Packit c5a612
static inline void list_add_tail(struct list_head *new, struct list_head *head)
Packit c5a612
{
Packit c5a612
	__list_add(new, head->prev, head);
Packit c5a612
}
Packit c5a612
Packit c5a612
/*
Packit c5a612
 * Delete a list entry by making the prev/next entries
Packit c5a612
 * point to each other.
Packit c5a612
 *
Packit c5a612
 * This is only for internal list manipulation where we know
Packit c5a612
 * the prev/next entries already!
Packit c5a612
 */
Packit c5a612
static inline void __list_del(struct list_head * prev, struct list_head * next)
Packit c5a612
{
Packit c5a612
	next->prev = prev;
Packit c5a612
	prev->next = next;
Packit c5a612
}
Packit c5a612
Packit c5a612
/**
Packit c5a612
 * list_del - deletes entry from list.
Packit c5a612
 * @entry: the element to delete from the list.
Packit c5a612
 * Note: list_empty() on entry does not return true after this, the entry is
Packit c5a612
 * in an undefined state.
Packit c5a612
 */
Packit c5a612
static inline void list_del(struct list_head *entry)
Packit c5a612
{
Packit c5a612
	__list_del(entry->prev, entry->next);
Packit c5a612
	entry->next = LIST_POISON1;
Packit c5a612
	entry->prev = LIST_POISON2;
Packit c5a612
}
Packit c5a612
Packit c5a612
/**
Packit c5a612
 * list_replace - replace old entry by new one
Packit c5a612
 * @old : the element to be replaced
Packit c5a612
 * @new : the new element to insert
Packit c5a612
 *
Packit c5a612
 * If @old was empty, it will be overwritten.
Packit c5a612
 */
Packit c5a612
static inline void list_replace(struct list_head *old,
Packit c5a612
				struct list_head *new)
Packit c5a612
{
Packit c5a612
	new->next = old->next;
Packit c5a612
	new->next->prev = new;
Packit c5a612
	new->prev = old->prev;
Packit c5a612
	new->prev->next = new;
Packit c5a612
}
Packit c5a612
Packit c5a612
static inline void list_replace_init(struct list_head *old,
Packit c5a612
					struct list_head *new)
Packit c5a612
{
Packit c5a612
	list_replace(old, new);
Packit c5a612
	init_list_head(old);
Packit c5a612
}
Packit c5a612
Packit c5a612
/**
Packit c5a612
 * list_del_init - deletes entry from list and reinitialize it.
Packit c5a612
 * @entry: the element to delete from the list.
Packit c5a612
 */
Packit c5a612
static inline void list_del_init(struct list_head *entry)
Packit c5a612
{
Packit c5a612
	__list_del(entry->prev, entry->next);
Packit c5a612
	init_list_head(entry);
Packit c5a612
}
Packit c5a612
Packit c5a612
/**
Packit c5a612
 * list_move - delete from one list and add as another's head
Packit c5a612
 * @list: the entry to move
Packit c5a612
 * @head: the head that will precede our entry
Packit c5a612
 */
Packit c5a612
static inline void list_move(struct list_head *list, struct list_head *head)
Packit c5a612
{
Packit c5a612
	__list_del(list->prev, list->next);
Packit c5a612
	list_add(list, head);
Packit c5a612
}
Packit c5a612
Packit c5a612
/**
Packit c5a612
 * list_move_tail - delete from one list and add as another's tail
Packit c5a612
 * @list: the entry to move
Packit c5a612
 * @head: the head that will follow our entry
Packit c5a612
 */
Packit c5a612
static inline void list_move_tail(struct list_head *list,
Packit c5a612
				  struct list_head *head)
Packit c5a612
{
Packit c5a612
	__list_del(list->prev, list->next);
Packit c5a612
	list_add_tail(list, head);
Packit c5a612
}
Packit c5a612
Packit c5a612
/**
Packit c5a612
 * list_is_last - tests whether @list is the last entry in list @head
Packit c5a612
 * @list: the entry to test
Packit c5a612
 * @head: the head of the list
Packit c5a612
 */
Packit c5a612
static inline int list_is_last(const struct list_head *list,
Packit c5a612
				const struct list_head *head)
Packit c5a612
{
Packit c5a612
	return list->next == head;
Packit c5a612
}
Packit c5a612
Packit c5a612
/**
Packit c5a612
 * list_empty - tests whether a list is empty
Packit c5a612
 * @head: the list to test.
Packit c5a612
 */
Packit c5a612
static inline int list_empty(const struct list_head *head)
Packit c5a612
{
Packit c5a612
	return head->next == head;
Packit c5a612
}
Packit c5a612
Packit c5a612
/**
Packit c5a612
 * list_empty_careful - tests whether a list is empty and not being modified
Packit c5a612
 * @head: the list to test
Packit c5a612
 *
Packit c5a612
 * Description:
Packit c5a612
 * tests whether a list is empty _and_ checks that no other CPU might be
Packit c5a612
 * in the process of modifying either member (next or prev)
Packit c5a612
 *
Packit c5a612
 * NOTE: using list_empty_careful() without synchronization
Packit c5a612
 * can only be safe if the only activity that can happen
Packit c5a612
 * to the list entry is list_del_init(). Eg. it cannot be used
Packit c5a612
 * if another CPU could re-list_add() it.
Packit c5a612
 */
Packit c5a612
static inline int list_empty_careful(const struct list_head *head)
Packit c5a612
{
Packit c5a612
	struct list_head *next = head->next;
Packit c5a612
	return (next == head) && (next == head->prev);
Packit c5a612
}
Packit c5a612
Packit c5a612
/**
Packit c5a612
 * list_is_singular - tests whether a list has just one entry.
Packit c5a612
 * @head: the list to test.
Packit c5a612
 */
Packit c5a612
static inline int list_is_singular(const struct list_head *head)
Packit c5a612
{
Packit c5a612
	return !list_empty(head) && (head->next == head->prev);
Packit c5a612
}
Packit c5a612
Packit c5a612
static inline void __list_cut_position(struct list_head *list,
Packit c5a612
		struct list_head *head, struct list_head *entry)
Packit c5a612
{
Packit c5a612
	struct list_head *new_first = entry->next;
Packit c5a612
	list->next = head->next;
Packit c5a612
	list->next->prev = list;
Packit c5a612
	list->prev = entry;
Packit c5a612
	entry->next = list;
Packit c5a612
	head->next = new_first;
Packit c5a612
	new_first->prev = head;
Packit c5a612
}
Packit c5a612
Packit c5a612
/**
Packit c5a612
 * list_cut_position - cut a list into two
Packit c5a612
 * @list: a new list to add all removed entries
Packit c5a612
 * @head: a list with entries
Packit c5a612
 * @entry: an entry within head, could be the head itself
Packit c5a612
 *	and if so we won't cut the list
Packit c5a612
 *
Packit c5a612
 * This helper moves the initial part of @head, up to and
Packit c5a612
 * including @entry, from @head to @list. You should
Packit c5a612
 * pass on @entry an element you know is on @head. @list
Packit c5a612
 * should be an empty list or a list you do not care about
Packit c5a612
 * losing its data.
Packit c5a612
 *
Packit c5a612
 */
Packit c5a612
static inline void list_cut_position(struct list_head *list,
Packit c5a612
		struct list_head *head, struct list_head *entry)
Packit c5a612
{
Packit c5a612
	if (list_empty(head))
Packit c5a612
		return;
Packit c5a612
	if (list_is_singular(head) &&
Packit c5a612
		(head->next != entry && head != entry))
Packit c5a612
		return;
Packit c5a612
	if (entry == head)
Packit c5a612
		init_list_head(list);
Packit c5a612
	else
Packit c5a612
		__list_cut_position(list, head, entry);
Packit c5a612
}
Packit c5a612
Packit c5a612
static inline void __list_splice(const struct list_head *list,
Packit c5a612
				 struct list_head *prev,
Packit c5a612
				 struct list_head *next)
Packit c5a612
{
Packit c5a612
	struct list_head *first = list->next;
Packit c5a612
	struct list_head *last = list->prev;
Packit c5a612
Packit c5a612
	first->prev = prev;
Packit c5a612
	prev->next = first;
Packit c5a612
Packit c5a612
	last->next = next;
Packit c5a612
	next->prev = last;
Packit c5a612
}
Packit c5a612
Packit c5a612
/**
Packit c5a612
 * list_splice - join two lists, this is designed for stacks
Packit c5a612
 * @list: the new list to add.
Packit c5a612
 * @head: the place to add it in the first list.
Packit c5a612
 */
Packit c5a612
static inline void list_splice(const struct list_head *list,
Packit c5a612
				struct list_head *head)
Packit c5a612
{
Packit c5a612
	if (!list_empty(list))
Packit c5a612
		__list_splice(list, head, head->next);
Packit c5a612
}
Packit c5a612
Packit c5a612
/**
Packit c5a612
 * list_splice_tail - join two lists, each list being a queue
Packit c5a612
 * @list: the new list to add.
Packit c5a612
 * @head: the place to add it in the first list.
Packit c5a612
 */
Packit c5a612
static inline void list_splice_tail(struct list_head *list,
Packit c5a612
				struct list_head *head)
Packit c5a612
{
Packit c5a612
	if (!list_empty(list))
Packit c5a612
		__list_splice(list, head->prev, head);
Packit c5a612
}
Packit c5a612
Packit c5a612
/**
Packit c5a612
 * list_splice_init - join two lists and reinitialise the emptied list.
Packit c5a612
 * @list: the new list to add.
Packit c5a612
 * @head: the place to add it in the first list.
Packit c5a612
 *
Packit c5a612
 * The list at @list is reinitialised
Packit c5a612
 */
Packit c5a612
static inline void list_splice_init(struct list_head *list,
Packit c5a612
				    struct list_head *head)
Packit c5a612
{
Packit c5a612
	if (!list_empty(list)) {
Packit c5a612
		__list_splice(list, head, head->next);
Packit c5a612
		init_list_head(list);
Packit c5a612
	}
Packit c5a612
}
Packit c5a612
Packit c5a612
/**
Packit c5a612
 * list_splice_tail_init - join two lists and reinitialise the emptied list
Packit c5a612
 * @list: the new list to add.
Packit c5a612
 * @head: the place to add it in the first list.
Packit c5a612
 *
Packit c5a612
 * Each of the lists is a queue.
Packit c5a612
 * The list at @list is reinitialised
Packit c5a612
 */
Packit c5a612
static inline void list_splice_tail_init(struct list_head *list,
Packit c5a612
					 struct list_head *head)
Packit c5a612
{
Packit c5a612
	if (!list_empty(list)) {
Packit c5a612
		__list_splice(list, head->prev, head);
Packit c5a612
		init_list_head(list);
Packit c5a612
	}
Packit c5a612
}
Packit c5a612
Packit c5a612
/**
Packit c5a612
 * list_entry - get the struct for this entry
Packit c5a612
 * @ptr:	the &struct list_head pointer.
Packit c5a612
 * @type:	the type of the struct this is embedded in.
Packit c5a612
 * @member:	the name of the list_struct within the struct.
Packit c5a612
 */
Packit c5a612
#define list_entry(ptr, type, member) \
Packit c5a612
	container_of(ptr, type, member)
Packit c5a612
Packit c5a612
/**
Packit c5a612
 * list_first_entry - get the first element from a list
Packit c5a612
 * @ptr:	the list head to take the element from.
Packit c5a612
 * @type:	the type of the struct this is embedded in.
Packit c5a612
 * @member:	the name of the list_struct within the struct.
Packit c5a612
 *
Packit c5a612
 * Note, that list is expected to be not empty.
Packit c5a612
 */
Packit c5a612
#define list_first_entry(ptr, type, member) \
Packit c5a612
	list_entry((ptr)->next, type, member)
Packit c5a612
Packit c5a612
Packit c5a612
/**
Packit c5a612
 * list_for_each_entry	-	iterate over list of given type
Packit c5a612
 * @pos:	the type * to use as a loop cursor.
Packit c5a612
 * @head:	the head for your list.
Packit c5a612
 * @member:	the name of the list_struct within the struct.
Packit c5a612
 */
Packit c5a612
#define list_for_each_entry(pos, head, member)				\
Packit c5a612
	for (pos = list_entry((head)->next, typeof(*pos), member);	\
Packit c5a612
	     prefetch(pos->member.next), &pos->member != (head); 	\
Packit c5a612
	     pos = list_entry(pos->member.next, typeof(*pos), member))
Packit c5a612
Packit c5a612
/**
Packit c5a612
 * list_for_each_entry_reverse - iterate backwards over list of given type.
Packit c5a612
 * @pos:	the type * to use as a loop cursor.
Packit c5a612
 * @head:	the head for your list.
Packit c5a612
 * @member:	the name of the list_struct within the struct.
Packit c5a612
 */
Packit c5a612
#define list_for_each_entry_reverse(pos, head, member)			\
Packit c5a612
	for (pos = list_entry((head)->prev, typeof(*pos), member);	\
Packit c5a612
	     prefetch(pos->member.prev), &pos->member != (head); 	\
Packit c5a612
	     pos = list_entry(pos->member.prev, typeof(*pos), member))
Packit c5a612
Packit c5a612
/**
Packit c5a612
 * list_prepare_entry - prepare a pos entry for use in list_for_each_entry_continue()
Packit c5a612
 * @pos:	the type * to use as a start point
Packit c5a612
 * @head:	the head of the list
Packit c5a612
 * @member:	the name of the list_struct within the struct.
Packit c5a612
 *
Packit c5a612
 * Prepares a pos entry for use as a start point in list_for_each_entry_continue().
Packit c5a612
 */
Packit c5a612
#define list_prepare_entry(pos, head, member) \
Packit c5a612
	((pos) ? : list_entry(head, typeof(*pos), member))
Packit c5a612
Packit c5a612
/**
Packit c5a612
 * list_for_each_entry_continue - continue iteration over list of given type
Packit c5a612
 * @pos:	the type * to use as a loop cursor.
Packit c5a612
 * @head:	the head for your list.
Packit c5a612
 * @member:	the name of the list_struct within the struct.
Packit c5a612
 *
Packit c5a612
 * Continue to iterate over list of given type, continuing after
Packit c5a612
 * the current position.
Packit c5a612
 */
Packit c5a612
#define list_for_each_entry_continue(pos, head, member) 		\
Packit c5a612
	for (pos = list_entry(pos->member.next, typeof(*pos), member);	\
Packit c5a612
	     prefetch(pos->member.next), &pos->member != (head);	\
Packit c5a612
	     pos = list_entry(pos->member.next, typeof(*pos), member))
Packit c5a612
Packit c5a612
/**
Packit c5a612
 * list_for_each_entry_continue_reverse - iterate backwards from the given point
Packit c5a612
 * @pos:	the type * to use as a loop cursor.
Packit c5a612
 * @head:	the head for your list.
Packit c5a612
 * @member:	the name of the list_struct within the struct.
Packit c5a612
 *
Packit c5a612
 * Start to iterate over list of given type backwards, continuing after
Packit c5a612
 * the current position.
Packit c5a612
 */
Packit c5a612
#define list_for_each_entry_continue_reverse(pos, head, member)		\
Packit c5a612
	for (pos = list_entry(pos->member.prev, typeof(*pos), member);	\
Packit c5a612
	     prefetch(pos->member.prev), &pos->member != (head);	\
Packit c5a612
	     pos = list_entry(pos->member.prev, typeof(*pos), member))
Packit c5a612
Packit c5a612
/**
Packit c5a612
 * list_for_each_entry_from - iterate over list of given type from the current point
Packit c5a612
 * @pos:	the type * to use as a loop cursor.
Packit c5a612
 * @head:	the head for your list.
Packit c5a612
 * @member:	the name of the list_struct within the struct.
Packit c5a612
 *
Packit c5a612
 * Iterate over list of given type, continuing from current position.
Packit c5a612
 */
Packit c5a612
#define list_for_each_entry_from(pos, head, member) 			\
Packit c5a612
	for (; prefetch(pos->member.next), &pos->member != (head);	\
Packit c5a612
	     pos = list_entry(pos->member.next, typeof(*pos), member))
Packit c5a612
Packit c5a612
/**
Packit c5a612
 * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
Packit c5a612
 * @pos:	the type * to use as a loop cursor.
Packit c5a612
 * @n:		another type * to use as temporary storage
Packit c5a612
 * @head:	the head for your list.
Packit c5a612
 * @member:	the name of the list_struct within the struct.
Packit c5a612
 */
Packit c5a612
#define list_for_each_entry_safe(pos, n, head, member)			\
Packit c5a612
	for (pos = list_entry((head)->next, typeof(*pos), member),	\
Packit c5a612
		n = list_entry(pos->member.next, typeof(*pos), member);	\
Packit c5a612
	     &pos->member != (head); 					\
Packit c5a612
	     pos = n, n = list_entry(n->member.next, typeof(*n), member))
Packit c5a612
Packit c5a612
/**
Packit c5a612
 * list_for_each_entry_safe_continue
Packit c5a612
 * @pos:	the type * to use as a loop cursor.
Packit c5a612
 * @n:		another type * to use as temporary storage
Packit c5a612
 * @head:	the head for your list.
Packit c5a612
 * @member:	the name of the list_struct within the struct.
Packit c5a612
 *
Packit c5a612
 * Iterate over list of given type, continuing after current point,
Packit c5a612
 * safe against removal of list entry.
Packit c5a612
 */
Packit c5a612
#define list_for_each_entry_safe_continue(pos, n, head, member) 		\
Packit c5a612
	for (pos = list_entry(pos->member.next, typeof(*pos), member), 		\
Packit c5a612
		n = list_entry(pos->member.next, typeof(*pos), member);		\
Packit c5a612
	     &pos->member != (head);						\
Packit c5a612
	     pos = n, n = list_entry(n->member.next, typeof(*n), member))
Packit c5a612
Packit c5a612
/**
Packit c5a612
 * list_for_each_entry_safe_from
Packit c5a612
 * @pos:	the type * to use as a loop cursor.
Packit c5a612
 * @n:		another type * to use as temporary storage
Packit c5a612
 * @head:	the head for your list.
Packit c5a612
 * @member:	the name of the list_struct within the struct.
Packit c5a612
 *
Packit c5a612
 * Iterate over list of given type from current point, safe against
Packit c5a612
 * removal of list entry.
Packit c5a612
 */
Packit c5a612
#define list_for_each_entry_safe_from(pos, n, head, member) 			\
Packit c5a612
	for (n = list_entry(pos->member.next, typeof(*pos), member);		\
Packit c5a612
	     &pos->member != (head);						\
Packit c5a612
	     pos = n, n = list_entry(n->member.next, typeof(*n), member))
Packit c5a612
Packit c5a612
/**
Packit c5a612
 * list_for_each_entry_safe_reverse
Packit c5a612
 * @pos:	the type * to use as a loop cursor.
Packit c5a612
 * @n:		another type * to use as temporary storage
Packit c5a612
 * @head:	the head for your list.
Packit c5a612
 * @member:	the name of the list_struct within the struct.
Packit c5a612
 *
Packit c5a612
 * Iterate backwards over list of given type, safe against removal
Packit c5a612
 * of list entry.
Packit c5a612
 */
Packit c5a612
#define list_for_each_entry_safe_reverse(pos, n, head, member)		\
Packit c5a612
	for (pos = list_entry((head)->prev, typeof(*pos), member),	\
Packit c5a612
		n = list_entry(pos->member.prev, typeof(*pos), member);	\
Packit c5a612
	     &pos->member != (head); 					\
Packit c5a612
	     pos = n, n = list_entry(n->member.prev, typeof(*n), member))
Packit c5a612
Packit c5a612
/*
Packit c5a612
 * Double linked lists with a single pointer list head.
Packit c5a612
 * Mostly useful for hash tables where the two pointer list head is
Packit c5a612
 * too wasteful.
Packit c5a612
 * You lose the ability to access the tail in O(1).
Packit c5a612
 */
Packit c5a612
Packit c5a612
struct hlist_head {
Packit c5a612
	struct hlist_node *first;
Packit c5a612
};
Packit c5a612
Packit c5a612
struct hlist_node {
Packit c5a612
	struct hlist_node *next, **pprev;
Packit c5a612
};
Packit c5a612
Packit c5a612
#define HLIST_HEAD_INIT { .first = NULL }
Packit c5a612
#define HLIST_HEAD(name) struct hlist_head name = {  .first = NULL }
Packit c5a612
Packit c5a612
#define init_hlist_head(ptr) ((ptr)->first = NULL)
Packit c5a612
Packit c5a612
static inline void init_hlist_node(struct hlist_node *h)
Packit c5a612
{
Packit c5a612
	h->next = NULL;
Packit c5a612
	h->pprev = NULL;
Packit c5a612
}
Packit c5a612
Packit c5a612
static inline int hlist_unhashed(const struct hlist_node *h)
Packit c5a612
{
Packit c5a612
	return !h->pprev;
Packit c5a612
}
Packit c5a612
Packit c5a612
static inline int hlist_empty(const struct hlist_head *h)
Packit c5a612
{
Packit c5a612
	return !h->first;
Packit c5a612
}
Packit c5a612
Packit c5a612
static inline void __hlist_del(struct hlist_node *n)
Packit c5a612
{
Packit c5a612
	struct hlist_node *next = n->next;
Packit c5a612
	struct hlist_node **pprev = n->pprev;
Packit c5a612
	*pprev = next;
Packit c5a612
	if (next)
Packit c5a612
		next->pprev = pprev;
Packit c5a612
}
Packit c5a612
Packit c5a612
static inline void hlist_del(struct hlist_node *n)
Packit c5a612
{
Packit c5a612
	__hlist_del(n);
Packit c5a612
	n->next = LIST_POISON1;
Packit c5a612
	n->pprev = LIST_POISON2;
Packit c5a612
}
Packit c5a612
Packit c5a612
static inline void hlist_del_init(struct hlist_node *n)
Packit c5a612
{
Packit c5a612
	if (!hlist_unhashed(n)) {
Packit c5a612
		__hlist_del(n);
Packit c5a612
		init_hlist_node(n);
Packit c5a612
	}
Packit c5a612
}
Packit c5a612
Packit c5a612
static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
Packit c5a612
{
Packit c5a612
	struct hlist_node *first = h->first;
Packit c5a612
	n->next = first;
Packit c5a612
	if (first)
Packit c5a612
		first->pprev = &n->next;
Packit c5a612
	h->first = n;
Packit c5a612
	n->pprev = &h->first;
Packit c5a612
}
Packit c5a612
Packit c5a612
/* next must be != NULL */
Packit c5a612
static inline void hlist_add_before(struct hlist_node *n,
Packit c5a612
					struct hlist_node *next)
Packit c5a612
{
Packit c5a612
	n->pprev = next->pprev;
Packit c5a612
	n->next = next;
Packit c5a612
	next->pprev = &n->next;
Packit c5a612
	*(n->pprev) = n;
Packit c5a612
}
Packit c5a612
Packit c5a612
static inline void hlist_add_after(struct hlist_node *n,
Packit c5a612
					struct hlist_node *next)
Packit c5a612
{
Packit c5a612
	next->next = n->next;
Packit c5a612
	n->next = next;
Packit c5a612
	next->pprev = &n->next;
Packit c5a612
Packit c5a612
	if(next->next)
Packit c5a612
		next->next->pprev  = &next->next;
Packit c5a612
}
Packit c5a612
Packit c5a612
#define hlist_entry(ptr, type, member) container_of(ptr,type,member)
Packit c5a612
Packit c5a612
#define hlist_for_each(pos, head) \
Packit c5a612
	for (pos = (head)->first; pos && ({ prefetch(pos->next); 1; }); \
Packit c5a612
	     pos = pos->next)
Packit c5a612
Packit c5a612
#define hlist_for_each_safe(pos, n, head) \
Packit c5a612
	for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \
Packit c5a612
	     pos = n)
Packit c5a612
Packit c5a612
/**
Packit c5a612
 * hlist_for_each_entry	- iterate over list of given type
Packit c5a612
 * @tpos:	the type * to use as a loop cursor.
Packit c5a612
 * @pos:	the &struct hlist_node to use as a loop cursor.
Packit c5a612
 * @head:	the head for your list.
Packit c5a612
 * @member:	the name of the hlist_node within the struct.
Packit c5a612
 */
Packit c5a612
#define hlist_for_each_entry(tpos, pos, head, member)			 \
Packit c5a612
	for (pos = (head)->first;					 \
Packit c5a612
	     pos && ({ prefetch(pos->next); 1;}) &&			 \
Packit c5a612
		({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
Packit c5a612
	     pos = pos->next)
Packit c5a612
Packit c5a612
/**
Packit c5a612
 * hlist_for_each_entry_continue - iterate over a hlist continuing after current point
Packit c5a612
 * @tpos:	the type * to use as a loop cursor.
Packit c5a612
 * @pos:	the &struct hlist_node to use as a loop cursor.
Packit c5a612
 * @member:	the name of the hlist_node within the struct.
Packit c5a612
 */
Packit c5a612
#define hlist_for_each_entry_continue(tpos, pos, member)		 \
Packit c5a612
	for (pos = (pos)->next;						 \
Packit c5a612
	     pos && ({ prefetch(pos->next); 1;}) &&			 \
Packit c5a612
		({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
Packit c5a612
	     pos = pos->next)
Packit c5a612
Packit c5a612
/**
Packit c5a612
 * hlist_for_each_entry_from - iterate over a hlist continuing from current point
Packit c5a612
 * @tpos:	the type * to use as a loop cursor.
Packit c5a612
 * @pos:	the &struct hlist_node to use as a loop cursor.
Packit c5a612
 * @member:	the name of the hlist_node within the struct.
Packit c5a612
 */
Packit c5a612
#define hlist_for_each_entry_from(tpos, pos, member)			 \
Packit c5a612
	for (; pos && ({ prefetch(pos->next); 1;}) &&			 \
Packit c5a612
		({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
Packit c5a612
	     pos = pos->next)
Packit c5a612
Packit c5a612
/**
Packit c5a612
 * hlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry
Packit c5a612
 * @tpos:	the type * to use as a loop cursor.
Packit c5a612
 * @pos:	the &struct hlist_node to use as a loop cursor.
Packit c5a612
 * @n:		another &struct hlist_node to use as temporary storage
Packit c5a612
 * @head:	the head for your list.
Packit c5a612
 * @member:	the name of the hlist_node within the struct.
Packit c5a612
 */
Packit c5a612
#define hlist_for_each_entry_safe(tpos, pos, n, head, member) 		 \
Packit c5a612
	for (pos = (head)->first;					 \
Packit c5a612
	     pos && ({ n = pos->next; 1; }) && 				 \
Packit c5a612
		({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
Packit c5a612
	     pos = n)
Packit c5a612
Packit c5a612
#endif