\input{configpres}

\title{klist}
\maketitle

\subsection{klist}

\begin{frame}
\frametitle{Overview}
\tableofcontents
\end{frame}

\subsubsection{What is it?}
\begin{frame}
\frametitle{klist functionality}
\begin{itemize}
\item Type oblivious - use with any data structure you have in mind
\item Doubly linked list
\item Iterations, etc. are easily readable
\end{itemize}
\end{frame}

\subsubsection{Usage}
\begin{frame}[fragile]
\frametitle{Initialization}
\begin{lstlisting}
struct my_elem {
        int member1;
        long member2;
        struct list_head node;
};

/* the following is the same as
 * struct list_head mylist;
 * INIT_LIST_HEAD(&mylist.list);
 */
LIST_HEAD(mylist);
\end{lstlisting}
\end{frame}

\begin{frame}[fragile]
\frametitle{Add elements}
\begin{lstlisting}
struct my_elem *e;
while( .. ) {
        e = kzalloc(sizeof(*e), GFP_KERNEL);
        e->member1 = 3;

        /* add element to the beginning of the list */
        list_add(&e->node, &mylist);

        /* to add element to the tail of the list use
         * list_add_tail(&e->node, &mylist);
         */
}
\end{lstlisting}
\end{frame}


\begin{frame}[fragile]
\frametitle{Iterate over list}
\begin{lstlisting}
struct my_elem *iterator, tmp;

/* last argument is name of struct list_head inside mylist */
list_for_each_entry(iterator, &mylist, node) {
        iterator->member1 = 0x08;
        iterator->member2 = 0x15;
}
\end{lstlisting}
\pause
\begin{lstlisting}
list_for_each_entry_reverse(iterator, &mylist, node)
        iterator->member1 = 0x08;
\end{lstlisting}
\pause
\begin{lstlisting}
/* clear list and free elements
 * _safe allows modificatio of the list during iteration
 */
list_for_each_entry_safe(iterator, tmp, &mylist, node) {
        list_del(&iterator->node);
        kfree(iterator);
}
\end{lstlisting}
\end{frame}

\begin{frame}
\frametitle{There are a lot of helpers!}
see: include/linux/list.h
\end{frame}

\input{tailpres}
