Changeset bd08239 in mainline for kernel/generic/include/adt/list.h
- Timestamp:
- 2011-06-18T15:35:25Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 44e2c1a
- Parents:
- 313775b (diff), adfdbd5 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/adt/list.h
r313775b rbd08239 1 1 /* 2 2 * Copyright (c) 2001-2004 Jakub Jermar 3 * Copyright (c) 2011 Jiri Svoboda 3 4 * All rights reserved. 4 5 * … … 39 40 #include <trace.h> 40 41 41 /** Doubly linked list head and link type. */42 /** Doubly linked list link. */ 42 43 typedef struct link { 43 44 struct link *prev; /**< Pointer to the previous item in the list. */ … … 45 46 } link_t; 46 47 48 /** Doubly linked list. */ 49 typedef struct list { 50 link_t head; /**< List head. Does not have any data. */ 51 } list_t; 52 47 53 /** Declare and initialize statically allocated list. 48 54 * … … 51 57 */ 52 58 #define LIST_INITIALIZE(name) \ 53 link_t name = { \ 54 .prev = &name, \ 55 .next = &name \ 59 list_t name = { \ 60 .head = { \ 61 .prev = &(name).head, \ 62 .next = &(name).head \ 63 } \ 56 64 } 57 65 … … 60 68 61 69 #define list_foreach(list, iterator) \ 62 for (link_t *iterator = (list). next; \63 iterator != &(list) ; iterator = iterator->next)70 for (link_t *iterator = (list).head.next; \ 71 iterator != &(list).head; iterator = iterator->next) 64 72 65 73 /** Initialize doubly-linked circular list link … … 80 88 * Initialize doubly-linked circular list. 81 89 * 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; 90 * @param list Pointer to list_t structure. 91 * 92 */ 93 NO_TRACE static inline void list_initialize(list_t *list) 94 { 95 list->head.prev = &list->head; 96 list->head.next = &list->head; 97 } 98 99 /** Insert item before another item in doubly-linked circular list. 100 * 101 */ 102 static inline void list_insert_before(link_t *lnew, link_t *lold) 103 { 104 lnew->next = lold; 105 lnew->prev = lold->prev; 106 lold->prev->next = lnew; 107 lold->prev = lnew; 108 } 109 110 /** Insert item after another item in doubly-linked circular list. 111 * 112 */ 113 static inline void list_insert_after(link_t *lnew, link_t *lold) 114 { 115 lnew->prev = lold; 116 lnew->next = lold->next; 117 lold->next->prev = lnew; 118 lold->next = lnew; 89 119 } 90 120 … … 94 124 * 95 125 * @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; 126 * @param list Pointer to list_t structure. 127 * 128 */ 129 NO_TRACE static inline void list_prepend(link_t *link, list_t *list) 130 { 131 list_insert_after(link, &list->head); 105 132 } 106 133 … … 110 137 * 111 138 * @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; 121 } 122 123 /** Insert item before another item in doubly-linked circular list. 124 * 125 */ 126 static inline void list_insert_before(link_t *link, link_t *list) 127 { 128 list_append(link, list); 129 } 130 131 /** Insert item after another item in doubly-linked circular list. 132 * 133 */ 134 static inline void list_insert_after(link_t *link, link_t *list) 135 { 136 list_prepend(list, link); 139 * @param list Pointer to list_t structure. 140 * 141 */ 142 NO_TRACE static inline void list_append(link_t *link, list_t *list) 143 { 144 list_insert_before(link, &list->head); 137 145 } 138 146 … … 156 164 * Query emptiness of doubly-linked circular list. 157 165 * 158 * @param list Pointer to lin k_t structure representing the list.159 * 160 */ 161 NO_TRACE static inline int list_empty(li nk_t *list)162 { 163 return (list-> next == list);164 } 165 166 /** Get head item of alist.167 * 168 * @param list Pointer to li nk_t structure representing the list.166 * @param list Pointer to lins_t structure. 167 * 168 */ 169 NO_TRACE static inline int list_empty(list_t *list) 170 { 171 return (list->head.next == &list->head); 172 } 173 174 /** Get first item in list. 175 * 176 * @param list Pointer to list_t structure. 169 177 * 170 178 * @return Head item of the list. … … 172 180 * 173 181 */ 174 static inline link_t *list_head(link_t *list) 175 { 176 return ((list->next == list) ? NULL : list->next); 182 static inline link_t *list_first(list_t *list) 183 { 184 return ((list->head.next == &list->head) ? NULL : list->head.next); 185 } 186 187 /** Get last item in list. 188 * 189 * @param list Pointer to list_t structure. 190 * 191 * @return Head item of the list. 192 * @return NULL if the list is empty. 193 * 194 */ 195 static inline link_t *list_last(list_t *list) 196 { 197 return ((list->head.prev == &list->head) ? NULL : list->head.prev); 177 198 } 178 199 … … 231 252 } 232 253 233 /** Get n-th item ofa list.254 /** Get n-th item in a list. 234 255 * 235 256 * @param list Pointer to link_t structure representing the list. … … 240 261 * 241 262 */ 242 static inline link_t *list_nth(li nk_t *list, unsigned int n)263 static inline link_t *list_nth(list_t *list, unsigned int n) 243 264 { 244 265 unsigned int cnt = 0; … … 254 275 } 255 276 256 extern int list_member(const link_t *, const li nk_t *);257 extern void list_concat(li nk_t *, link_t *);258 extern unsigned int list_count(const li nk_t *);277 extern int list_member(const link_t *, const list_t *); 278 extern void list_concat(list_t *, list_t *); 279 extern unsigned int list_count(const list_t *); 259 280 260 281 #endif
Note:
See TracChangeset
for help on using the changeset viewer.