diff options
| author | William Lee Irwin III <wli@holomorphy.com> | 2004-10-18 17:59:53 -0700 |
|---|---|---|
| committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2004-10-18 17:59:53 -0700 |
| commit | baa896b3ded47a7f6a401267f5995dcc09d5d5d4 (patch) | |
| tree | c0d13ea74dd5342ce61bc9f8dd42762707bca262 /kernel | |
| parent | fd4d36bf0d54e0b020b8ffeddf7552562eab17c5 (diff) | |
[PATCH] consolidate bit waiting code patterns
Consolidate bit waiting code patterns for page waitqueues using
__wait_on_bit() and __wait_on_bit_lock().
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'kernel')
| -rw-r--r-- | kernel/wait.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/kernel/wait.c b/kernel/wait.c index 78256a812ca0..29057f707dbd 100644 --- a/kernel/wait.c +++ b/kernel/wait.c @@ -143,6 +143,43 @@ int wake_bit_function(wait_queue_t *wait, unsigned mode, int sync, void *arg) } EXPORT_SYMBOL(wake_bit_function); +/* + * To allow interruptible waiting and asynchronous (i.e. nonblocking) + * waiting, the actions of __wait_on_bit() and __wait_on_bit_lock() are + * permitted return codes. Nonzero return codes halt waiting and return. + */ +int __sched fastcall +__wait_on_bit(wait_queue_head_t *wq, struct wait_bit_queue *q, + void *word, int bit, int (*action)(void *), unsigned mode) +{ + int ret = 0; + + prepare_to_wait(wq, &q->wait, mode); + if (test_bit(bit, word)) + ret = (*action)(word); + finish_wait(wq, &q->wait); + return ret; +} +EXPORT_SYMBOL(__wait_on_bit); + +int __sched fastcall +__wait_on_bit_lock(wait_queue_head_t *wq, struct wait_bit_queue *q, + void *word, int bit, int (*action)(void *), unsigned mode) +{ + int ret = 0; + + while (test_and_set_bit(bit, word)) { + prepare_to_wait_exclusive(wq, &q->wait, mode); + if (test_bit(bit, word)) { + if ((ret = (*action)(word))) + break; + } + } + finish_wait(wq, &q->wait); + return ret; +} +EXPORT_SYMBOL(__wait_on_bit_lock); + void fastcall __wake_up_bit(wait_queue_head_t *wq, void *word, int bit) { struct wait_bit_key key = __WAIT_BIT_KEY_INITIALIZER(word, bit); |
