\doxysection{include/osmocom/core/linuxlist.h File Reference}
\label{linuxlist_8h}\index{include/osmocom/core/linuxlist.h@{include/osmocom/core/linuxlist.h}}


Simple doubly linked list implementation.  


{\ttfamily \#include $<$stddef.\+h$>$}\newline
{\ttfamily \#include $<$stdbool.\+h$>$}\newline
\doxysubsection*{Data Structures}
\begin{DoxyCompactItemize}
\item 
struct \textbf{ llist\+\_\+head}
\begin{DoxyCompactList}\small\item\em (double) linked list header structure \end{DoxyCompactList}\item 
struct \textbf{ hlist\+\_\+head}
\begin{DoxyCompactList}\small\item\em Double linked lists with a single pointer list head. \end{DoxyCompactList}\item 
struct \textbf{ hlist\+\_\+node}
\end{DoxyCompactItemize}
\doxysubsection*{Macros}
\begin{DoxyCompactItemize}
\item 
\#define \textbf{ inline}~\+\_\+\+\_\+inline\+\_\+\+\_\+
\item 
\#define \textbf{ container\+\_\+of}(ptr,  \textbf{ type},  member)
\begin{DoxyCompactList}\small\item\em Cast a member of a structure out to the containing structure. \end{DoxyCompactList}\item 
\#define \textbf{ LLIST\+\_\+\+POISON1}~((void $\ast$) 0x00100100)
\begin{DoxyCompactList}\small\item\em These are non-\/\+NULL pointers that will result in page faults under normal circumstances, used to verify that nobody uses non-\/initialized llist entries. \end{DoxyCompactList}\item 
\#define \textbf{ LLIST\+\_\+\+POISON2}~((void $\ast$) 0x00200200)
\item 
\#define \textbf{ LLIST\+\_\+\+HEAD\+\_\+\+INIT}(\textbf{ name})~\{ \&(\textbf{ name}), \&(\textbf{ name}) \}
\begin{DoxyCompactList}\small\item\em Define a new \doxyref{llist\+\_\+head}{p.}{structllist__head} pointing to a given \doxyref{llist\+\_\+head}{p.}{structllist__head}. \end{DoxyCompactList}\item 
\#define \textbf{ LLIST\+\_\+\+HEAD}(\textbf{ name})~ struct \textbf{ llist\+\_\+head} \textbf{ name} = \textbf{ LLIST\+\_\+\+HEAD\+\_\+\+INIT}(\textbf{ name})
\begin{DoxyCompactList}\small\item\em Define a statically-\/initialized variable of type \doxyref{llist\+\_\+head}{p.}{structllist__head}. \end{DoxyCompactList}\item 
\#define \textbf{ INIT\+\_\+\+LLIST\+\_\+\+HEAD}(ptr)
\begin{DoxyCompactList}\small\item\em Initialize a \doxyref{llist\+\_\+head}{p.}{structllist__head} to point back to itself. \end{DoxyCompactList}\item 
\#define \textbf{ llist\+\_\+entry}(ptr,  \textbf{ type},  member)~ \textbf{ container\+\_\+of}(ptr, \textbf{ type}, member)
\begin{DoxyCompactList}\small\item\em Get the struct containing this list entry. \end{DoxyCompactList}\item 
\#define \textbf{ llist\+\_\+first\+\_\+entry}(ptr,  \textbf{ type},  member)~ \textbf{ llist\+\_\+entry}((ptr)-\/$>$next, \textbf{ type}, member)
\begin{DoxyCompactList}\small\item\em Get the first element from a linked list. \end{DoxyCompactList}\item 
\#define \textbf{ llist\+\_\+last\+\_\+entry}(ptr,  \textbf{ type},  member)~ \textbf{ llist\+\_\+entry}((ptr)-\/$>$prev, \textbf{ type}, member)
\begin{DoxyCompactList}\small\item\em Get the last element from a list. \end{DoxyCompactList}\item 
\#define \textbf{ llist\+\_\+last}(head)~(head)-\/$>$prev
\begin{DoxyCompactList}\small\item\em Return the last element of the list. \end{DoxyCompactList}\item 
\#define \textbf{ llist\+\_\+first\+\_\+entry\+\_\+or\+\_\+null}(ptr,  \textbf{ type},  member)~ (!\textbf{ llist\+\_\+empty}(ptr) ? \textbf{ llist\+\_\+first\+\_\+entry}(ptr, \textbf{ type}, member) \+: NULL)
\begin{DoxyCompactList}\small\item\em Get the first element from a list, or NULL. \end{DoxyCompactList}\item 
\#define \textbf{ llist\+\_\+for\+\_\+each}(pos,  head)
\begin{DoxyCompactList}\small\item\em Iterate over a linked list. \end{DoxyCompactList}\item 
\#define \textbf{ \+\_\+\+\_\+llist\+\_\+for\+\_\+each}(pos,  head)~ \textbf{ for} (pos = (head)-\/$>$next; pos != (head); pos = pos-\/$>$next)
\begin{DoxyCompactList}\small\item\em Iterate over a linked list (no prefetch). \end{DoxyCompactList}\item 
\#define \textbf{ llist\+\_\+for\+\_\+each\+\_\+prev}(pos,  head)
\begin{DoxyCompactList}\small\item\em Iterate over a linked list backwards. \end{DoxyCompactList}\item 
\#define \textbf{ llist\+\_\+for\+\_\+each\+\_\+safe}(pos,  \textbf{ n},  head)
\begin{DoxyCompactList}\small\item\em Iterate over a linked list, safe against removal of llist entry. \end{DoxyCompactList}\item 
\#define \textbf{ llist\+\_\+for\+\_\+each\+\_\+entry}(pos,  head,  member)
\begin{DoxyCompactList}\small\item\em Iterate over a linked list of a given type. \end{DoxyCompactList}\item 
\#define \textbf{ llist\+\_\+for\+\_\+each\+\_\+entry\+\_\+reverse}(pos,  head,  member)
\begin{DoxyCompactList}\small\item\em Iterate backwards over a linked list of a given type. \end{DoxyCompactList}\item 
\#define \textbf{ llist\+\_\+for\+\_\+each\+\_\+entry\+\_\+continue}(pos,  head,  member)
\begin{DoxyCompactList}\small\item\em Iterate over a linked list of a given type, continuing after an existing point. \end{DoxyCompactList}\item 
\#define \textbf{ llist\+\_\+for\+\_\+each\+\_\+entry\+\_\+safe}(pos,  \textbf{ n},  head,  member)
\begin{DoxyCompactList}\small\item\em Iterate over llist of given type, safe against removal of llist entry. \end{DoxyCompactList}\item 
\#define \textbf{ llist\+\_\+for\+\_\+each\+\_\+rcu}(pos,  head)
\begin{DoxyCompactList}\small\item\em Iterate over an rcu-\/protected llist. \end{DoxyCompactList}\item 
\#define \textbf{ \+\_\+\+\_\+llist\+\_\+for\+\_\+each\+\_\+rcu}(pos,  head)
\item 
\#define \textbf{ llist\+\_\+for\+\_\+each\+\_\+safe\+\_\+rcu}(pos,  \textbf{ n},  head)
\begin{DoxyCompactList}\small\item\em Iterate over an rcu-\/protected llist, safe against removal of llist entry. \end{DoxyCompactList}\item 
\#define \textbf{ llist\+\_\+for\+\_\+each\+\_\+entry\+\_\+rcu}(pos,  head,  member)
\begin{DoxyCompactList}\small\item\em Iterate over an rcu-\/protected llist of a given type. \end{DoxyCompactList}\item 
\#define \textbf{ llist\+\_\+for\+\_\+each\+\_\+continue\+\_\+rcu}(pos,  head)
\begin{DoxyCompactList}\small\item\em Iterate over an rcu-\/protected llist, continuing after existing point. \end{DoxyCompactList}\item 
\#define \textbf{ HLIST\+\_\+\+HEAD\+\_\+\+INIT}~\{ .first = NULL \}
\item 
\#define \textbf{ HLIST\+\_\+\+HEAD}(\textbf{ name})~struct \textbf{ hlist\+\_\+head} \textbf{ name} = \{  .first = NULL \}
\item 
\#define \textbf{ INIT\+\_\+\+HLIST\+\_\+\+HEAD}(ptr)~((ptr)-\/$>$first = NULL)
\item 
\#define \textbf{ READ\+\_\+\+ONCE}(x)~x
\item 
\#define \textbf{ WRITE\+\_\+\+ONCE}(a,  b)~a = b
\item 
\#define \textbf{ hlist\+\_\+entry}(ptr,  \textbf{ type},  member)~\textbf{ container\+\_\+of}(ptr,\textbf{ type},member)
\item 
\#define \textbf{ hlist\+\_\+for\+\_\+each}(pos,  head)~ \textbf{ for} (pos = (head)-\/$>$first; pos ; pos = pos-\/$>$next)
\item 
\#define \textbf{ hlist\+\_\+for\+\_\+each\+\_\+safe}(pos,  \textbf{ n},  head)
\item 
\#define \textbf{ hlist\+\_\+entry\+\_\+safe}(ptr,  \textbf{ type},  member)
\item 
\#define \textbf{ hlist\+\_\+for\+\_\+each\+\_\+entry}(pos,  head,  member)
\begin{DoxyCompactList}\small\item\em iterate over list of given type. \end{DoxyCompactList}\item 
\#define \textbf{ hlist\+\_\+for\+\_\+each\+\_\+entry\+\_\+continue}(pos,  member)
\begin{DoxyCompactList}\small\item\em iterate over a hlist continuing after current point. \end{DoxyCompactList}\item 
\#define \textbf{ hlist\+\_\+for\+\_\+each\+\_\+entry\+\_\+from}(pos,  member)
\begin{DoxyCompactList}\small\item\em iterate over a hlist continuing from current point. \end{DoxyCompactList}\item 
\#define \textbf{ hlist\+\_\+for\+\_\+each\+\_\+entry\+\_\+safe}(pos,  \textbf{ n},  head,  member)
\begin{DoxyCompactList}\small\item\em hlist\+\_\+for\+\_\+each\+\_\+entry\+\_\+safe -\/ iterate over list of given type safe against removal of list entry. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Functions}
\begin{DoxyCompactItemize}
\item 
static void \textbf{ prefetch} (const void $\ast$x)
\item 
static void \textbf{ \+\_\+\+\_\+llist\+\_\+add} (struct \textbf{ llist\+\_\+head} $\ast$\+\_\+new, struct \textbf{ llist\+\_\+head} $\ast$prev, struct \textbf{ llist\+\_\+head} $\ast$next)
\item 
static void \textbf{ llist\+\_\+add} (struct \textbf{ llist\+\_\+head} $\ast$\+\_\+new, struct \textbf{ llist\+\_\+head} $\ast$head)
\begin{DoxyCompactList}\small\item\em Add a new entry into a linked list (at head). \end{DoxyCompactList}\item 
static void \textbf{ llist\+\_\+add\+\_\+tail} (struct \textbf{ llist\+\_\+head} $\ast$\+\_\+new, struct \textbf{ llist\+\_\+head} $\ast$head)
\begin{DoxyCompactList}\small\item\em Add a new entry into a linked list (at tail). \end{DoxyCompactList}\item 
static void \textbf{ \+\_\+\+\_\+llist\+\_\+del} (struct \textbf{ llist\+\_\+head} $\ast$prev, struct \textbf{ llist\+\_\+head} $\ast$next)
\item 
static void \textbf{ llist\+\_\+del} (struct \textbf{ llist\+\_\+head} $\ast$entry)
\begin{DoxyCompactList}\small\item\em Delete a single entry from a linked list. \end{DoxyCompactList}\item 
static void \textbf{ llist\+\_\+del\+\_\+init} (struct \textbf{ llist\+\_\+head} $\ast$entry)
\begin{DoxyCompactList}\small\item\em Delete a single entry from a linked list and reinitialize it. \end{DoxyCompactList}\item 
static void \textbf{ llist\+\_\+move} (struct \textbf{ llist\+\_\+head} $\ast$llist, struct \textbf{ llist\+\_\+head} $\ast$head)
\begin{DoxyCompactList}\small\item\em Delete from one llist and add as another\textquotesingle{}s head. \end{DoxyCompactList}\item 
static void \textbf{ llist\+\_\+move\+\_\+tail} (struct \textbf{ llist\+\_\+head} $\ast$llist, struct \textbf{ llist\+\_\+head} $\ast$head)
\begin{DoxyCompactList}\small\item\em Delete from one llist and add as another\textquotesingle{}s tail. \end{DoxyCompactList}\item 
static int \textbf{ llist\+\_\+empty} (const struct \textbf{ llist\+\_\+head} $\ast$head)
\begin{DoxyCompactList}\small\item\em Test whether a linked list is empty. \end{DoxyCompactList}\item 
static void \textbf{ \+\_\+\+\_\+llist\+\_\+splice} (struct \textbf{ llist\+\_\+head} $\ast$llist, struct \textbf{ llist\+\_\+head} $\ast$head)
\item 
static void \textbf{ llist\+\_\+splice} (struct \textbf{ llist\+\_\+head} $\ast$llist, struct \textbf{ llist\+\_\+head} $\ast$head)
\begin{DoxyCompactList}\small\item\em Join two linked lists. \end{DoxyCompactList}\item 
static void \textbf{ llist\+\_\+splice\+\_\+init} (struct \textbf{ llist\+\_\+head} $\ast$llist, struct \textbf{ llist\+\_\+head} $\ast$head)
\begin{DoxyCompactList}\small\item\em Join two llists and reinitialise the emptied llist. \end{DoxyCompactList}\item 
static unsigned int \textbf{ llist\+\_\+count} (const struct \textbf{ llist\+\_\+head} $\ast$head)
\begin{DoxyCompactList}\small\item\em Count number of llist items by iterating. \end{DoxyCompactList}\item 
static void \textbf{ INIT\+\_\+\+HLIST\+\_\+\+NODE} (struct \textbf{ hlist\+\_\+node} $\ast$\textbf{ h})
\item 
static int \textbf{ hlist\+\_\+unhashed} (const struct \textbf{ hlist\+\_\+node} $\ast$\textbf{ h})
\begin{DoxyCompactList}\small\item\em Has node been removed from list and reinitialized?. \end{DoxyCompactList}\item 
static int \textbf{ hlist\+\_\+unhashed\+\_\+lockless} (const struct \textbf{ hlist\+\_\+node} $\ast$\textbf{ h})
\begin{DoxyCompactList}\small\item\em Version of hlist\+\_\+unhashed for lockless use. \end{DoxyCompactList}\item 
static int \textbf{ hlist\+\_\+empty} (const struct \textbf{ hlist\+\_\+head} $\ast$\textbf{ h})
\begin{DoxyCompactList}\small\item\em Is the specified \doxyref{hlist\+\_\+head}{p.}{structhlist__head} structure an empty hlist?. \end{DoxyCompactList}\item 
static void \textbf{ \+\_\+\+\_\+hlist\+\_\+del} (struct \textbf{ hlist\+\_\+node} $\ast$\textbf{ n})
\item 
static void \textbf{ hlist\+\_\+del} (struct \textbf{ hlist\+\_\+node} $\ast$\textbf{ n})
\begin{DoxyCompactList}\small\item\em Delete the specified \doxyref{hlist\+\_\+node}{p.}{structhlist__node} from its list. \end{DoxyCompactList}\item 
static void \textbf{ hlist\+\_\+del\+\_\+init} (struct \textbf{ hlist\+\_\+node} $\ast$\textbf{ n})
\begin{DoxyCompactList}\small\item\em Delete the specified \doxyref{hlist\+\_\+node}{p.}{structhlist__node} from its list and initialize. \end{DoxyCompactList}\item 
static void \textbf{ hlist\+\_\+add\+\_\+head} (struct \textbf{ hlist\+\_\+node} $\ast$\textbf{ n}, struct \textbf{ hlist\+\_\+head} $\ast$\textbf{ h})
\begin{DoxyCompactList}\small\item\em add a new entry at the beginning of the hlist. \end{DoxyCompactList}\item 
static void \textbf{ hlist\+\_\+add\+\_\+before} (struct \textbf{ hlist\+\_\+node} $\ast$\textbf{ n}, struct \textbf{ hlist\+\_\+node} $\ast$next)
\begin{DoxyCompactList}\small\item\em add a new entry before the one specified. \end{DoxyCompactList}\item 
static void \textbf{ hlist\+\_\+add\+\_\+behind} (struct \textbf{ hlist\+\_\+node} $\ast$\textbf{ n}, struct \textbf{ hlist\+\_\+node} $\ast$prev)
\begin{DoxyCompactList}\small\item\em add a new entry after the one specified \end{DoxyCompactList}\item 
static void \textbf{ hlist\+\_\+add\+\_\+fake} (struct \textbf{ hlist\+\_\+node} $\ast$\textbf{ n})
\begin{DoxyCompactList}\small\item\em create a fake hlist consisting of a single headless node. \end{DoxyCompactList}\item 
static bool \textbf{ hlist\+\_\+fake} (struct \textbf{ hlist\+\_\+node} $\ast$\textbf{ h})
\begin{DoxyCompactList}\small\item\em Is this node a fake hlist?. \end{DoxyCompactList}\item 
static bool \textbf{ hlist\+\_\+is\+\_\+singular\+\_\+node} (struct \textbf{ hlist\+\_\+node} $\ast$\textbf{ n}, struct \textbf{ hlist\+\_\+head} $\ast$\textbf{ h})
\begin{DoxyCompactList}\small\item\em is node the only element of the specified hlist?. \end{DoxyCompactList}\item 
static void \textbf{ hlist\+\_\+move\+\_\+list} (struct \textbf{ hlist\+\_\+head} $\ast$old, struct \textbf{ hlist\+\_\+head} $\ast$\+\_\+new)
\begin{DoxyCompactList}\small\item\em Move an hlist. \end{DoxyCompactList}\end{DoxyCompactItemize}


\doxysubsection{Detailed Description}
Simple doubly linked list implementation. 

Some of the internal functions (\char`\"{}\+\_\+\+\_\+xxx\char`\"{}) 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.