3 * \brief List implemenation
6 * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
7 * Ronald Aigner <ra3@os.inf.tu-dresden.de>
8 * economic rights: Technische Universität Dresden (Germany)
9 * This file is part of TUD:OS and distributed under the terms of the
10 * GNU Lesser General Public License 2.1.
11 * Please see the COPYING-LGPL-2.1 file for details.
13 #ifndef __L4UTIL__SLL_H__
14 #define __L4UTIL__SLL_H__
18 #include <l4/sys/compiler.h>
23 * the linked list structure
26 typedef struct slist_t
28 struct slist_t *next; /* pointer to next node */
29 void *data; /* void pointer for user data */
35 static inline slist_t*
36 list_new_entry(void *data);
38 static inline slist_t*
39 list_append(slist_t *list, slist_t *new_node);
41 static inline slist_t*
42 list_remove(slist_t *list, slist_t *node);
45 list_free_entry(slist_t **list);
47 static inline unsigned char
48 list_is_empty(slist_t *list);
50 static inline slist_t*
51 list_get_at(slist_t *list, int n);
53 static inline slist_t*
54 list_add(slist_t *list, slist_t *new_node);
57 list_insert_after(slist_t *after, slist_t *new_node);
60 list_elements(slist_t *head);
64 * allocate a new node.
67 * void *data a generic pointer to object data
70 * pointer to slist_t if succeeds
74 static inline slist_t*
75 list_new_entry(void *data)
79 sll = (slist_t *)malloc(sizeof(slist_t));
81 return ((slist_t *) NULL);
91 * appends a node to the end of a list
94 * slist_t *head - modify the list
95 * slist_t *new - appends this node
101 static inline slist_t*
102 list_append(slist_t *head, slist_t *new_node)
110 head->next = new_node;
116 * insert a node at the beginning of a list
119 * slist_t *head - modify this list
120 * slist_t *new - appends this node
126 static inline slist_t*
127 list_add(slist_t *head, slist_t *new_node)
131 new_node->next = head;
137 * insert a node at the beginning of a list
140 * slist_t *head - modify this list
141 * slist_t *new - appends this node
148 list_insert_after(slist_t *after, slist_t *new_node)
154 new_node->next = after->next;
155 after->next = new_node;
161 * check if a list variable is NULL
171 static inline unsigned char
172 list_is_empty(slist_t *list)
174 return ((list) ? 0 : 1);
179 * remove a node from a list
182 * slist_t *head - list to modify
183 * slist_t *node - node to remove
189 static inline slist_t*
190 list_remove(slist_t *head, slist_t *node)
193 if (list_is_empty(head))
204 while (head && (head->next != node))
209 head->next = node->next;
211 list_free_entry(&node);
220 * slist_t *list node to free
227 list_free_entry(slist_t **list)
231 free ((void *) (*list));
239 * get nth node in a list
242 * slist_t *list - the head list
243 * int n - return the node
245 * a pointer to the list at position n
246 * NULL if there's no such node at posion n
249 static inline slist_t*
250 list_get_at(slist_t *list, int n)
262 return ((slist_t *) NULL);
267 * returns number of nodes in the list
270 * slist_t *head - the head node of the list
277 list_elements(slist_t *head)
280 for (n=0; head; head=head->next) n++;
286 #endif /* __L4UTIL__SLL_H__ */