|
|
|
@@ -1,5 +1,21 @@
|
|
|
|
#pragma once
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*! \defgroup linuxlist Simple doubly linked list implementation
|
|
|
|
|
|
|
|
* @{
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
|
|
* \file linuxlist.h
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* \brief Simple doubly linked list implementation.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* Some of the internal functions ("__xxx") are useful when
|
|
|
|
|
|
|
|
* manipulating whole llists rather than single entries, as
|
|
|
|
|
|
|
|
* sometimes we already know the next/prev entries and we can
|
|
|
|
|
|
|
|
* generate better code by using them directly rather than
|
|
|
|
|
|
|
|
* using the generic single-entry routines.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef inline
|
|
|
|
#ifndef inline
|
|
|
|
@@ -8,20 +24,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
static inline void prefetch(const void *x) {;}
|
|
|
|
static inline void prefetch(const void *x) {;}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/*! \brief cast a member of a structure out to the containing structure
|
|
|
|
* container_of - cast a member of a structure out to the containing structure
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @ptr: the pointer to the member.
|
|
|
|
|
|
|
|
* @type: the type of the container struct this is embedded in.
|
|
|
|
|
|
|
|
* @member: the name of the member within the struct.
|
|
|
|
|
|
|
|
*
|
|
|
|
*
|
|
|
|
|
|
|
|
* \param[in] ptr the pointer to the member.
|
|
|
|
|
|
|
|
* \param[in] type the type of the container struct this is embedded in.
|
|
|
|
|
|
|
|
* \param[in] member the name of the member within the struct.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
#define container_of(ptr, type, member) ({ \
|
|
|
|
#define container_of(ptr, type, member) ({ \
|
|
|
|
const typeof( ((type *)0)->member ) *__mptr = (typeof( ((type *)0)->member ) *)(ptr); \
|
|
|
|
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
|
|
|
|
(type *)( (char *)__mptr - offsetof(type, member) );})
|
|
|
|
(type *)( (char *)__mptr - offsetof(type, member) );})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*!
|
|
|
|
* These are non-NULL pointers that will result in page faults
|
|
|
|
* These are non-NULL pointers that will result in page faults
|
|
|
|
* under normal circumstances, used to verify that nobody uses
|
|
|
|
* under normal circumstances, used to verify that nobody uses
|
|
|
|
* non-initialized llist entries.
|
|
|
|
* non-initialized llist entries.
|
|
|
|
@@ -29,31 +43,28 @@ static inline void prefetch(const void *x) {;}
|
|
|
|
#define LLIST_POISON1 ((void *) 0x00100100)
|
|
|
|
#define LLIST_POISON1 ((void *) 0x00100100)
|
|
|
|
#define LLIST_POISON2 ((void *) 0x00200200)
|
|
|
|
#define LLIST_POISON2 ((void *) 0x00200200)
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*! \brief (double) linked list header structure */
|
|
|
|
* Simple doubly linked llist implementation.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* Some of the internal functions ("__xxx") are useful when
|
|
|
|
|
|
|
|
* manipulating whole llists rather than single entries, as
|
|
|
|
|
|
|
|
* sometimes we already know the next/prev entries and we can
|
|
|
|
|
|
|
|
* generate better code by using them directly rather than
|
|
|
|
|
|
|
|
* using the generic single-entry routines.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct llist_head {
|
|
|
|
struct llist_head {
|
|
|
|
|
|
|
|
/*! \brief Pointer to next and previous item */
|
|
|
|
struct llist_head *next, *prev;
|
|
|
|
struct llist_head *next, *prev;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#define LLIST_HEAD_INIT(name) { &(name), &(name) }
|
|
|
|
#define LLIST_HEAD_INIT(name) { &(name), &(name) }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*! \brief define a statically-initialized \ref llist_head
|
|
|
|
|
|
|
|
* \param[in] name Variable name
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* This is a helper macro that will define a named variable of type
|
|
|
|
|
|
|
|
* \ref llist_head and initialize it */
|
|
|
|
#define LLIST_HEAD(name) \
|
|
|
|
#define LLIST_HEAD(name) \
|
|
|
|
struct llist_head name = LLIST_HEAD_INIT(name)
|
|
|
|
struct llist_head name = LLIST_HEAD_INIT(name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*! \brief initialize a \ref llist_head to point back to self */
|
|
|
|
#define INIT_LLIST_HEAD(ptr) do { \
|
|
|
|
#define INIT_LLIST_HEAD(ptr) do { \
|
|
|
|
(ptr)->next = (ptr); (ptr)->prev = (ptr); \
|
|
|
|
(ptr)->next = (ptr); (ptr)->prev = (ptr); \
|
|
|
|
} while (0)
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*! \brief Insert a new entry between two known consecutive entries.
|
|
|
|
* Insert a new entry between two known consecutive entries.
|
|
|
|
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* This is only for internal llist manipulation where we know
|
|
|
|
* This is only for internal llist manipulation where we know
|
|
|
|
* the prev/next entries already!
|
|
|
|
* the prev/next entries already!
|
|
|
|
@@ -68,10 +79,9 @@ static inline void __llist_add(struct llist_head *_new,
|
|
|
|
prev->next = _new;
|
|
|
|
prev->next = _new;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/*! \brief add a new entry into a linked list (at head)
|
|
|
|
* llist_add - add a new entry
|
|
|
|
* \param _new New entry to be added
|
|
|
|
* @new: new entry to be added
|
|
|
|
* \param head \ref llist_head to add it after
|
|
|
|
* @head: llist head to add it after
|
|
|
|
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Insert a new entry after the specified head.
|
|
|
|
* Insert a new entry after the specified head.
|
|
|
|
* This is good for implementing stacks.
|
|
|
|
* This is good for implementing stacks.
|
|
|
|
@@ -81,10 +91,9 @@ static inline void llist_add(struct llist_head *_new, struct llist_head *head)
|
|
|
|
__llist_add(_new, head, head->next);
|
|
|
|
__llist_add(_new, head, head->next);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/*! \brief add a new entry into a linked list (at tail)
|
|
|
|
* llist_add_tail - add a new entry
|
|
|
|
* \param _new New entry to be added
|
|
|
|
* @new: new entry to be added
|
|
|
|
* \param head Head of linked list to whose tail we shall add \a _new
|
|
|
|
* @head: llist head to add it before
|
|
|
|
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Insert a new entry before the specified head.
|
|
|
|
* Insert a new entry before the specified head.
|
|
|
|
* This is useful for implementing queues.
|
|
|
|
* This is useful for implementing queues.
|
|
|
|
@@ -107,9 +116,9 @@ static inline void __llist_del(struct llist_head * prev, struct llist_head * nex
|
|
|
|
prev->next = next;
|
|
|
|
prev->next = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/*! \brief Delete entry from linked list
|
|
|
|
* llist_del - deletes entry from llist.
|
|
|
|
* \param entry The element to delete from the llist
|
|
|
|
* @entry: the element to delete from the llist.
|
|
|
|
*
|
|
|
|
* Note: llist_empty on entry does not return true after this, the entry is
|
|
|
|
* Note: llist_empty on entry does not return true after this, the entry is
|
|
|
|
* in an undefined state.
|
|
|
|
* in an undefined state.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@@ -120,9 +129,8 @@ static inline void llist_del(struct llist_head *entry)
|
|
|
|
entry->prev = (struct llist_head *)LLIST_POISON2;
|
|
|
|
entry->prev = (struct llist_head *)LLIST_POISON2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/*! \brief Delete entry from linked list and reinitialize it
|
|
|
|
* llist_del_init - deletes entry from llist and reinitialize it.
|
|
|
|
* \param entry The element to delete from the list
|
|
|
|
* @entry: the element to delete from the llist.
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
static inline void llist_del_init(struct llist_head *entry)
|
|
|
|
static inline void llist_del_init(struct llist_head *entry)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@@ -130,10 +138,9 @@ static inline void llist_del_init(struct llist_head *entry)
|
|
|
|
INIT_LLIST_HEAD(entry);
|
|
|
|
INIT_LLIST_HEAD(entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/*! \brief Delete from one llist and add as another's head
|
|
|
|
* llist_move - delete from one llist and add as another's head
|
|
|
|
* \param llist The entry to move
|
|
|
|
* @llist: the entry to move
|
|
|
|
* \param head The head that will precede our entry
|
|
|
|
* @head: the head that will precede our entry
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
static inline void llist_move(struct llist_head *llist, struct llist_head *head)
|
|
|
|
static inline void llist_move(struct llist_head *llist, struct llist_head *head)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@@ -141,10 +148,9 @@ static inline void llist_move(struct llist_head *llist, struct llist_head *head)
|
|
|
|
llist_add(llist, head);
|
|
|
|
llist_add(llist, head);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/*! \brief Delete from one llist and add as another's tail
|
|
|
|
* llist_move_tail - delete from one llist and add as another's tail
|
|
|
|
* \param llist The entry to move
|
|
|
|
* @llist: the entry to move
|
|
|
|
* \param head The head that will follow our entry
|
|
|
|
* @head: the head that will follow our entry
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
static inline void llist_move_tail(struct llist_head *llist,
|
|
|
|
static inline void llist_move_tail(struct llist_head *llist,
|
|
|
|
struct llist_head *head)
|
|
|
|
struct llist_head *head)
|
|
|
|
@@ -153,9 +159,9 @@ static inline void llist_move_tail(struct llist_head *llist,
|
|
|
|
llist_add_tail(llist, head);
|
|
|
|
llist_add_tail(llist, head);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/*! \brief Test whether a linked list is empty
|
|
|
|
* llist_empty - tests whether a llist is empty
|
|
|
|
* \param[in] head The llist to test.
|
|
|
|
* @head: the llist to test.
|
|
|
|
* \returns 1 if the list is empty, 0 otherwise
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
static inline int llist_empty(const struct llist_head *head)
|
|
|
|
static inline int llist_empty(const struct llist_head *head)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@@ -176,10 +182,9 @@ static inline void __llist_splice(struct llist_head *llist,
|
|
|
|
at->prev = last;
|
|
|
|
at->prev = last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/*! \brief Join two llists
|
|
|
|
* llist_splice - join two llists
|
|
|
|
* \param llist The new linked list to add
|
|
|
|
* @llist: the new llist to add.
|
|
|
|
* \param head The place to add \a llist in the other list
|
|
|
|
* @head: the place to add it in the first llist.
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
static inline void llist_splice(struct llist_head *llist, struct llist_head *head)
|
|
|
|
static inline void llist_splice(struct llist_head *llist, struct llist_head *head)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@@ -187,10 +192,9 @@ static inline void llist_splice(struct llist_head *llist, struct llist_head *hea
|
|
|
|
__llist_splice(llist, head);
|
|
|
|
__llist_splice(llist, head);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/*! \brief join two llists and reinitialise the emptied llist.
|
|
|
|
* llist_splice_init - join two llists and reinitialise the emptied llist.
|
|
|
|
* \param llist The new linked list to add.
|
|
|
|
* @llist: the new llist to add.
|
|
|
|
* \param head The place to add it in the first llist.
|
|
|
|
* @head: the place to add it in the first llist.
|
|
|
|
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* The llist at @llist is reinitialised
|
|
|
|
* The llist at @llist is reinitialised
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@@ -203,28 +207,25 @@ static inline void llist_splice_init(struct llist_head *llist,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/*! \brief Get the struct containing this list entry
|
|
|
|
* llist_entry - get the struct for this entry
|
|
|
|
* \param ptr The \ref llist_head pointer
|
|
|
|
* @ptr: the &struct llist_head pointer.
|
|
|
|
* \param type The type of the struct this is embedded in
|
|
|
|
* @type: the type of the struct this is embedded in.
|
|
|
|
* \param @member The name of the \ref llist_head within the struct
|
|
|
|
* @member: the name of the llist_struct within the struct.
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
#define llist_entry(ptr, type, member) \
|
|
|
|
#define llist_entry(ptr, type, member) \
|
|
|
|
container_of(ptr, type, member)
|
|
|
|
container_of(ptr, type, member)
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/*! \brief Iterate over a linked list
|
|
|
|
* llist_for_each - iterate over a llist
|
|
|
|
* \param pos The \ref llist_head to use as a loop counter
|
|
|
|
* @pos: the &struct llist_head to use as a loop counter.
|
|
|
|
* \param head The head of the list over which to iterate
|
|
|
|
* @head: the head for your llist.
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
#define llist_for_each(pos, head) \
|
|
|
|
#define llist_for_each(pos, head) \
|
|
|
|
for (pos = (head)->next, prefetch(pos->next); pos != (head); \
|
|
|
|
for (pos = (head)->next, prefetch(pos->next); pos != (head); \
|
|
|
|
pos = pos->next, prefetch(pos->next))
|
|
|
|
pos = pos->next, prefetch(pos->next))
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/*! \brief Iterate over a llist (no prefetch)
|
|
|
|
* __llist_for_each - iterate over a llist
|
|
|
|
* \param pos The \ref llist_head to use as a loop counter
|
|
|
|
* @pos: the &struct llist_head to use as a loop counter.
|
|
|
|
* \param head The head of the list over which to iterate
|
|
|
|
* @head: the head for your llist.
|
|
|
|
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* This variant differs from llist_for_each() in that it's the
|
|
|
|
* This variant differs from llist_for_each() in that it's the
|
|
|
|
* simplest possible llist iteration code, no prefetching is done.
|
|
|
|
* simplest possible llist iteration code, no prefetching is done.
|
|
|
|
@@ -234,30 +235,27 @@ static inline void llist_splice_init(struct llist_head *llist,
|
|
|
|
#define __llist_for_each(pos, head) \
|
|
|
|
#define __llist_for_each(pos, head) \
|
|
|
|
for (pos = (head)->next; pos != (head); pos = pos->next)
|
|
|
|
for (pos = (head)->next; pos != (head); pos = pos->next)
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/*! \brief Iterate over a llist backwards
|
|
|
|
* llist_for_each_prev - iterate over a llist backwards
|
|
|
|
* \param pos The \ref llist_head to use as a loop counter
|
|
|
|
* @pos: the &struct llist_head to use as a loop counter.
|
|
|
|
* \param head The head of the list over which to iterate
|
|
|
|
* @head: the head for your llist.
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
#define llist_for_each_prev(pos, head) \
|
|
|
|
#define llist_for_each_prev(pos, head) \
|
|
|
|
for (pos = (head)->prev, prefetch(pos->prev); pos != (head); \
|
|
|
|
for (pos = (head)->prev, prefetch(pos->prev); pos != (head); \
|
|
|
|
pos = pos->prev, prefetch(pos->prev))
|
|
|
|
pos = pos->prev, prefetch(pos->prev))
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/*! \brief Iterate over a list; safe against removal of llist entry
|
|
|
|
* llist_for_each_safe - iterate over a llist safe against removal of llist entry
|
|
|
|
* \param pos The \ref llist_head to use as a loop counter
|
|
|
|
* @pos: the &struct llist_head to use as a loop counter.
|
|
|
|
* \param n Another \ref llist_head to use as temporary storage
|
|
|
|
* @n: another &struct llist_head to use as temporary storage
|
|
|
|
* \param head The head of the list over which to iterate
|
|
|
|
* @head: the head for your llist.
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
#define llist_for_each_safe(pos, n, head) \
|
|
|
|
#define llist_for_each_safe(pos, n, head) \
|
|
|
|
for (pos = (head)->next, n = pos->next; pos != (head); \
|
|
|
|
for (pos = (head)->next, n = pos->next; pos != (head); \
|
|
|
|
pos = n, n = pos->next)
|
|
|
|
pos = n, n = pos->next)
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/*! \brief Iterate over llist of given type
|
|
|
|
* llist_for_each_entry - iterate over llist of given type
|
|
|
|
* \param pos The 'type *' to use as a loop counter
|
|
|
|
* @pos: the type * to use as a loop counter.
|
|
|
|
* \param head The head of the list over which to iterate
|
|
|
|
* @head: the head for your llist.
|
|
|
|
* \param member The name of the \ref llist_head within struct \a pos
|
|
|
|
* @member: the name of the llist_struct within the struct.
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
#define llist_for_each_entry(pos, head, member) \
|
|
|
|
#define llist_for_each_entry(pos, head, member) \
|
|
|
|
for (pos = llist_entry((head)->next, typeof(*pos), member), \
|
|
|
|
for (pos = llist_entry((head)->next, typeof(*pos), member), \
|
|
|
|
@@ -266,11 +264,10 @@ static inline void llist_splice_init(struct llist_head *llist,
|
|
|
|
pos = llist_entry(pos->member.next, typeof(*pos), member), \
|
|
|
|
pos = llist_entry(pos->member.next, typeof(*pos), member), \
|
|
|
|
prefetch(pos->member.next))
|
|
|
|
prefetch(pos->member.next))
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/*! \brief Iterate backwards over llist of given type.
|
|
|
|
* llist_for_each_entry_reverse - iterate backwards over llist of given type.
|
|
|
|
* \param pos The 'type *' to use as a loop counter
|
|
|
|
* @pos: the type * to use as a loop counter.
|
|
|
|
* \param head The head of the list over which to iterate
|
|
|
|
* @head: the head for your llist.
|
|
|
|
* \param member The name of the \ref llist_head within struct \a pos
|
|
|
|
* @member: the name of the llist_struct within the struct.
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
#define llist_for_each_entry_reverse(pos, head, member) \
|
|
|
|
#define llist_for_each_entry_reverse(pos, head, member) \
|
|
|
|
for (pos = llist_entry((head)->prev, typeof(*pos), member), \
|
|
|
|
for (pos = llist_entry((head)->prev, typeof(*pos), member), \
|
|
|
|
@@ -279,12 +276,11 @@ static inline void llist_splice_init(struct llist_head *llist,
|
|
|
|
pos = llist_entry(pos->member.prev, typeof(*pos), member), \
|
|
|
|
pos = llist_entry(pos->member.prev, typeof(*pos), member), \
|
|
|
|
prefetch(pos->member.prev))
|
|
|
|
prefetch(pos->member.prev))
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/*! \brief iterate over llist of given type continuing after existing
|
|
|
|
* llist_for_each_entry_continue - iterate over llist of given type
|
|
|
|
* point
|
|
|
|
* continuing after existing point
|
|
|
|
* \param pos The 'type *' to use as a loop counter
|
|
|
|
* @pos: the type * to use as a loop counter.
|
|
|
|
* \param head The head of the list over which to iterate
|
|
|
|
* @head: the head for your llist.
|
|
|
|
* \param member The name of the \ref llist_head within struct \a pos
|
|
|
|
* @member: the name of the llist_struct within the struct.
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
#define llist_for_each_entry_continue(pos, head, member) \
|
|
|
|
#define llist_for_each_entry_continue(pos, head, member) \
|
|
|
|
for (pos = llist_entry(pos->member.next, typeof(*pos), member), \
|
|
|
|
for (pos = llist_entry(pos->member.next, typeof(*pos), member), \
|
|
|
|
@@ -293,13 +289,12 @@ static inline void llist_splice_init(struct llist_head *llist,
|
|
|
|
pos = llist_entry(pos->member.next, typeof(*pos), member), \
|
|
|
|
pos = llist_entry(pos->member.next, typeof(*pos), member), \
|
|
|
|
prefetch(pos->member.next))
|
|
|
|
prefetch(pos->member.next))
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/*! \brief iterate over llist of given type, safe against removal of
|
|
|
|
* llist_for_each_entry_safe - iterate over llist of given type, safe against
|
|
|
|
* non-consecutive(!) llist entries
|
|
|
|
* removal of non-consecutive(!) llist entries
|
|
|
|
* \param pos The 'type *' to use as a loop counter
|
|
|
|
* @pos: the type * to use as a loop counter.
|
|
|
|
* \param n Another type * to use as temporary storage
|
|
|
|
* @n: another type * to use as temporary storage
|
|
|
|
* \param head The head of the list over which to iterate
|
|
|
|
* @head: the head for your llist.
|
|
|
|
* \param member The name of the \ref llist_head within struct \a pos
|
|
|
|
* @member: the name of the llist_struct within the struct.
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
#define llist_for_each_entry_safe(pos, n, head, member) \
|
|
|
|
#define llist_for_each_entry_safe(pos, n, head, member) \
|
|
|
|
for (pos = llist_entry((head)->next, typeof(*pos), member), \
|
|
|
|
for (pos = llist_entry((head)->next, typeof(*pos), member), \
|
|
|
|
@@ -355,3 +350,23 @@ static inline void llist_splice_init(struct llist_head *llist,
|
|
|
|
#define llist_for_each_continue_rcu(pos, head) \
|
|
|
|
#define llist_for_each_continue_rcu(pos, head) \
|
|
|
|
for ((pos) = (pos)->next, prefetch((pos)->next); (pos) != (head); \
|
|
|
|
for ((pos) = (pos)->next, prefetch((pos)->next); (pos) != (head); \
|
|
|
|
(pos) = (pos)->next, ({ smp_read_barrier_depends(); 0;}), prefetch((pos)->next))
|
|
|
|
(pos) = (pos)->next, ({ smp_read_barrier_depends(); 0;}), prefetch((pos)->next))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*! \brief count nr of llist items by iterating.
|
|
|
|
|
|
|
|
* \param head The llist head to count items of.
|
|
|
|
|
|
|
|
* \returns Number of items.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* This function is not efficient, mostly useful for small lists and non time
|
|
|
|
|
|
|
|
* critical cases like unit tests.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
static inline unsigned int llist_count(struct llist_head *head)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
struct llist_head *entry;
|
|
|
|
|
|
|
|
unsigned int i = 0;
|
|
|
|
|
|
|
|
llist_for_each(entry, head)
|
|
|
|
|
|
|
|
i++;
|
|
|
|
|
|
|
|
return i;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
|
|
* }@
|
|
|
|
|
|
|
|
*/
|