Changeset 0c2d9bb in mainline for kernel/generic/include/adt/list.h
- Timestamp:
- 2013-12-25T22:54:29Z (10 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b51cf2c
- Parents:
- f7a33de (diff), ac36aed (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
rf7a33de r0c2d9bb 37 37 #define KERN_LIST_H_ 38 38 39 #include <debug.h> 39 40 #include <typedefs.h> 40 41 #include <trace.h> … … 67 68 ((type *) (((void *)(link)) - list_link_to_void(&(((type *) NULL)->member)))) 68 69 69 #define list_foreach(list, iterator) \ 70 for (link_t *iterator = (list).head.next; \ 71 iterator != &(list).head; iterator = iterator->next) 70 #define list_foreach(list, member, itype, iterator) \ 71 for (itype *iterator = NULL; iterator == NULL; iterator = (itype *) 1) \ 72 for (link_t *_link = (list).head.next; \ 73 iterator = list_get_instance(_link, itype, member), \ 74 _link != &(list).head; _link = _link->next) 75 76 #define list_foreach_rev(list, member, itype, iterator) \ 77 for (itype *iterator = NULL; iterator == NULL; iterator = (itype *) 1) \ 78 for (link_t *_link = (list).head.prev; \ 79 iterator = list_get_instance(_link, itype, member), \ 80 _link != &(list).head; _link = _link->prev) 72 81 73 82 #define assert_link_not_used(link) \ 74 ASSERT( ((link)->prev == NULL) && ((link)->next == NULL))83 ASSERT(!link_used(link)) 75 84 76 85 /** Initialize doubly-linked circular list link … … 204 213 } 205 214 215 /** Get next item in list. 216 * 217 * @param link Current item link 218 * @param list List containing @a link 219 * 220 * @return Next item or NULL if @a link is the last item. 221 */ 222 static inline link_t *list_next(link_t *link, const list_t *list) 223 { 224 return (link->next == &list->head) ? NULL : link->next; 225 } 226 227 /** Get previous item in list. 228 * 229 * @param link Current item link 230 * @param list List containing @a link 231 * 232 * @return Previous item or NULL if @a link is the first item. 233 */ 234 static inline link_t *list_prev(link_t *link, const list_t *list) 235 { 236 return (link->prev == &list->head) ? NULL : link->prev; 237 } 238 206 239 /** Split or concatenate headless doubly-linked circular list 207 240 * … … 270 303 { 271 304 unsigned int cnt = 0; 272 273 list_foreach(*list, link) { 305 link_t *link; 306 307 link = list_first(list); 308 while (link != NULL) { 274 309 if (cnt == n) 275 310 return link; 276 311 277 312 cnt++; 313 link = list_next(link, list); 278 314 } 279 315 … … 288 324 { 289 325 return link; 326 } 327 328 /** Determine if link is used. 329 * 330 * @param link Link 331 * @return @c true if link is used, @c false if not. 332 */ 333 static inline bool link_used(link_t *link) 334 { 335 if (link->prev == NULL && link->next == NULL) 336 return false; 337 338 ASSERT(link->prev != NULL && link->next != NULL); 339 return true; 290 340 } 291 341
Note:
See TracChangeset
for help on using the changeset viewer.