Loading...
Searching...
No Matches
linuxlist.h
Go to the documentation of this file.
#pragma once
#include <stddef.h>
#include <stdbool.h>
#ifndef inline
#define inline __inline__
#endif
static inline void prefetch(const void *x) {;}
#define container_of(ptr, type, member) ({ \
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type, member) );})
#define LLIST_POISON1 ((void *) 0x00100100)
#define LLIST_POISON2 ((void *) 0x00200200)
struct llist_head {
struct llist_head *next, *prev;
};
#define LLIST_HEAD_INIT(name) { &(name), &(name) }
#define LLIST_HEAD(name) \
struct llist_head name = LLIST_HEAD_INIT(name)
#define INIT_LLIST_HEAD(ptr) do { \
(ptr)->next = (ptr); (ptr)->prev = (ptr); \
} while (0)
/*
* Insert a new entry between two known consecutive entries.
*
* This is only for internal llist manipulation where we know
* the prev/next entries already!
*/
static inline void __llist_add(struct llist_head *_new,
struct llist_head *prev,
struct llist_head *next)
{
next->prev = _new;
_new->next = next;
_new->prev = prev;
prev->next = _new;
}
static inline void llist_add(struct llist_head *_new, struct llist_head *head)
{
__llist_add(_new, head, head->next);
}
static inline void llist_add_tail(struct llist_head *_new, struct llist_head *head)
{
__llist_add(_new, head->prev, head);
}
/*
* Delete a llist entry by making the prev/next entries
* point to each other.
*
* This is only for internal llist manipulation where we know
* the prev/next entries already!
*/
static inline void __llist_del(struct llist_head * prev, struct llist_head * next)
{
next->prev = prev;
prev->next = next;
}
static inline void llist_del(struct llist_head *entry)
{
__llist_del(entry->prev, entry->next);
entry->next = (struct llist_head *)LLIST_POISON1;
entry->prev = (struct llist_head *)LLIST_POISON2;
}
static inline void llist_del_init(struct llist_head *entry)
{
__llist_del(entry->prev, entry->next);
INIT_LLIST_HEAD(entry);
}
static inline void llist_move(struct llist_head *llist, struct llist_head *head)
{
__llist_del(llist->prev, llist->next);
llist_add(llist, head);
}
static inline void llist_move_tail(struct llist_head *llist,
struct llist_head *head)
{
__llist_del(llist->prev, llist->next);
llist_add_tail(llist, head);
}
static inline int llist_empty(const struct llist_head *head)
{
return head->next == head;
}
static inline void __llist_splice(struct llist_head *llist,
struct llist_head *head)
{
struct llist_head *first = llist->next;
struct llist_head *last = llist->prev;
struct llist_head *at = head->next;
first->prev = head;
head->next = first;
last->next = at;
at->prev = last;
}
static inline void llist_splice(struct llist_head *llist, struct llist_head *head)
{
if (!llist_empty(llist))
__llist_splice(llist, head);
}
static inline void llist_splice_init(struct llist_head *llist,
struct llist_head *head)
{
if (!llist_empty(llist)) {
__llist_splice(llist, head);
INIT_LLIST_HEAD(llist);
}
}
#define llist_entry(ptr, type, member) \
container_of(ptr, type, member)
#define llist_first_entry(ptr, type, member) \
llist_entry((ptr)->next, type, member)
#define llist_last_entry(ptr, type, member) \
llist_entry((ptr)->prev, type, member)
#define llist_last(head) (head)->prev
#define llist_first_entry_or_null(ptr, type, member) \
(!llist_empty(ptr) ? llist_first_entry(ptr, type, member) : NULL)
#define llist_for_each(pos, head) \
for (pos = (head)->next, prefetch(pos->next); pos != (head); \
pos = pos->next, prefetch(pos->next))
#define __llist_for_each(pos, head) \
for (pos = (head)->next; pos != (head); pos = pos->next)
#define llist_for_each_prev(pos, head) \
for (pos = (head)->prev, prefetch(pos->prev); pos != (head); \
pos = pos->prev, prefetch(pos->prev))
#define llist_for_each_safe(pos, n, head) \
for (pos = (head)->next, n = pos->next; pos != (head); \
pos = n, n = pos->next)
#define llist_for_each_entry(pos, head, member) \
for (pos = llist_entry((head)->next, typeof(*pos), member), \
prefetch(pos->member.next); \
&pos->member != (head); \
pos = llist_entry(pos->member.next, typeof(*pos), member), \
prefetch(pos->member.next))
#define llist_for_each_entry_reverse(pos, head, member) \
for (pos = llist_entry((head)->prev, typeof(*pos), member), \
prefetch(pos->member.prev); \
&pos->member != (head); \
pos = llist_entry(pos->member.prev, typeof(*pos), member), \
prefetch(pos->member.prev))
#define llist_for_each_entry_continue(pos, head, member) \
for (pos = llist_entry(pos->member.next, typeof(*pos), member), \
prefetch(pos->member.next); \
&pos->member != (head); \
pos = llist_entry(pos->member.next, typeof(*pos), member), \
prefetch(pos->member.next))
#define llist_for_each_entry_safe(pos, n, head, member) \
for (pos = llist_entry((head)->next, typeof(*pos), member), \
n = llist_entry(pos->member.next, typeof(*pos), member); \
&pos->member != (head); \
pos = n, n = llist_entry(n->member.next, typeof(*n), member))
#define llist_for_each_rcu(pos, head) \
for (pos = (head)->next, prefetch(pos->next); pos != (head); \
pos = pos->next, ({ smp_read_barrier_depends(); 0;}), prefetch(pos->next))
#define __llist_for_each_rcu(pos, head) \
for (pos = (head)->next; pos != (head); \
pos = pos->next, ({ smp_read_barrier_depends(); 0;}))
#define llist_for_each_safe_rcu(pos, n, head) \
for (pos = (head)->next, n = pos->next; pos != (head); \
pos = n, ({ smp_read_barrier_depends(); 0;}), n = pos->next)
#define llist_for_each_entry_rcu(pos, head, member) \
for (pos = llist_entry((head)->next, typeof(*pos), member), \
prefetch(pos->member.next); \
&pos->member != (head); \
pos = llist_entry(pos->member.next, typeof(*pos), member), \
({ smp_read_barrier_depends(); 0;}), \
prefetch(pos->member.next))
#define llist_for_each_continue_rcu(pos, head) \
for ((pos) = (pos)->next, prefetch((pos)->next); (pos) != (head); \
(pos) = (pos)->next, ({ smp_read_barrier_depends(); 0;}), prefetch((pos)->next))
static inline unsigned int llist_count(const struct llist_head *head)
{
struct llist_head *entry;
unsigned int i = 0;
llist_for_each(entry, head)
i++;
return i;
}
struct hlist_head {
struct hlist_node *first;
};
struct hlist_node {
struct hlist_node *next, **pprev;
};
#define HLIST_HEAD_INIT { .first = NULL }
#define HLIST_HEAD(name) struct hlist_head name = { .first = NULL }
#define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL)
static inline void INIT_HLIST_NODE(struct hlist_node *h)
{
h->next = NULL;
h->pprev = NULL;
}
#define READ_ONCE(x) x
#define WRITE_ONCE(a, b) a = b
static inline int hlist_unhashed(const struct hlist_node *h)
{
return !h->pprev;
}
static inline int hlist_unhashed_lockless(const struct hlist_node *h)
{
return !READ_ONCE(h->pprev);
}
static inline int hlist_empty(const struct hlist_head *h)
{
return !READ_ONCE(h->first);
}
static inline void __hlist_del(struct hlist_node *n)
{
struct hlist_node *next = n->next;
struct hlist_node **pprev = n->pprev;
WRITE_ONCE(*pprev, next);
if (next)
WRITE_ONCE(next->pprev, pprev);
}
static inline void hlist_del(struct hlist_node *n)
{
__hlist_del(n);
n->next = (struct hlist_node *)LLIST_POISON1;
n->pprev = (struct hlist_node **)LLIST_POISON2;
}
static inline void hlist_del_init(struct hlist_node *n)
{
if (!hlist_unhashed(n)) {
__hlist_del(n);
INIT_HLIST_NODE(n);
}
}
static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
{
struct hlist_node *first = h->first;
WRITE_ONCE(n->next, first);
if (first)
WRITE_ONCE(first->pprev, &n->next);
WRITE_ONCE(h->first, n);
WRITE_ONCE(n->pprev, &h->first);
}
static inline void hlist_add_before(struct hlist_node *n,
struct hlist_node *next)
{
WRITE_ONCE(n->pprev, next->pprev);
WRITE_ONCE(n->next, next);
WRITE_ONCE(next->pprev, &n->next);
WRITE_ONCE(*(n->pprev), n);
}
static inline void hlist_add_behind(struct hlist_node *n,
struct hlist_node *prev)
{
WRITE_ONCE(n->next, prev->next);
WRITE_ONCE(prev->next, n);
WRITE_ONCE(n->pprev, &prev->next);
if (n->next)
WRITE_ONCE(n->next->pprev, &n->next);
}
static inline void hlist_add_fake(struct hlist_node *n)
{
n->pprev = &n->next;
}
static inline bool hlist_fake(struct hlist_node *h)
{
return h->pprev == &h->next;
}
static inline bool
hlist_is_singular_node(struct hlist_node *n, struct hlist_head *h)
{
return !n->next && n->pprev == &h->first;
}
static inline void hlist_move_list(struct hlist_head *old,
struct hlist_head *_new)
{
_new->first = old->first;
if (_new->first)
_new->first->pprev = &_new->first;
old->first = NULL;
}
#define hlist_entry(ptr, type, member) container_of(ptr,type,member)
#define hlist_for_each(pos, head) \
for (pos = (head)->first; pos ; pos = pos->next)
#define hlist_for_each_safe(pos, n, head) \
for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \
pos = n)
#define hlist_entry_safe(ptr, type, member) \
({ typeof(ptr) ____ptr = (ptr); \
____ptr ? hlist_entry(____ptr, type, member) : NULL; \
})
#define hlist_for_each_entry(pos, head, member) \
for (pos = hlist_entry_safe((head)->first, typeof(*(pos)), member);\
pos; \
pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member))
#define hlist_for_each_entry_continue(pos, member) \
for (pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member);\
pos; \
pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member))
#define hlist_for_each_entry_from(pos, member) \
for (; pos; \
pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member))
#define hlist_for_each_entry_safe(pos, n, head, member) \
for (pos = hlist_entry_safe((head)->first, typeof(*pos), member);\
pos && ({ n = pos->member.next; 1; }); \
pos = hlist_entry_safe(n, typeof(*pos), member))
n
write Write running configuration to or terminal n Write configuration to the copy running config startup Copy configuration n Copy running config to n Copy running config to startup write Write running configuration to or terminal n Write to terminal n
llist_count
static unsigned int llist_count(const struct llist_head *head)
Count number of llist items by iterating.
Definition linuxlist.h:393
LLIST_POISON1
#define LLIST_POISON1
These are non-NULL pointers that will result in page faults under normal circumstances,...
Definition linuxlist.h:42
LLIST_POISON2
#define LLIST_POISON2
Definition linuxlist.h:43
__hlist_del
static void __hlist_del(struct hlist_node *n)
Definition linuxlist.h:465
hlist_add_behind
static void hlist_add_behind(struct hlist_node *n, struct hlist_node *prev)
add a new entry after the one specified
Definition linuxlist.h:535
hlist_add_before
static void hlist_add_before(struct hlist_node *n, struct hlist_node *next)
add a new entry before the one specified.
Definition linuxlist.h:522
__llist_add
static void __llist_add(struct llist_head *_new, struct llist_head *prev, struct llist_head *next)
Definition linuxlist.h:75
llist_splice
static void llist_splice(struct llist_head *llist, struct llist_head *head)
Join two linked lists.
Definition linuxlist.h:192
hlist_del_init
static void hlist_del_init(struct hlist_node *n)
Delete the specified hlist_node from its list and initialize.
Definition linuxlist.h:493
hlist_fake
static bool hlist_fake(struct hlist_node *h)
Is this node a fake hlist?.
Definition linuxlist.h:561
llist_del_init
static void llist_del_init(struct llist_head *entry)
Delete a single entry from a linked list and reinitialize it.
Definition linuxlist.h:138
llist_move_tail
static void llist_move_tail(struct llist_head *llist, struct llist_head *head)
Delete from one llist and add as another's tail.
Definition linuxlist.h:158
INIT_HLIST_NODE
static void INIT_HLIST_NODE(struct hlist_node *h)
Definition linuxlist.h:421
llist_splice_init
static void llist_splice_init(struct llist_head *llist, struct llist_head *head)
Join two llists and reinitialise the emptied llist.
Definition linuxlist.h:204
llist_add
static void llist_add(struct llist_head *_new, struct llist_head *head)
Add a new entry into a linked list (at head).
Definition linuxlist.h:92
hlist_is_singular_node
static bool hlist_is_singular_node(struct hlist_node *n, struct hlist_head *h)
is node the only element of the specified hlist?.
Definition linuxlist.h:574
hlist_add_fake
static void hlist_add_fake(struct hlist_node *n)
create a fake hlist consisting of a single headless node.
Definition linuxlist.h:553
hlist_unhashed
static int hlist_unhashed(const struct hlist_node *h)
Has node been removed from list and reinitialized?.
Definition linuxlist.h:438
WRITE_ONCE
#define WRITE_ONCE(a, b)
Definition linuxlist.h:428
__llist_splice
static void __llist_splice(struct llist_head *llist, struct llist_head *head)
Definition linuxlist.h:174
READ_ONCE
#define READ_ONCE(x)
Definition linuxlist.h:427
hlist_del
static void hlist_del(struct hlist_node *n)
Delete the specified hlist_node from its list.
Definition linuxlist.h:481
llist_empty
static int llist_empty(const struct llist_head *head)
Test whether a linked list is empty.
Definition linuxlist.h:169
llist_move
static void llist_move(struct llist_head *llist, struct llist_head *head)
Delete from one llist and add as another's head.
Definition linuxlist.h:148
llist_del
static void llist_del(struct llist_head *entry)
Delete a single entry from a linked list.
Definition linuxlist.h:128
hlist_add_head
static void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
add a new entry at the beginning of the hlist.
Definition linuxlist.h:508
llist_for_each
#define llist_for_each(pos, head)
Iterate over a linked list.
Definition linuxlist.h:261
prefetch
static void prefetch(const void *x)
Definition linuxlist.h:25
hlist_unhashed_lockless
static int hlist_unhashed_lockless(const struct hlist_node *h)
Version of hlist_unhashed for lockless use.
Definition linuxlist.h:451
hlist_move_list
static void hlist_move_list(struct hlist_head *old, struct hlist_head *_new)
Move an hlist.
Definition linuxlist.h:586
llist_add_tail
static void llist_add_tail(struct llist_head *_new, struct llist_head *head)
Add a new entry into a linked list (at tail).
Definition linuxlist.h:104
INIT_LLIST_HEAD
#define INIT_LLIST_HEAD(ptr)
Initialize a llist_head to point back to itself.
Definition linuxlist.h:65
hlist_empty
static int hlist_empty(const struct hlist_head *h)
Is the specified hlist_head structure an empty hlist?.
Definition linuxlist.h:460
__llist_del
static void __llist_del(struct llist_head *prev, struct llist_head *next)
Definition linuxlist.h:116
h
struct gad_raw_head h
x
uint32_t x
Definition jhash.h:0
hlist_head
Double linked lists with a single pointer list head.
Definition linuxlist.h:410
hlist_head::first
struct hlist_node * first
Definition linuxlist.h:411
hlist_node
Definition linuxlist.h:414
hlist_node::pprev
struct hlist_node ** pprev
Definition linuxlist.h:415
hlist_node::next
struct hlist_node * next
Definition linuxlist.h:415
llist_head
(double) linked list header structure
Definition linuxlist.h:46
llist_head::next
struct llist_head * next
Pointer to next and previous item.
Definition linuxlist.h:48
llist_head::prev
struct llist_head * prev
Definition linuxlist.h:48