Changeset dd0c8a0 in mainline for kernel/generic/include/adt/list.h
- Timestamp:
- 2013-09-29T06:56:33Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a9bd960d
- Parents:
- 3deb0155 (diff), 13be2583 (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
r3deb0155 rdd0c8a0 1 1 /* 2 2 * Copyright (c) 2001-2004 Jakub Jermar 3 * Copyright (c) 201 1Jiri Svoboda3 * Copyright (c) 2013 Jiri Svoboda 4 4 * All rights reserved. 5 5 * … … 65 65 66 66 #define list_get_instance(link, type, member) \ 67 ((type *) (((void *)(link)) - ((void *) &(((type *) NULL)->member)))) 68 69 #define list_foreach(list, iterator) \ 70 for (link_t *iterator = (list).head.next; \ 71 iterator != &(list).head; iterator = iterator->next) 67 ((type *) (((void *)(link)) - list_link_to_void(&(((type *) NULL)->member)))) 68 69 #define list_foreach(list, member, itype, iterator) \ 70 for (itype *iterator = NULL; iterator == NULL; iterator = (itype *) 1) \ 71 for (link_t *_link = (list).head.next; \ 72 iterator = list_get_instance(_link, itype, member), \ 73 _link != &(list).head; _link = _link->next) 72 74 73 75 #define assert_link_not_used(link) \ … … 204 206 } 205 207 208 /** Get next item in list. 209 * 210 * @param link Current item link 211 * @param list List containing @a link 212 * 213 * @return Next item or NULL if @a link is the last item. 214 */ 215 static inline link_t *list_next(link_t *link, const list_t *list) 216 { 217 return (link->next == &list->head) ? NULL : link->next; 218 } 219 220 /** Get previous item in list. 221 * 222 * @param link Current item link 223 * @param list List containing @a link 224 * 225 * @return Previous item or NULL if @a link is the first item. 226 */ 227 static inline link_t *list_prev(link_t *link, const list_t *list) 228 { 229 return (link->prev == &list->head) ? NULL : link->prev; 230 } 231 206 232 /** Split or concatenate headless doubly-linked circular list 207 233 * … … 270 296 { 271 297 unsigned int cnt = 0; 272 273 list_foreach(*list, link) { 298 link_t *link; 299 300 link = list_first(list); 301 while (link != NULL) { 274 302 if (cnt == n) 275 303 return link; 276 304 277 305 cnt++; 306 link = list_next(link, list); 278 307 } 279 308 280 309 return NULL; 310 } 311 312 /** Verify that argument type is a pointer to link_t (at compile time). 313 * 314 * This can be used to check argument type in a macro. 315 */ 316 static inline const void *list_link_to_void(const link_t *link) 317 { 318 return link; 281 319 } 282 320
Note:
See TracChangeset
for help on using the changeset viewer.