diff options
Diffstat (limited to 'include/linux')
| -rw-r--r-- | include/linux/wait.h | 164 |
1 files changed, 164 insertions, 0 deletions
diff --git a/include/linux/wait.h b/include/linux/wait.h index 168dfe122dd..7cb64d4b499 100644 --- a/include/linux/wait.h +++ b/include/linux/wait.h | |||
| @@ -550,6 +550,170 @@ do { \ | |||
| 550 | __ret; \ | 550 | __ret; \ |
| 551 | }) | 551 | }) |
| 552 | 552 | ||
| 553 | |||
| 554 | #define __wait_event_lock_irq(wq, condition, lock, cmd) \ | ||
| 555 | do { \ | ||
| 556 | DEFINE_WAIT(__wait); \ | ||
| 557 | \ | ||
| 558 | for (;;) { \ | ||
| 559 | prepare_to_wait(&wq, &__wait, TASK_UNINTERRUPTIBLE); \ | ||
| 560 | if (condition) \ | ||
| 561 | break; \ | ||
| 562 | spin_unlock_irq(&lock); \ | ||
| 563 | cmd; \ | ||
| 564 | schedule(); \ | ||
| 565 | spin_lock_irq(&lock); \ | ||
| 566 | } \ | ||
| 567 | finish_wait(&wq, &__wait); \ | ||
| 568 | } while (0) | ||
| 569 | |||
| 570 | /** | ||
| 571 | * wait_event_lock_irq_cmd - sleep until a condition gets true. The | ||
| 572 | * condition is checked under the lock. This | ||
| 573 | * is expected to be called with the lock | ||
| 574 | * taken. | ||
| 575 | * @wq: the waitqueue to wait on | ||
| 576 | * @condition: a C expression for the event to wait for | ||
| 577 | * @lock: a locked spinlock_t, which will be released before cmd | ||
| 578 | * and schedule() and reacquired afterwards. | ||
| 579 | * @cmd: a command which is invoked outside the critical section before | ||
| 580 | * sleep | ||
| 581 | * | ||
| 582 | * The process is put to sleep (TASK_UNINTERRUPTIBLE) until the | ||
| 583 | * @condition evaluates to true. The @condition is checked each time | ||
| 584 | * the waitqueue @wq is woken up. | ||
| 585 | * | ||
| 586 | * wake_up() has to be called after changing any variable that could | ||
| 587 | * change the result of the wait condition. | ||
| 588 | * | ||
| 589 | * This is supposed to be called while holding the lock. The lock is | ||
| 590 | * dropped before invoking the cmd and going to sleep and is reacquired | ||
| 591 | * afterwards. | ||
| 592 | */ | ||
| 593 | #define wait_event_lock_irq_cmd(wq, condition, lock, cmd) \ | ||
| 594 | do { \ | ||
| 595 | if (condition) \ | ||
| 596 | break; \ | ||
| 597 | __wait_event_lock_irq(wq, condition, lock, cmd); \ | ||
| 598 | } while (0) | ||
| 599 | |||
| 600 | /** | ||
| 601 | * wait_event_lock_irq - sleep until a condition gets true. The | ||
| 602 | * condition is checked under the lock. This | ||
| 603 | * is expected to be called with the lock | ||
| 604 | * taken. | ||
| 605 | * @wq: the waitqueue to wait on | ||
| 606 | * @condition: a C expression for the event to wait for | ||
| 607 | * @lock: a locked spinlock_t, which will be released before schedule() | ||
| 608 | * and reacquired afterwards. | ||
| 609 | * | ||
| 610 | * The process is put to sleep (TASK_UNINTERRUPTIBLE) until the | ||
| 611 | * @condition evaluates to true. The @condition is checked each time | ||
| 612 | * the waitqueue @wq is woken up. | ||
| 613 | * | ||
| 614 | * wake_up() has to be called after changing any variable that could | ||
| 615 | * change the result of the wait condition. | ||
| 616 | * | ||
| 617 | * This is supposed to be called while holding the lock. The lock is | ||
| 618 | * dropped before going to sleep and is reacquired afterwards. | ||
| 619 | */ | ||
| 620 | #define wait_event_lock_irq(wq, condition, lock) \ | ||
| 621 | do { \ | ||
| 622 | if (condition) \ | ||
| 623 | break; \ | ||
| 624 | __wait_event_lock_irq(wq, condition, lock, ); \ | ||
| 625 | } while (0) | ||
| 626 | |||
| 627 | |||
| 628 | #define __wait_event_interruptible_lock_irq(wq, condition, \ | ||
| 629 | lock, ret, cmd) \ | ||
| 630 | do { \ | ||
| 631 | DEFINE_WAIT(__wait); \ | ||
| 632 | \ | ||
| 633 | for (;;) { \ | ||
| 634 | prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE); \ | ||
| 635 | if (condition) \ | ||
| 636 | break; \ | ||
| 637 | if (signal_pending(current)) { \ | ||
| 638 | ret = -ERESTARTSYS; \ | ||
| 639 | break; \ | ||
| 640 | } \ | ||
| 641 | spin_unlock_irq(&lock); \ | ||
| 642 | cmd; \ | ||
| 643 | schedule(); \ | ||
| 644 | spin_lock_irq(&lock); \ | ||
| 645 | } \ | ||
| 646 | finish_wait(&wq, &__wait); \ | ||
| 647 | } while (0) | ||
| 648 | |||
| 649 | /** | ||
| 650 | * wait_event_interruptible_lock_irq_cmd - sleep until a condition gets true. | ||
| 651 | * The condition is checked under the lock. This is expected to | ||
| 652 | * be called with the lock taken. | ||
| 653 | * @wq: the waitqueue to wait on | ||
| 654 | * @condition: a C expression for the event to wait for | ||
| 655 | * @lock: a locked spinlock_t, which will be released before cmd and | ||
| 656 | * schedule() and reacquired afterwards. | ||
| 657 | * @cmd: a command which is invoked outside the critical section before | ||
| 658 | * sleep | ||
| 659 | * | ||
| 660 | * The process is put to sleep (TASK_INTERRUPTIBLE) until the | ||
| 661 | * @condition evaluates to true or a signal is received. The @condition is | ||
| 662 | * checked each time the waitqueue @wq is woken up. | ||
| 663 | * | ||
| 664 | * wake_up() has to be called after changing any variable that could | ||
| 665 | * change the result of the wait condition. | ||
| 666 | * | ||
| 667 | * This is supposed to be called while holding the lock. The lock is | ||
| 668 | * dropped before invoking the cmd and going to sleep and is reacquired | ||
| 669 | * afterwards. | ||
| 670 | * | ||
| 671 | * The macro will return -ERESTARTSYS if it was interrupted by a signal | ||
| 672 | * and 0 if @condition evaluated to true. | ||
| 673 | */ | ||
| 674 | #define wait_event_interruptible_lock_irq_cmd(wq, condition, lock, cmd) \ | ||
| 675 | ({ \ | ||
| 676 | int __ret = 0; \ | ||
| 677 | \ | ||
| 678 | if (!(condition)) \ | ||
| 679 | __wait_event_interruptible_lock_irq(wq, condition, \ | ||
| 680 | lock, __ret, cmd); \ | ||
| 681 | __ret; \ | ||
| 682 | }) | ||
| 683 | |||
| 684 | /** | ||
| 685 | * wait_event_interruptible_lock_irq - sleep until a condition gets true. | ||
| 686 | * The condition is checked under the lock. This is expected | ||
| 687 | * to be called with the lock taken. | ||
| 688 | * @wq: the waitqueue to wait on | ||
| 689 | * @condition: a C expression for the event to wait for | ||
| 690 | * @lock: a locked spinlock_t, which will be released before schedule() | ||
| 691 | * and reacquired afterwards. | ||
| 692 | * | ||
| 693 | * The process is put to sleep (TASK_INTERRUPTIBLE) until the | ||
| 694 | * @condition evaluates to true or signal is received. The @condition is | ||
| 695 | * checked each time the waitqueue @wq is woken up. | ||
| 696 | * | ||
| 697 | * wake_up() has to be called after changing any variable that could | ||
| 698 | * change the result of the wait condition. | ||
| 699 | * | ||
| 700 | * This is supposed to be called while holding the lock. The lock is | ||
| 701 | * dropped before going to sleep and is reacquired afterwards. | ||
| 702 | * | ||
| 703 | * The macro will return -ERESTARTSYS if it was interrupted by a signal | ||
| 704 | * and 0 if @condition evaluated to true. | ||
| 705 | */ | ||
| 706 | #define wait_event_interruptible_lock_irq(wq, condition, lock) \ | ||
| 707 | ({ \ | ||
| 708 | int __ret = 0; \ | ||
| 709 | \ | ||
| 710 | if (!(condition)) \ | ||
| 711 | __wait_event_interruptible_lock_irq(wq, condition, \ | ||
| 712 | lock, __ret, ); \ | ||
| 713 | __ret; \ | ||
| 714 | }) | ||
| 715 | |||
| 716 | |||
| 553 | /* | 717 | /* |
| 554 | * These are the old interfaces to sleep waiting for an event. | 718 | * These are the old interfaces to sleep waiting for an event. |
| 555 | * They are racy. DO NOT use them, use the wait_event* interfaces above. | 719 | * They are racy. DO NOT use them, use the wait_event* interfaces above. |
