Blame libiptc/linux_list.h

Packit Service d1fe03
#ifndef _LINUX_LIST_H
Packit Service d1fe03
#define _LINUX_LIST_H
Packit Service d1fe03
Packit Service d1fe03
#undef offsetof
Packit Service d1fe03
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
Packit Service d1fe03
Packit Service d1fe03
/**
Packit Service d1fe03
 * container_of - cast a member of a structure out to the containing structure
Packit Service d1fe03
 *
Packit Service d1fe03
 * @ptr:	the pointer to the member.
Packit Service d1fe03
 * @type:	the type of the container struct this is embedded in.
Packit Service d1fe03
 * @member:	the name of the member within the struct.
Packit Service d1fe03
 *
Packit Service d1fe03
 */
Packit Service d1fe03
#define container_of(ptr, type, member) ({			\
Packit Service d1fe03
        const typeof( ((type *)0)->member ) *__mptr = (ptr);	\
Packit Service d1fe03
        (type *)( (char *)__mptr - offsetof(type,member) );})
Packit Service d1fe03
Packit Service d1fe03
/*
Packit Service d1fe03
 * Check at compile time that something is of a particular type.
Packit Service d1fe03
 * Always evaluates to 1 so you may use it easily in comparisons.
Packit Service d1fe03
 */
Packit Service d1fe03
#define typecheck(type,x) \
Packit Service d1fe03
({	type __dummy; \
Packit Service d1fe03
	typeof(x) __dummy2; \
Packit Service d1fe03
	(void)(&__dummy == &__dummy2); \
Packit Service d1fe03
	1; \
Packit Service d1fe03
})
Packit Service d1fe03
Packit Service d1fe03
#define prefetch(x)		((void)0)
Packit Service d1fe03
Packit Service d1fe03
/* empty define to make this work in userspace -HW */
Packit Service d1fe03
#define smp_wmb()
Packit Service d1fe03
Packit Service d1fe03
/*
Packit Service d1fe03
 * These are non-NULL pointers that will result in page faults
Packit Service d1fe03
 * under normal circumstances, used to verify that nobody uses
Packit Service d1fe03
 * non-initialized list entries.
Packit Service d1fe03
 */
Packit Service d1fe03
#define LIST_POISON1  ((void *) 0x00100100)
Packit Service d1fe03
#define LIST_POISON2  ((void *) 0x00200200)
Packit Service d1fe03
Packit Service d1fe03
/*
Packit Service d1fe03
 * Simple doubly linked list implementation.
Packit Service d1fe03
 *
Packit Service d1fe03
 * Some of the internal functions ("__xxx") are useful when
Packit Service d1fe03
 * manipulating whole lists rather than single entries, as
Packit Service d1fe03
 * sometimes we already know the next/prev entries and we can
Packit Service d1fe03
 * generate better code by using them directly rather than
Packit Service d1fe03
 * using the generic single-entry routines.
Packit Service d1fe03
 */
Packit Service d1fe03
Packit Service d1fe03
struct list_head {
Packit Service d1fe03
	struct list_head *next, *prev;
Packit Service d1fe03
};
Packit Service d1fe03
Packit Service d1fe03
#define LIST_HEAD_INIT(name) { &(name), &(name) }
Packit Service d1fe03
Packit Service d1fe03
#define LIST_HEAD(name) \
Packit Service d1fe03
	struct list_head name = LIST_HEAD_INIT(name)
Packit Service d1fe03
Packit Service d1fe03
#define INIT_LIST_HEAD(ptr) do { \
Packit Service d1fe03
	(ptr)->next = (ptr); (ptr)->prev = (ptr); \
Packit Service d1fe03
} while (0)
Packit Service d1fe03
Packit Service d1fe03
/*
Packit Service d1fe03
 * Insert a new entry between two known consecutive entries.
Packit Service d1fe03
 *
Packit Service d1fe03
 * This is only for internal list manipulation where we know
Packit Service d1fe03
 * the prev/next entries already!
Packit Service d1fe03
 */
Packit Service d1fe03
static inline void __list_add(struct list_head *new,
Packit Service d1fe03
			      struct list_head *prev,
Packit Service d1fe03
			      struct list_head *next)
Packit Service d1fe03
{
Packit Service d1fe03
	next->prev = new;
Packit Service d1fe03
	new->next = next;
Packit Service d1fe03
	new->prev = prev;
Packit Service d1fe03
	prev->next = new;
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
/**
Packit Service d1fe03
 * list_add - add a new entry
Packit Service d1fe03
 * @new: new entry to be added
Packit Service d1fe03
 * @head: list head to add it after
Packit Service d1fe03
 *
Packit Service d1fe03
 * Insert a new entry after the specified head.
Packit Service d1fe03
 * This is good for implementing stacks.
Packit Service d1fe03
 */
Packit Service d1fe03
static inline void list_add(struct list_head *new, struct list_head *head)
Packit Service d1fe03
{
Packit Service d1fe03
	__list_add(new, head, head->next);
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
/**
Packit Service d1fe03
 * list_add_tail - add a new entry
Packit Service d1fe03
 * @new: new entry to be added
Packit Service d1fe03
 * @head: list head to add it before
Packit Service d1fe03
 *
Packit Service d1fe03
 * Insert a new entry before the specified head.
Packit Service d1fe03
 * This is useful for implementing queues.
Packit Service d1fe03
 */
Packit Service d1fe03
static inline void list_add_tail(struct list_head *new, struct list_head *head)
Packit Service d1fe03
{
Packit Service d1fe03
	__list_add(new, head->prev, head);
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
/*
Packit Service d1fe03
 * Insert a new entry between two known consecutive entries.
Packit Service d1fe03
 *
Packit Service d1fe03
 * This is only for internal list manipulation where we know
Packit Service d1fe03
 * the prev/next entries already!
Packit Service d1fe03
 */
Packit Service d1fe03
static inline void __list_add_rcu(struct list_head * new,
Packit Service d1fe03
		struct list_head * prev, struct list_head * next)
Packit Service d1fe03
{
Packit Service d1fe03
	new->next = next;
Packit Service d1fe03
	new->prev = prev;
Packit Service d1fe03
	smp_wmb();
Packit Service d1fe03
	next->prev = new;
Packit Service d1fe03
	prev->next = new;
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
/**
Packit Service d1fe03
 * list_add_rcu - add a new entry to rcu-protected list
Packit Service d1fe03
 * @new: new entry to be added
Packit Service d1fe03
 * @head: list head to add it after
Packit Service d1fe03
 *
Packit Service d1fe03
 * Insert a new entry after the specified head.
Packit Service d1fe03
 * This is good for implementing stacks.
Packit Service d1fe03
 *
Packit Service d1fe03
 * The caller must take whatever precautions are necessary
Packit Service d1fe03
 * (such as holding appropriate locks) to avoid racing
Packit Service d1fe03
 * with another list-mutation primitive, such as list_add_rcu()
Packit Service d1fe03
 * or list_del_rcu(), running on this same list.
Packit Service d1fe03
 * However, it is perfectly legal to run concurrently with
Packit Service d1fe03
 * the _rcu list-traversal primitives, such as
Packit Service d1fe03
 * list_for_each_entry_rcu().
Packit Service d1fe03
 */
Packit Service d1fe03
static inline void list_add_rcu(struct list_head *new, struct list_head *head)
Packit Service d1fe03
{
Packit Service d1fe03
	__list_add_rcu(new, head, head->next);
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
/**
Packit Service d1fe03
 * list_add_tail_rcu - add a new entry to rcu-protected list
Packit Service d1fe03
 * @new: new entry to be added
Packit Service d1fe03
 * @head: list head to add it before
Packit Service d1fe03
 *
Packit Service d1fe03
 * Insert a new entry before the specified head.
Packit Service d1fe03
 * This is useful for implementing queues.
Packit Service d1fe03
 *
Packit Service d1fe03
 * The caller must take whatever precautions are necessary
Packit Service d1fe03
 * (such as holding appropriate locks) to avoid racing
Packit Service d1fe03
 * with another list-mutation primitive, such as list_add_tail_rcu()
Packit Service d1fe03
 * or list_del_rcu(), running on this same list.
Packit Service d1fe03
 * However, it is perfectly legal to run concurrently with
Packit Service d1fe03
 * the _rcu list-traversal primitives, such as
Packit Service d1fe03
 * list_for_each_entry_rcu().
Packit Service d1fe03
 */
Packit Service d1fe03
static inline void list_add_tail_rcu(struct list_head *new,
Packit Service d1fe03
					struct list_head *head)
Packit Service d1fe03
{
Packit Service d1fe03
	__list_add_rcu(new, head->prev, head);
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
/*
Packit Service d1fe03
 * Delete a list entry by making the prev/next entries
Packit Service d1fe03
 * point to each other.
Packit Service d1fe03
 *
Packit Service d1fe03
 * This is only for internal list manipulation where we know
Packit Service d1fe03
 * the prev/next entries already!
Packit Service d1fe03
 */
Packit Service d1fe03
static inline void __list_del(struct list_head * prev, struct list_head * next)
Packit Service d1fe03
{
Packit Service d1fe03
	next->prev = prev;
Packit Service d1fe03
	prev->next = next;
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
/**
Packit Service d1fe03
 * list_del - deletes entry from list.
Packit Service d1fe03
 * @entry: the element to delete from the list.
Packit Service d1fe03
 * Note: list_empty on entry does not return true after this, the entry is
Packit Service d1fe03
 * in an undefined state.
Packit Service d1fe03
 */
Packit Service d1fe03
static inline void list_del(struct list_head *entry)
Packit Service d1fe03
{
Packit Service d1fe03
	__list_del(entry->prev, entry->next);
Packit Service d1fe03
	entry->next = LIST_POISON1;
Packit Service d1fe03
	entry->prev = LIST_POISON2;
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
/**
Packit Service d1fe03
 * list_del_rcu - deletes entry from list without re-initialization
Packit Service d1fe03
 * @entry: the element to delete from the list.
Packit Service d1fe03
 *
Packit Service d1fe03
 * Note: list_empty on entry does not return true after this,
Packit Service d1fe03
 * the entry is in an undefined state. It is useful for RCU based
Packit Service d1fe03
 * lockfree traversal.
Packit Service d1fe03
 *
Packit Service d1fe03
 * In particular, it means that we can not poison the forward
Packit Service d1fe03
 * pointers that may still be used for walking the list.
Packit Service d1fe03
 *
Packit Service d1fe03
 * The caller must take whatever precautions are necessary
Packit Service d1fe03
 * (such as holding appropriate locks) to avoid racing
Packit Service d1fe03
 * with another list-mutation primitive, such as list_del_rcu()
Packit Service d1fe03
 * or list_add_rcu(), running on this same list.
Packit Service d1fe03
 * However, it is perfectly legal to run concurrently with
Packit Service d1fe03
 * the _rcu list-traversal primitives, such as
Packit Service d1fe03
 * list_for_each_entry_rcu().
Packit Service d1fe03
 *
Packit Service d1fe03
 * Note that the caller is not permitted to immediately free
Packit Service d1fe03
 * the newly deleted entry.  Instead, either synchronize_kernel()
Packit Service d1fe03
 * or call_rcu() must be used to defer freeing until an RCU
Packit Service d1fe03
 * grace period has elapsed.
Packit Service d1fe03
 */
Packit Service d1fe03
static inline void list_del_rcu(struct list_head *entry)
Packit Service d1fe03
{
Packit Service d1fe03
	__list_del(entry->prev, entry->next);
Packit Service d1fe03
	entry->prev = LIST_POISON2;
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
/**
Packit Service d1fe03
 * list_del_init - deletes entry from list and reinitialize it.
Packit Service d1fe03
 * @entry: the element to delete from the list.
Packit Service d1fe03
 */
Packit Service d1fe03
static inline void list_del_init(struct list_head *entry)
Packit Service d1fe03
{
Packit Service d1fe03
	__list_del(entry->prev, entry->next);
Packit Service d1fe03
	INIT_LIST_HEAD(entry);
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
/**
Packit Service d1fe03
 * list_move - delete from one list and add as another's head
Packit Service d1fe03
 * @list: the entry to move
Packit Service d1fe03
 * @head: the head that will precede our entry
Packit Service d1fe03
 */
Packit Service d1fe03
static inline void list_move(struct list_head *list, struct list_head *head)
Packit Service d1fe03
{
Packit Service d1fe03
        __list_del(list->prev, list->next);
Packit Service d1fe03
        list_add(list, head);
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
/**
Packit Service d1fe03
 * list_move_tail - delete from one list and add as another's tail
Packit Service d1fe03
 * @list: the entry to move
Packit Service d1fe03
 * @head: the head that will follow our entry
Packit Service d1fe03
 */
Packit Service d1fe03
static inline void list_move_tail(struct list_head *list,
Packit Service d1fe03
				  struct list_head *head)
Packit Service d1fe03
{
Packit Service d1fe03
        __list_del(list->prev, list->next);
Packit Service d1fe03
        list_add_tail(list, head);
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
/**
Packit Service d1fe03
 * list_empty - tests whether a list is empty
Packit Service d1fe03
 * @head: the list to test.
Packit Service d1fe03
 */
Packit Service d1fe03
static inline int list_empty(const struct list_head *head)
Packit Service d1fe03
{
Packit Service d1fe03
	return head->next == head;
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
/**
Packit Service d1fe03
 * list_empty_careful - tests whether a list is
Packit Service d1fe03
 * empty _and_ checks that no other CPU might be
Packit Service d1fe03
 * in the process of still modifying either member
Packit Service d1fe03
 *
Packit Service d1fe03
 * NOTE: using list_empty_careful() without synchronization
Packit Service d1fe03
 * can only be safe if the only activity that can happen
Packit Service d1fe03
 * to the list entry is list_del_init(). Eg. it cannot be used
Packit Service d1fe03
 * if another CPU could re-list_add() it.
Packit Service d1fe03
 *
Packit Service d1fe03
 * @head: the list to test.
Packit Service d1fe03
 */
Packit Service d1fe03
static inline int list_empty_careful(const struct list_head *head)
Packit Service d1fe03
{
Packit Service d1fe03
	struct list_head *next = head->next;
Packit Service d1fe03
	return (next == head) && (next == head->prev);
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
static inline void __list_splice(struct list_head *list,
Packit Service d1fe03
				 struct list_head *head)
Packit Service d1fe03
{
Packit Service d1fe03
	struct list_head *first = list->next;
Packit Service d1fe03
	struct list_head *last = list->prev;
Packit Service d1fe03
	struct list_head *at = head->next;
Packit Service d1fe03
Packit Service d1fe03
	first->prev = head;
Packit Service d1fe03
	head->next = first;
Packit Service d1fe03
Packit Service d1fe03
	last->next = at;
Packit Service d1fe03
	at->prev = last;
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
/**
Packit Service d1fe03
 * list_splice - join two lists
Packit Service d1fe03
 * @list: the new list to add.
Packit Service d1fe03
 * @head: the place to add it in the first list.
Packit Service d1fe03
 */
Packit Service d1fe03
static inline void list_splice(struct list_head *list, struct list_head *head)
Packit Service d1fe03
{
Packit Service d1fe03
	if (!list_empty(list))
Packit Service d1fe03
		__list_splice(list, head);
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
/**
Packit Service d1fe03
 * list_splice_init - join two lists and reinitialise the emptied list.
Packit Service d1fe03
 * @list: the new list to add.
Packit Service d1fe03
 * @head: the place to add it in the first list.
Packit Service d1fe03
 *
Packit Service d1fe03
 * The list at @list is reinitialised
Packit Service d1fe03
 */
Packit Service d1fe03
static inline void list_splice_init(struct list_head *list,
Packit Service d1fe03
				    struct list_head *head)
Packit Service d1fe03
{
Packit Service d1fe03
	if (!list_empty(list)) {
Packit Service d1fe03
		__list_splice(list, head);
Packit Service d1fe03
		INIT_LIST_HEAD(list);
Packit Service d1fe03
	}
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
/**
Packit Service d1fe03
 * list_entry - get the struct for this entry
Packit Service d1fe03
 * @ptr:	the &struct list_head pointer.
Packit Service d1fe03
 * @type:	the type of the struct this is embedded in.
Packit Service d1fe03
 * @member:	the name of the list_struct within the struct.
Packit Service d1fe03
 */
Packit Service d1fe03
#define list_entry(ptr, type, member) \
Packit Service d1fe03
	container_of(ptr, type, member)
Packit Service d1fe03
Packit Service d1fe03
/**
Packit Service d1fe03
 * list_for_each	-	iterate over a list
Packit Service d1fe03
 * @pos:	the &struct list_head to use as a loop counter.
Packit Service d1fe03
 * @head:	the head for your list.
Packit Service d1fe03
 */
Packit Service d1fe03
#define list_for_each(pos, head) \
Packit Service d1fe03
	for (pos = (head)->next, prefetch(pos->next); pos != (head); \
Packit Service d1fe03
        	pos = pos->next, prefetch(pos->next))
Packit Service d1fe03
Packit Service d1fe03
/**
Packit Service d1fe03
 * __list_for_each	-	iterate over a list
Packit Service d1fe03
 * @pos:	the &struct list_head to use as a loop counter.
Packit Service d1fe03
 * @head:	the head for your list.
Packit Service d1fe03
 *
Packit Service d1fe03
 * This variant differs from list_for_each() in that it's the
Packit Service d1fe03
 * simplest possible list iteration code, no prefetching is done.
Packit Service d1fe03
 * Use this for code that knows the list to be very short (empty
Packit Service d1fe03
 * or 1 entry) most of the time.
Packit Service d1fe03
 */
Packit Service d1fe03
#define __list_for_each(pos, head) \
Packit Service d1fe03
	for (pos = (head)->next; pos != (head); pos = pos->next)
Packit Service d1fe03
Packit Service d1fe03
/**
Packit Service d1fe03
 * list_for_each_prev	-	iterate over a list backwards
Packit Service d1fe03
 * @pos:	the &struct list_head to use as a loop counter.
Packit Service d1fe03
 * @head:	the head for your list.
Packit Service d1fe03
 */
Packit Service d1fe03
#define list_for_each_prev(pos, head) \
Packit Service d1fe03
	for (pos = (head)->prev, prefetch(pos->prev); pos != (head); \
Packit Service d1fe03
        	pos = pos->prev, prefetch(pos->prev))
Packit Service d1fe03
Packit Service d1fe03
/**
Packit Service d1fe03
 * list_for_each_safe	-	iterate over a list safe against removal of list entry
Packit Service d1fe03
 * @pos:	the &struct list_head to use as a loop counter.
Packit Service d1fe03
 * @n:		another &struct list_head to use as temporary storage
Packit Service d1fe03
 * @head:	the head for your list.
Packit Service d1fe03
 */
Packit Service d1fe03
#define list_for_each_safe(pos, n, head) \
Packit Service d1fe03
	for (pos = (head)->next, n = pos->next; pos != (head); \
Packit Service d1fe03
		pos = n, n = pos->next)
Packit Service d1fe03
Packit Service d1fe03
/**
Packit Service d1fe03
 * list_for_each_entry	-	iterate over list of given type
Packit Service d1fe03
 * @pos:	the type * to use as a loop counter.
Packit Service d1fe03
 * @head:	the head for your list.
Packit Service d1fe03
 * @member:	the name of the list_struct within the struct.
Packit Service d1fe03
 */
Packit Service d1fe03
#define list_for_each_entry(pos, head, member)				\
Packit Service d1fe03
	for (pos = list_entry((head)->next, typeof(*pos), member),	\
Packit Service d1fe03
		     prefetch(pos->member.next);			\
Packit Service d1fe03
	     &pos->member != (head); 					\
Packit Service d1fe03
	     pos = list_entry(pos->member.next, typeof(*pos), member),	\
Packit Service d1fe03
		     prefetch(pos->member.next))
Packit Service d1fe03
Packit Service d1fe03
/**
Packit Service d1fe03
 * list_for_each_entry_reverse - iterate backwards over list of given type.
Packit Service d1fe03
 * @pos:	the type * to use as a loop counter.
Packit Service d1fe03
 * @head:	the head for your list.
Packit Service d1fe03
 * @member:	the name of the list_struct within the struct.
Packit Service d1fe03
 */
Packit Service d1fe03
#define list_for_each_entry_reverse(pos, head, member)			\
Packit Service d1fe03
	for (pos = list_entry((head)->prev, typeof(*pos), member),	\
Packit Service d1fe03
		     prefetch(pos->member.prev);			\
Packit Service d1fe03
	     &pos->member != (head); 					\
Packit Service d1fe03
	     pos = list_entry(pos->member.prev, typeof(*pos), member),	\
Packit Service d1fe03
		     prefetch(pos->member.prev))
Packit Service d1fe03
Packit Service d1fe03
/**
Packit Service d1fe03
 * list_prepare_entry - prepare a pos entry for use as a start point in
Packit Service d1fe03
 *			list_for_each_entry_continue
Packit Service d1fe03
 * @pos:	the type * to use as a start point
Packit Service d1fe03
 * @head:	the head of the list
Packit Service d1fe03
 * @member:	the name of the list_struct within the struct.
Packit Service d1fe03
 */
Packit Service d1fe03
#define list_prepare_entry(pos, head, member) \
Packit Service d1fe03
	((pos) ? : list_entry(head, typeof(*pos), member))
Packit Service d1fe03
Packit Service d1fe03
/**
Packit Service d1fe03
 * list_for_each_entry_continue -	iterate over list of given type
Packit Service d1fe03
 *			continuing after existing point
Packit Service d1fe03
 * @pos:	the type * to use as a loop counter.
Packit Service d1fe03
 * @head:	the head for your list.
Packit Service d1fe03
 * @member:	the name of the list_struct within the struct.
Packit Service d1fe03
 */
Packit Service d1fe03
#define list_for_each_entry_continue(pos, head, member) 		\
Packit Service d1fe03
	for (pos = list_entry(pos->member.next, typeof(*pos), member),	\
Packit Service d1fe03
		     prefetch(pos->member.next);			\
Packit Service d1fe03
	     &pos->member != (head);					\
Packit Service d1fe03
	     pos = list_entry(pos->member.next, typeof(*pos), member),	\
Packit Service d1fe03
		     prefetch(pos->member.next))
Packit Service d1fe03
Packit Service d1fe03
/**
Packit Service d1fe03
 * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
Packit Service d1fe03
 * @pos:	the type * to use as a loop counter.
Packit Service d1fe03
 * @n:		another type * to use as temporary storage
Packit Service d1fe03
 * @head:	the head for your list.
Packit Service d1fe03
 * @member:	the name of the list_struct within the struct.
Packit Service d1fe03
 */
Packit Service d1fe03
#define list_for_each_entry_safe(pos, n, head, member)			\
Packit Service d1fe03
	for (pos = list_entry((head)->next, typeof(*pos), member),	\
Packit Service d1fe03
		n = list_entry(pos->member.next, typeof(*pos), member);	\
Packit Service d1fe03
	     &pos->member != (head); 					\
Packit Service d1fe03
	     pos = n, n = list_entry(n->member.next, typeof(*n), member))
Packit Service d1fe03
Packit Service d1fe03
/**
Packit Service d1fe03
 * list_for_each_rcu	-	iterate over an rcu-protected list
Packit Service d1fe03
 * @pos:	the &struct list_head to use as a loop counter.
Packit Service d1fe03
 * @head:	the head for your list.
Packit Service d1fe03
 *
Packit Service d1fe03
 * This list-traversal primitive may safely run concurrently with
Packit Service d1fe03
 * the _rcu list-mutation primitives such as list_add_rcu()
Packit Service d1fe03
 * as long as the traversal is guarded by rcu_read_lock().
Packit Service d1fe03
 */
Packit Service d1fe03
#define list_for_each_rcu(pos, head) \
Packit Service d1fe03
	for (pos = (head)->next, prefetch(pos->next); pos != (head); \
Packit Service d1fe03
        	pos = pos->next, ({ smp_read_barrier_depends(); 0;}), prefetch(pos->next))
Packit Service d1fe03
Packit Service d1fe03
#define __list_for_each_rcu(pos, head) \
Packit Service d1fe03
	for (pos = (head)->next; pos != (head); \
Packit Service d1fe03
        	pos = pos->next, ({ smp_read_barrier_depends(); 0;}))
Packit Service d1fe03
Packit Service d1fe03
/**
Packit Service d1fe03
 * list_for_each_safe_rcu	-	iterate over an rcu-protected list safe
Packit Service d1fe03
 *					against removal of list entry
Packit Service d1fe03
 * @pos:	the &struct list_head to use as a loop counter.
Packit Service d1fe03
 * @n:		another &struct list_head to use as temporary storage
Packit Service d1fe03
 * @head:	the head for your list.
Packit Service d1fe03
 *
Packit Service d1fe03
 * This list-traversal primitive may safely run concurrently with
Packit Service d1fe03
 * the _rcu list-mutation primitives such as list_add_rcu()
Packit Service d1fe03
 * as long as the traversal is guarded by rcu_read_lock().
Packit Service d1fe03
 */
Packit Service d1fe03
#define list_for_each_safe_rcu(pos, n, head) \
Packit Service d1fe03
	for (pos = (head)->next, n = pos->next; pos != (head); \
Packit Service d1fe03
		pos = n, ({ smp_read_barrier_depends(); 0;}), n = pos->next)
Packit Service d1fe03
Packit Service d1fe03
/**
Packit Service d1fe03
 * list_for_each_entry_rcu	-	iterate over rcu list of given type
Packit Service d1fe03
 * @pos:	the type * to use as a loop counter.
Packit Service d1fe03
 * @head:	the head for your list.
Packit Service d1fe03
 * @member:	the name of the list_struct within the struct.
Packit Service d1fe03
 *
Packit Service d1fe03
 * This list-traversal primitive may safely run concurrently with
Packit Service d1fe03
 * the _rcu list-mutation primitives such as list_add_rcu()
Packit Service d1fe03
 * as long as the traversal is guarded by rcu_read_lock().
Packit Service d1fe03
 */
Packit Service d1fe03
#define list_for_each_entry_rcu(pos, head, member)			\
Packit Service d1fe03
	for (pos = list_entry((head)->next, typeof(*pos), member),	\
Packit Service d1fe03
		     prefetch(pos->member.next);			\
Packit Service d1fe03
	     &pos->member != (head); 					\
Packit Service d1fe03
	     pos = list_entry(pos->member.next, typeof(*pos), member),	\
Packit Service d1fe03
		     ({ smp_read_barrier_depends(); 0;}),		\
Packit Service d1fe03
		     prefetch(pos->member.next))
Packit Service d1fe03
Packit Service d1fe03
Packit Service d1fe03
/**
Packit Service d1fe03
 * list_for_each_continue_rcu	-	iterate over an rcu-protected list
Packit Service d1fe03
 *			continuing after existing point.
Packit Service d1fe03
 * @pos:	the &struct list_head to use as a loop counter.
Packit Service d1fe03
 * @head:	the head for your list.
Packit Service d1fe03
 *
Packit Service d1fe03
 * This list-traversal primitive may safely run concurrently with
Packit Service d1fe03
 * the _rcu list-mutation primitives such as list_add_rcu()
Packit Service d1fe03
 * as long as the traversal is guarded by rcu_read_lock().
Packit Service d1fe03
 */
Packit Service d1fe03
#define list_for_each_continue_rcu(pos, head) \
Packit Service d1fe03
	for ((pos) = (pos)->next, prefetch((pos)->next); (pos) != (head); \
Packit Service d1fe03
        	(pos) = (pos)->next, ({ smp_read_barrier_depends(); 0;}), prefetch((pos)->next))
Packit Service d1fe03
Packit Service d1fe03
/*
Packit Service d1fe03
 * Double linked lists with a single pointer list head.
Packit Service d1fe03
 * Mostly useful for hash tables where the two pointer list head is
Packit Service d1fe03
 * too wasteful.
Packit Service d1fe03
 * You lose the ability to access the tail in O(1).
Packit Service d1fe03
 */
Packit Service d1fe03
Packit Service d1fe03
struct hlist_head {
Packit Service d1fe03
	struct hlist_node *first;
Packit Service d1fe03
};
Packit Service d1fe03
Packit Service d1fe03
struct hlist_node {
Packit Service d1fe03
	struct hlist_node *next, **pprev;
Packit Service d1fe03
};
Packit Service d1fe03
Packit Service d1fe03
#define HLIST_HEAD_INIT { .first = NULL }
Packit Service d1fe03
#define HLIST_HEAD(name) struct hlist_head name = {  .first = NULL }
Packit Service d1fe03
#define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL)
Packit Service d1fe03
#define INIT_HLIST_NODE(ptr) ((ptr)->next = NULL, (ptr)->pprev = NULL)
Packit Service d1fe03
Packit Service d1fe03
static inline int hlist_unhashed(const struct hlist_node *h)
Packit Service d1fe03
{
Packit Service d1fe03
	return !h->pprev;
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
static inline int hlist_empty(const struct hlist_head *h)
Packit Service d1fe03
{
Packit Service d1fe03
	return !h->first;
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
static inline void __hlist_del(struct hlist_node *n)
Packit Service d1fe03
{
Packit Service d1fe03
	struct hlist_node *next = n->next;
Packit Service d1fe03
	struct hlist_node **pprev = n->pprev;
Packit Service d1fe03
	*pprev = next;
Packit Service d1fe03
	if (next)
Packit Service d1fe03
		next->pprev = pprev;
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
static inline void hlist_del(struct hlist_node *n)
Packit Service d1fe03
{
Packit Service d1fe03
	__hlist_del(n);
Packit Service d1fe03
	n->next = LIST_POISON1;
Packit Service d1fe03
	n->pprev = LIST_POISON2;
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
/**
Packit Service d1fe03
 * hlist_del_rcu - deletes entry from hash list without re-initialization
Packit Service d1fe03
 * @n: the element to delete from the hash list.
Packit Service d1fe03
 *
Packit Service d1fe03
 * Note: list_unhashed() on entry does not return true after this,
Packit Service d1fe03
 * the entry is in an undefined state. It is useful for RCU based
Packit Service d1fe03
 * lockfree traversal.
Packit Service d1fe03
 *
Packit Service d1fe03
 * In particular, it means that we can not poison the forward
Packit Service d1fe03
 * pointers that may still be used for walking the hash list.
Packit Service d1fe03
 *
Packit Service d1fe03
 * The caller must take whatever precautions are necessary
Packit Service d1fe03
 * (such as holding appropriate locks) to avoid racing
Packit Service d1fe03
 * with another list-mutation primitive, such as hlist_add_head_rcu()
Packit Service d1fe03
 * or hlist_del_rcu(), running on this same list.
Packit Service d1fe03
 * However, it is perfectly legal to run concurrently with
Packit Service d1fe03
 * the _rcu list-traversal primitives, such as
Packit Service d1fe03
 * hlist_for_each_entry().
Packit Service d1fe03
 */
Packit Service d1fe03
static inline void hlist_del_rcu(struct hlist_node *n)
Packit Service d1fe03
{
Packit Service d1fe03
	__hlist_del(n);
Packit Service d1fe03
	n->pprev = LIST_POISON2;
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
static inline void hlist_del_init(struct hlist_node *n)
Packit Service d1fe03
{
Packit Service d1fe03
	if (n->pprev)  {
Packit Service d1fe03
		__hlist_del(n);
Packit Service d1fe03
		INIT_HLIST_NODE(n);
Packit Service d1fe03
	}
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
#define hlist_del_rcu_init hlist_del_init
Packit Service d1fe03
Packit Service d1fe03
static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
Packit Service d1fe03
{
Packit Service d1fe03
	struct hlist_node *first = h->first;
Packit Service d1fe03
	n->next = first;
Packit Service d1fe03
	if (first)
Packit Service d1fe03
		first->pprev = &n->next;
Packit Service d1fe03
	h->first = n;
Packit Service d1fe03
	n->pprev = &h->first;
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
Packit Service d1fe03
/**
Packit Service d1fe03
 * hlist_add_head_rcu - adds the specified element to the specified hlist,
Packit Service d1fe03
 * while permitting racing traversals.
Packit Service d1fe03
 * @n: the element to add to the hash list.
Packit Service d1fe03
 * @h: the list to add to.
Packit Service d1fe03
 *
Packit Service d1fe03
 * The caller must take whatever precautions are necessary
Packit Service d1fe03
 * (such as holding appropriate locks) to avoid racing
Packit Service d1fe03
 * with another list-mutation primitive, such as hlist_add_head_rcu()
Packit Service d1fe03
 * or hlist_del_rcu(), running on this same list.
Packit Service d1fe03
 * However, it is perfectly legal to run concurrently with
Packit Service d1fe03
 * the _rcu list-traversal primitives, such as
Packit Service d1fe03
 * hlist_for_each_entry(), but only if smp_read_barrier_depends()
Packit Service d1fe03
 * is used to prevent memory-consistency problems on Alpha CPUs.
Packit Service d1fe03
 * Regardless of the type of CPU, the list-traversal primitive
Packit Service d1fe03
 * must be guarded by rcu_read_lock().
Packit Service d1fe03
 *
Packit Service d1fe03
 * OK, so why don't we have an hlist_for_each_entry_rcu()???
Packit Service d1fe03
 */
Packit Service d1fe03
static inline void hlist_add_head_rcu(struct hlist_node *n,
Packit Service d1fe03
					struct hlist_head *h)
Packit Service d1fe03
{
Packit Service d1fe03
	struct hlist_node *first = h->first;
Packit Service d1fe03
	n->next = first;
Packit Service d1fe03
	n->pprev = &h->first;
Packit Service d1fe03
	smp_wmb();
Packit Service d1fe03
	if (first)
Packit Service d1fe03
		first->pprev = &n->next;
Packit Service d1fe03
	h->first = n;
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
/* next must be != NULL */
Packit Service d1fe03
static inline void hlist_add_before(struct hlist_node *n,
Packit Service d1fe03
					struct hlist_node *next)
Packit Service d1fe03
{
Packit Service d1fe03
	n->pprev = next->pprev;
Packit Service d1fe03
	n->next = next;
Packit Service d1fe03
	next->pprev = &n->next;
Packit Service d1fe03
	*(n->pprev) = n;
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
static inline void hlist_add_after(struct hlist_node *n,
Packit Service d1fe03
					struct hlist_node *next)
Packit Service d1fe03
{
Packit Service d1fe03
	next->next = n->next;
Packit Service d1fe03
	n->next = next;
Packit Service d1fe03
	next->pprev = &n->next;
Packit Service d1fe03
Packit Service d1fe03
	if(next->next)
Packit Service d1fe03
		next->next->pprev  = &next->next;
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
#define hlist_entry(ptr, type, member) container_of(ptr,type,member)
Packit Service d1fe03
Packit Service d1fe03
#define hlist_for_each(pos, head) \
Packit Service d1fe03
	for (pos = (head)->first; pos && ({ prefetch(pos->next); 1; }); \
Packit Service d1fe03
	     pos = pos->next)
Packit Service d1fe03
Packit Service d1fe03
#define hlist_for_each_safe(pos, n, head) \
Packit Service d1fe03
	for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \
Packit Service d1fe03
	     pos = n)
Packit Service d1fe03
Packit Service d1fe03
/**
Packit Service d1fe03
 * hlist_for_each_entry	- iterate over list of given type
Packit Service d1fe03
 * @tpos:	the type * to use as a loop counter.
Packit Service d1fe03
 * @pos:	the &struct hlist_node to use as a loop counter.
Packit Service d1fe03
 * @head:	the head for your list.
Packit Service d1fe03
 * @member:	the name of the hlist_node within the struct.
Packit Service d1fe03
 */
Packit Service d1fe03
#define hlist_for_each_entry(tpos, pos, head, member)			 \
Packit Service d1fe03
	for (pos = (head)->first;					 \
Packit Service d1fe03
	     pos && ({ prefetch(pos->next); 1;}) &&			 \
Packit Service d1fe03
		({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
Packit Service d1fe03
	     pos = pos->next)
Packit Service d1fe03
Packit Service d1fe03
/**
Packit Service d1fe03
 * hlist_for_each_entry_continue - iterate over a hlist continuing after existing point
Packit Service d1fe03
 * @tpos:	the type * to use as a loop counter.
Packit Service d1fe03
 * @pos:	the &struct hlist_node to use as a loop counter.
Packit Service d1fe03
 * @member:	the name of the hlist_node within the struct.
Packit Service d1fe03
 */
Packit Service d1fe03
#define hlist_for_each_entry_continue(tpos, pos, member)		 \
Packit Service d1fe03
	for (pos = (pos)->next;						 \
Packit Service d1fe03
	     pos && ({ prefetch(pos->next); 1;}) &&			 \
Packit Service d1fe03
		({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
Packit Service d1fe03
	     pos = pos->next)
Packit Service d1fe03
Packit Service d1fe03
/**
Packit Service d1fe03
 * hlist_for_each_entry_from - iterate over a hlist continuing from existing point
Packit Service d1fe03
 * @tpos:	the type * to use as a loop counter.
Packit Service d1fe03
 * @pos:	the &struct hlist_node to use as a loop counter.
Packit Service d1fe03
 * @member:	the name of the hlist_node within the struct.
Packit Service d1fe03
 */
Packit Service d1fe03
#define hlist_for_each_entry_from(tpos, pos, member)			 \
Packit Service d1fe03
	for (; pos && ({ prefetch(pos->next); 1;}) &&			 \
Packit Service d1fe03
		({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
Packit Service d1fe03
	     pos = pos->next)
Packit Service d1fe03
Packit Service d1fe03
/**
Packit Service d1fe03
 * hlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry
Packit Service d1fe03
 * @tpos:	the type * to use as a loop counter.
Packit Service d1fe03
 * @pos:	the &struct hlist_node to use as a loop counter.
Packit Service d1fe03
 * @n:		another &struct hlist_node to use as temporary storage
Packit Service d1fe03
 * @head:	the head for your list.
Packit Service d1fe03
 * @member:	the name of the hlist_node within the struct.
Packit Service d1fe03
 */
Packit Service d1fe03
#define hlist_for_each_entry_safe(tpos, pos, n, head, member) 		 \
Packit Service d1fe03
	for (pos = (head)->first;					 \
Packit Service d1fe03
	     pos && ({ n = pos->next; 1; }) && 				 \
Packit Service d1fe03
		({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
Packit Service d1fe03
	     pos = n)
Packit Service d1fe03
Packit Service d1fe03
/**
Packit Service d1fe03
 * hlist_for_each_entry_rcu - iterate over rcu list of given type
Packit Service d1fe03
 * @pos:	the type * to use as a loop counter.
Packit Service d1fe03
 * @pos:	the &struct hlist_node to use as a loop counter.
Packit Service d1fe03
 * @head:	the head for your list.
Packit Service d1fe03
 * @member:	the name of the hlist_node within the struct.
Packit Service d1fe03
 *
Packit Service d1fe03
 * This list-traversal primitive may safely run concurrently with
Packit Service d1fe03
 * the _rcu list-mutation primitives such as hlist_add_rcu()
Packit Service d1fe03
 * as long as the traversal is guarded by rcu_read_lock().
Packit Service d1fe03
 */
Packit Service d1fe03
#define hlist_for_each_entry_rcu(tpos, pos, head, member)		 \
Packit Service d1fe03
	for (pos = (head)->first;					 \
Packit Service d1fe03
	     pos && ({ prefetch(pos->next); 1;}) &&			 \
Packit Service d1fe03
		({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
Packit Service d1fe03
	     pos = pos->next, ({ smp_read_barrier_depends(); 0; }) )
Packit Service d1fe03
Packit Service d1fe03
#endif