Rev 4065 | Rev 5270 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4065 | Rev 5056 | ||
---|---|---|---|
Line 359... | Line 359... | ||
359 | */ |
359 | */ |
360 | #define list_first_entry(ptr, type, member) \ |
360 | #define list_first_entry(ptr, type, member) \ |
361 | list_entry((ptr)->next, type, member) |
361 | list_entry((ptr)->next, type, member) |
Line 362... | Line 362... | ||
362 | 362 | ||
- | 363 | /** |
|
- | 364 | * list_last_entry - get the last element from a list |
|
- | 365 | * @ptr: the list head to take the element from. |
|
- | 366 | * @type: the type of the struct this is embedded in. |
|
- | 367 | * @member: the name of the list_struct within the struct. |
|
- | 368 | * |
|
- | 369 | * Note, that list is expected to be not empty. |
|
- | 370 | */ |
|
- | 371 | #define list_last_entry(ptr, type, member) \ |
|
- | 372 | list_entry((ptr)->prev, type, member) |
|
- | 373 | ||
363 | /** |
374 | /** |
364 | * list_first_entry_or_null - get the first element from a list |
375 | * list_first_entry_or_null - get the first element from a list |
365 | * @ptr: the list head to take the element from. |
376 | * @ptr: the list head to take the element from. |
366 | * @type: the type of the struct this is embedded in. |
377 | * @type: the type of the struct this is embedded in. |
367 | * @member: the name of the list_struct within the struct. |
378 | * @member: the name of the list_struct within the struct. |
Line 370... | Line 381... | ||
370 | */ |
381 | */ |
371 | #define list_first_entry_or_null(ptr, type, member) \ |
382 | #define list_first_entry_or_null(ptr, type, member) \ |
372 | (!list_empty(ptr) ? list_first_entry(ptr, type, member) : NULL) |
383 | (!list_empty(ptr) ? list_first_entry(ptr, type, member) : NULL) |
Line 373... | Line 384... | ||
373 | 384 | ||
- | 385 | /** |
|
- | 386 | * list_next_entry - get the next element in list |
|
- | 387 | * @pos: the type * to cursor |
|
- | 388 | * @member: the name of the list_struct within the struct. |
|
- | 389 | */ |
|
- | 390 | #define list_next_entry(pos, member) \ |
|
- | 391 | list_entry((pos)->member.next, typeof(*(pos)), member) |
|
- | 392 | ||
- | 393 | /** |
|
- | 394 | * list_prev_entry - get the prev element in list |
|
- | 395 | * @pos: the type * to cursor |
|
- | 396 | * @member: the name of the list_struct within the struct. |
|
- | 397 | */ |
|
- | 398 | #define list_prev_entry(pos, member) \ |
|
- | 399 | list_entry((pos)->member.prev, typeof(*(pos)), member) |
|
- | 400 | ||
374 | /** |
401 | /** |
375 | * list_for_each - iterate over a list |
402 | * list_for_each - iterate over a list |
376 | * @pos: the &struct list_head to use as a loop cursor. |
403 | * @pos: the &struct list_head to use as a loop cursor. |
377 | * @head: the head for your list. |
404 | * @head: the head for your list. |
378 | */ |
405 | */ |
Line 413... | Line 440... | ||
413 | * @pos: the type * to use as a loop cursor. |
440 | * @pos: the type * to use as a loop cursor. |
414 | * @head: the head for your list. |
441 | * @head: the head for your list. |
415 | * @member: the name of the list_struct within the struct. |
442 | * @member: the name of the list_struct within the struct. |
416 | */ |
443 | */ |
417 | #define list_for_each_entry(pos, head, member) \ |
444 | #define list_for_each_entry(pos, head, member) \ |
418 | for (pos = list_entry((head)->next, typeof(*pos), member); \ |
445 | for (pos = list_first_entry(head, typeof(*pos), member); \ |
419 | &pos->member != (head); \ |
446 | &pos->member != (head); \ |
420 | pos = list_entry(pos->member.next, typeof(*pos), member)) |
447 | pos = list_next_entry(pos, member)) |
Line 421... | Line 448... | ||
421 | 448 | ||
422 | /** |
449 | /** |
423 | * list_for_each_entry_reverse - iterate backwards over list of given type. |
450 | * list_for_each_entry_reverse - iterate backwards over list of given type. |
424 | * @pos: the type * to use as a loop cursor. |
451 | * @pos: the type * to use as a loop cursor. |
425 | * @head: the head for your list. |
452 | * @head: the head for your list. |
426 | * @member: the name of the list_struct within the struct. |
453 | * @member: the name of the list_struct within the struct. |
427 | */ |
454 | */ |
428 | #define list_for_each_entry_reverse(pos, head, member) \ |
455 | #define list_for_each_entry_reverse(pos, head, member) \ |
429 | for (pos = list_entry((head)->prev, typeof(*pos), member); \ |
456 | for (pos = list_last_entry(head, typeof(*pos), member); \ |
430 | &pos->member != (head); \ |
457 | &pos->member != (head); \ |
Line 431... | Line 458... | ||
431 | pos = list_entry(pos->member.prev, typeof(*pos), member)) |
458 | pos = list_prev_entry(pos, member)) |
432 | 459 | ||
433 | /** |
460 | /** |
434 | * list_prepare_entry - prepare a pos entry for use in list_for_each_entry_continue() |
461 | * list_prepare_entry - prepare a pos entry for use in list_for_each_entry_continue() |
Line 449... | Line 476... | ||
449 | * |
476 | * |
450 | * Continue to iterate over list of given type, continuing after |
477 | * Continue to iterate over list of given type, continuing after |
451 | * the current position. |
478 | * the current position. |
452 | */ |
479 | */ |
453 | #define list_for_each_entry_continue(pos, head, member) \ |
480 | #define list_for_each_entry_continue(pos, head, member) \ |
454 | for (pos = list_entry(pos->member.next, typeof(*pos), member); \ |
481 | for (pos = list_next_entry(pos, member); \ |
455 | &pos->member != (head); \ |
482 | &pos->member != (head); \ |
456 | pos = list_entry(pos->member.next, typeof(*pos), member)) |
483 | pos = list_next_entry(pos, member)) |
Line 457... | Line 484... | ||
457 | 484 | ||
458 | /** |
485 | /** |
459 | * list_for_each_entry_continue_reverse - iterate backwards from the given point |
486 | * list_for_each_entry_continue_reverse - iterate backwards from the given point |
460 | * @pos: the type * to use as a loop cursor. |
487 | * @pos: the type * to use as a loop cursor. |
Line 463... | Line 490... | ||
463 | * |
490 | * |
464 | * Start to iterate over list of given type backwards, continuing after |
491 | * Start to iterate over list of given type backwards, continuing after |
465 | * the current position. |
492 | * the current position. |
466 | */ |
493 | */ |
467 | #define list_for_each_entry_continue_reverse(pos, head, member) \ |
494 | #define list_for_each_entry_continue_reverse(pos, head, member) \ |
468 | for (pos = list_entry(pos->member.prev, typeof(*pos), member); \ |
495 | for (pos = list_prev_entry(pos, member); \ |
469 | &pos->member != (head); \ |
496 | &pos->member != (head); \ |
470 | pos = list_entry(pos->member.prev, typeof(*pos), member)) |
497 | pos = list_prev_entry(pos, member)) |
Line 471... | Line 498... | ||
471 | 498 | ||
472 | /** |
499 | /** |
473 | * list_for_each_entry_from - iterate over list of given type from the current point |
500 | * list_for_each_entry_from - iterate over list of given type from the current point |
474 | * @pos: the type * to use as a loop cursor. |
501 | * @pos: the type * to use as a loop cursor. |
Line 477... | Line 504... | ||
477 | * |
504 | * |
478 | * Iterate over list of given type, continuing from current position. |
505 | * Iterate over list of given type, continuing from current position. |
479 | */ |
506 | */ |
480 | #define list_for_each_entry_from(pos, head, member) \ |
507 | #define list_for_each_entry_from(pos, head, member) \ |
481 | for (; &pos->member != (head); \ |
508 | for (; &pos->member != (head); \ |
482 | pos = list_entry(pos->member.next, typeof(*pos), member)) |
509 | pos = list_next_entry(pos, member)) |
Line 483... | Line 510... | ||
483 | 510 | ||
484 | /** |
511 | /** |
485 | * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry |
512 | * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry |
486 | * @pos: the type * to use as a loop cursor. |
513 | * @pos: the type * to use as a loop cursor. |
487 | * @n: another type * to use as temporary storage |
514 | * @n: another type * to use as temporary storage |
488 | * @head: the head for your list. |
515 | * @head: the head for your list. |
489 | * @member: the name of the list_struct within the struct. |
516 | * @member: the name of the list_struct within the struct. |
490 | */ |
517 | */ |
491 | #define list_for_each_entry_safe(pos, n, head, member) \ |
518 | #define list_for_each_entry_safe(pos, n, head, member) \ |
492 | for (pos = list_entry((head)->next, typeof(*pos), member), \ |
519 | for (pos = list_first_entry(head, typeof(*pos), member), \ |
493 | n = list_entry(pos->member.next, typeof(*pos), member); \ |
520 | n = list_next_entry(pos, member); \ |
494 | &pos->member != (head); \ |
521 | &pos->member != (head); \ |
Line 495... | Line 522... | ||
495 | pos = n, n = list_entry(n->member.next, typeof(*n), member)) |
522 | pos = n, n = list_next_entry(n, member)) |
496 | 523 | ||
497 | /** |
524 | /** |
498 | * list_for_each_entry_safe_continue - continue list iteration safe against removal |
525 | * list_for_each_entry_safe_continue - continue list iteration safe against removal |
Line 503... | Line 530... | ||
503 | * |
530 | * |
504 | * Iterate over list of given type, continuing after current point, |
531 | * Iterate over list of given type, continuing after current point, |
505 | * safe against removal of list entry. |
532 | * safe against removal of list entry. |
506 | */ |
533 | */ |
507 | #define list_for_each_entry_safe_continue(pos, n, head, member) \ |
534 | #define list_for_each_entry_safe_continue(pos, n, head, member) \ |
508 | for (pos = list_entry(pos->member.next, typeof(*pos), member), \ |
535 | for (pos = list_next_entry(pos, member), \ |
509 | n = list_entry(pos->member.next, typeof(*pos), member); \ |
536 | n = list_next_entry(pos, member); \ |
510 | &pos->member != (head); \ |
537 | &pos->member != (head); \ |
511 | pos = n, n = list_entry(n->member.next, typeof(*n), member)) |
538 | pos = n, n = list_next_entry(n, member)) |
Line 512... | Line 539... | ||
512 | 539 | ||
513 | /** |
540 | /** |
514 | * list_for_each_entry_safe_from - iterate over list from current point safe against removal |
541 | * list_for_each_entry_safe_from - iterate over list from current point safe against removal |
515 | * @pos: the type * to use as a loop cursor. |
542 | * @pos: the type * to use as a loop cursor. |
Line 519... | Line 546... | ||
519 | * |
546 | * |
520 | * Iterate over list of given type from current point, safe against |
547 | * Iterate over list of given type from current point, safe against |
521 | * removal of list entry. |
548 | * removal of list entry. |
522 | */ |
549 | */ |
523 | #define list_for_each_entry_safe_from(pos, n, head, member) \ |
550 | #define list_for_each_entry_safe_from(pos, n, head, member) \ |
524 | for (n = list_entry(pos->member.next, typeof(*pos), member); \ |
551 | for (n = list_next_entry(pos, member); \ |
525 | &pos->member != (head); \ |
552 | &pos->member != (head); \ |
526 | pos = n, n = list_entry(n->member.next, typeof(*n), member)) |
553 | pos = n, n = list_next_entry(n, member)) |
Line 527... | Line 554... | ||
527 | 554 | ||
528 | /** |
555 | /** |
529 | * list_for_each_entry_safe_reverse - iterate backwards over list safe against removal |
556 | * list_for_each_entry_safe_reverse - iterate backwards over list safe against removal |
530 | * @pos: the type * to use as a loop cursor. |
557 | * @pos: the type * to use as a loop cursor. |
Line 534... | Line 561... | ||
534 | * |
561 | * |
535 | * Iterate backwards over list of given type, safe against removal |
562 | * Iterate backwards over list of given type, safe against removal |
536 | * of list entry. |
563 | * of list entry. |
537 | */ |
564 | */ |
538 | #define list_for_each_entry_safe_reverse(pos, n, head, member) \ |
565 | #define list_for_each_entry_safe_reverse(pos, n, head, member) \ |
539 | for (pos = list_entry((head)->prev, typeof(*pos), member), \ |
566 | for (pos = list_last_entry(head, typeof(*pos), member), \ |
540 | n = list_entry(pos->member.prev, typeof(*pos), member); \ |
567 | n = list_prev_entry(pos, member); \ |
541 | &pos->member != (head); \ |
568 | &pos->member != (head); \ |
542 | pos = n, n = list_entry(n->member.prev, typeof(*n), member)) |
569 | pos = n, n = list_prev_entry(n, member)) |
Line 543... | Line 570... | ||
543 | 570 | ||
544 | /** |
571 | /** |
545 | * list_safe_reset_next - reset a stale list_for_each_entry_safe loop |
572 | * list_safe_reset_next - reset a stale list_for_each_entry_safe loop |
546 | * @pos: the loop cursor used in the list_for_each_entry_safe loop |
573 | * @pos: the loop cursor used in the list_for_each_entry_safe loop |
Line 552... | Line 579... | ||
552 | * exception to this is if the cursor element (pos) is pinned in the list, |
579 | * exception to this is if the cursor element (pos) is pinned in the list, |
553 | * and list_safe_reset_next is called after re-taking the lock and before |
580 | * and list_safe_reset_next is called after re-taking the lock and before |
554 | * completing the current iteration of the loop body. |
581 | * completing the current iteration of the loop body. |
555 | */ |
582 | */ |
556 | #define list_safe_reset_next(pos, n, member) \ |
583 | #define list_safe_reset_next(pos, n, member) \ |
557 | n = list_entry(pos->member.next, typeof(*pos), member) |
584 | n = list_next_entry(pos, member) |
Line 558... | Line 585... | ||
558 | 585 | ||
559 | /* |
586 | /* |
560 | * Double linked lists with a single pointer list head. |
587 | * Double linked lists with a single pointer list head. |
561 | * Mostly useful for hash tables where the two pointer list head is |
588 | * Mostly useful for hash tables where the two pointer list head is |
Line 624... | Line 651... | ||
624 | n->next = next; |
651 | n->next = next; |
625 | next->pprev = &n->next; |
652 | next->pprev = &n->next; |
626 | *(n->pprev) = n; |
653 | *(n->pprev) = n; |
627 | } |
654 | } |
Line 628... | Line 655... | ||
628 | 655 | ||
629 | static inline void hlist_add_after(struct hlist_node *n, |
656 | static inline void hlist_add_behind(struct hlist_node *n, |
630 | struct hlist_node *next) |
657 | struct hlist_node *prev) |
631 | { |
658 | { |
632 | next->next = n->next; |
659 | n->next = prev->next; |
633 | n->next = next; |
660 | prev->next = n; |
Line 634... | Line 661... | ||
634 | next->pprev = &n->next; |
661 | n->pprev = &prev->next; |
635 | 662 | ||
636 | if(next->next) |
663 | if (n->next) |
Line 637... | Line 664... | ||
637 | next->next->pprev = &next->next; |
664 | n->next->pprev = &n->next; |
638 | } |
665 | } |
639 | 666 |