7d26c4a69c081e51ea52f982b7b73175cbf41645
[platform/adaptation/renesas_rcar/renesas_kernel.git] / drivers / staging / csr / oska / list.c
1 /*
2  * Operating system kernel abstraction -- linked lists.
3  *
4  * Copyright (C) 2009-2010 Cambridge Silicon Radio Ltd.
5  *
6  * Refer to LICENSE.txt included with this source code for details on
7  * the license terms.
8  */
9
10 #include <stddef.h>
11 #include "list.h"
12
13 /**
14  * Initialize an empty list.
15  *
16  * @ingroup list
17  */
18 void os_list_init(struct os_list *list)
19 {
20     list->head.next = list->head.prev = &list->head;
21 }
22
23 /**
24  * Is the list empty?
25  *
26  * @return true iff the list contains no nodes.
27  *
28  * @ingroup list
29  */
30 int os_list_empty(struct os_list *list)
31 {
32     return list->head.next == &list->head;
33 }
34
35 static void os_list_add(struct os_list_node *prev, struct os_list_node *new,
36                         struct os_list_node *next)
37 {
38     next->prev = new;
39     new->next  = next;
40     new->prev  = prev;
41     prev->next = new;
42 }
43
44 /**
45  * Add a node to the tail of the list.
46  *
47  * @param list the list.
48  * @param node the list node to add.
49  *
50  * @ingroup list
51  */
52 void os_list_add_tail(struct os_list *list, struct os_list_node *node)
53 {
54     os_list_add(list->head.prev, node, &list->head);
55 }
56
57 /**
58  * Remove a node from a list.
59  *
60  * @param node the node to remove.
61  *
62  * @ingroup list
63  */
64 void os_list_del(struct os_list_node *node)
65 {
66     node->prev->next = node->next;
67     node->next->prev = node->prev;
68
69     node->prev = node->next = NULL;
70 }
71
72 /**
73  * The node at the head of the list.
74  *
75  * @param list the list.
76  *
77  * @return the node at the head of the list; or os_list_end() if the
78  * list is empty.
79  *
80  * @ingroup list
81  */
82 struct os_list_node *os_list_head(struct os_list *list)
83 {
84     return list->head.next;
85 }
86
87 /**
88  * The node marking the end of a list.
89  *
90  * @param list the list.
91  *
92  * @return the node that marks the end of the list.
93  *
94  * @ingroup list
95  */
96 struct os_list_node *os_list_end(struct os_list *list)
97 {
98     return &list->head;
99 }