Changes in kernel/generic/include/adt/list.h [14a60e3:0a02653] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/adt/list.h
r14a60e3 r0a02653 1 1 /* 2 2 * Copyright (c) 2001-2004 Jakub Jermar 3 * Copyright (c) 2011 Jiri Svoboda4 3 * All rights reserved. 5 4 * … … 40 39 #include <trace.h> 41 40 42 /** Doubly linked list link. */41 /** Doubly linked list head and link type. */ 43 42 typedef struct link { 44 43 struct link *prev; /**< Pointer to the previous item in the list. */ … … 46 45 } link_t; 47 46 48 /** Doubly linked list. */49 typedef struct list {50 link_t head; /**< List head. Does not have any data. */51 } list_t;52 53 47 /** Declare and initialize statically allocated list. 54 48 * … … 57 51 */ 58 52 #define LIST_INITIALIZE(name) \ 59 list_t name = { \ 60 .head = { \ 61 .prev = &(name).head, \ 62 .next = &(name).head \ 63 } \ 53 link_t name = { \ 54 .prev = &name, \ 55 .next = &name \ 64 56 } 65 57 … … 68 60 69 61 #define list_foreach(list, iterator) \ 70 for (link_t *iterator = (list).head.next; \ 71 iterator != &(list).head; iterator = iterator->next) 72 73 #define assert_link_not_used(link) \ 74 ASSERT(((link)->prev == NULL) && ((link)->next == NULL)) 62 for (link_t *iterator = (list).next; \ 63 iterator != &(list); iterator = iterator->next) 75 64 76 65 /** Initialize doubly-linked circular list link … … 91 80 * Initialize doubly-linked circular list. 92 81 * 93 * @param list Pointer to list_t structure. 94 * 95 */ 96 NO_TRACE static inline void list_initialize(list_t *list) 97 { 98 list->head.prev = &list->head; 99 list->head.next = &list->head; 82 * @param list Pointer to link_t structure representing the list. 83 * 84 */ 85 NO_TRACE static inline void list_initialize(link_t *list) 86 { 87 list->prev = list; 88 list->next = list; 89 } 90 91 /** Add item to the beginning of doubly-linked circular list 92 * 93 * Add item to the beginning of doubly-linked circular list. 94 * 95 * @param link Pointer to link_t structure to be added. 96 * @param list Pointer to link_t structure representing the list. 97 * 98 */ 99 NO_TRACE static inline void list_prepend(link_t *link, link_t *list) 100 { 101 link->next = list->next; 102 link->prev = list; 103 list->next->prev = link; 104 list->next = link; 105 } 106 107 /** Add item to the end of doubly-linked circular list 108 * 109 * Add item to the end of doubly-linked circular list. 110 * 111 * @param link Pointer to link_t structure to be added. 112 * @param list Pointer to link_t structure representing the list. 113 * 114 */ 115 NO_TRACE static inline void list_append(link_t *link, link_t *list) 116 { 117 link->prev = list->prev; 118 link->next = list; 119 list->prev->next = link; 120 list->prev = link; 100 121 } 101 122 … … 103 124 * 104 125 */ 105 static inline void list_insert_before(link_t *lnew, link_t *lold) 106 { 107 lnew->next = lold; 108 lnew->prev = lold->prev; 109 lold->prev->next = lnew; 110 lold->prev = lnew; 126 static inline void list_insert_before(link_t *link, link_t *list) 127 { 128 list_append(link, list); 111 129 } 112 130 … … 114 132 * 115 133 */ 116 static inline void list_insert_after(link_t *lnew, link_t *lold) 117 { 118 lnew->prev = lold; 119 lnew->next = lold->next; 120 lold->next->prev = lnew; 121 lold->next = lnew; 122 } 123 124 /** Add item to the beginning of doubly-linked circular list 125 * 126 * Add item to the beginning of doubly-linked circular list. 127 * 128 * @param link Pointer to link_t structure to be added. 129 * @param list Pointer to list_t structure. 130 * 131 */ 132 NO_TRACE static inline void list_prepend(link_t *link, list_t *list) 133 { 134 list_insert_after(link, &list->head); 135 } 136 137 /** Add item to the end of doubly-linked circular list 138 * 139 * Add item to the end of doubly-linked circular list. 140 * 141 * @param link Pointer to link_t structure to be added. 142 * @param list Pointer to list_t structure. 143 * 144 */ 145 NO_TRACE static inline void list_append(link_t *link, list_t *list) 146 { 147 list_insert_before(link, &list->head); 134 static inline void list_insert_after(link_t *link, link_t *list) 135 { 136 list_prepend(list, link); 148 137 } 149 138 … … 158 147 NO_TRACE static inline void list_remove(link_t *link) 159 148 { 160 if ((link->prev != NULL) && (link->next != NULL)) { 161 link->next->prev = link->prev; 162 link->prev->next = link->next; 163 } 164 149 link->next->prev = link->prev; 150 link->prev->next = link->next; 165 151 link_initialize(link); 166 152 } … … 170 156 * Query emptiness of doubly-linked circular list. 171 157 * 172 * @param list Pointer to lin s_t structure.173 * 174 */ 175 NO_TRACE static inline int list_empty(li st_t *list)176 { 177 return (list-> head.next == &list->head);178 } 179 180 /** Get first item inlist.181 * 182 * @param list Pointer to li st_t structure.158 * @param list Pointer to link_t structure representing the list. 159 * 160 */ 161 NO_TRACE static inline int list_empty(link_t *list) 162 { 163 return (list->next == list); 164 } 165 166 /** Get head item of a list. 167 * 168 * @param list Pointer to link_t structure representing the list. 183 169 * 184 170 * @return Head item of the list. … … 186 172 * 187 173 */ 188 static inline link_t *list_first(list_t *list) 189 { 190 return ((list->head.next == &list->head) ? NULL : list->head.next); 191 } 192 193 /** Get last item in list. 194 * 195 * @param list Pointer to list_t structure. 196 * 197 * @return Head item of the list. 198 * @return NULL if the list is empty. 199 * 200 */ 201 static inline link_t *list_last(list_t *list) 202 { 203 return ((list->head.prev == &list->head) ? NULL : list->head.prev); 174 static inline link_t *list_head(link_t *list) 175 { 176 return ((list->next == list) ? NULL : list->next); 204 177 } 205 178 … … 258 231 } 259 232 260 /** Get n-th item ina list.233 /** Get n-th item of a list. 261 234 * 262 235 * @param list Pointer to link_t structure representing the list. … … 267 240 * 268 241 */ 269 static inline link_t *list_nth(li st_t *list, unsigned int n)242 static inline link_t *list_nth(link_t *list, unsigned int n) 270 243 { 271 244 unsigned int cnt = 0; … … 281 254 } 282 255 283 extern int list_member(const link_t *, const li st_t *);284 extern void list_concat(li st_t *, list_t *);285 extern unsigned int list_count(const li st_t *);256 extern int list_member(const link_t *, const link_t *); 257 extern void list_concat(link_t *, link_t *); 258 extern unsigned int list_count(const link_t *); 286 259 287 260 #endif
Note:
See TracChangeset
for help on using the changeset viewer.