From 38d25eaa96ea02ec6b83e1165bc246657fd89eda Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Sat, 26 Sep 2009 17:31:32 +0200 Subject: [PATCH] wait: add wait_bit_cleared() helper Check whether we got woken because our bit cleared or not. Signed-off-by: Jens Axboe --- fs/aio.c | 3 +-- include/linux/wait.h | 10 ++++++++++ kernel/wait.c | 8 +++----- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/fs/aio.c b/fs/aio.c index 36ee51a6d761..961f62a32109 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -1533,8 +1533,7 @@ static int aio_wake_function(wait_queue_t *wait, unsigned mode, = container_of(wait, struct wait_bit_queue, wait); struct kiocb *iocb = container_of(wb, struct kiocb, ki_wq); - if (wb->key.flags != key->flags || wb->key.bit_nr != key->bit_nr || - test_bit(key->bit_nr, key->flags)) + if (!wait_bit_cleared(wb, key)) return 0; list_del_init(&wait->task_list); diff --git a/include/linux/wait.h b/include/linux/wait.h index d6a073f3c3e0..586198803c0d 100644 --- a/include/linux/wait.h +++ b/include/linux/wait.h @@ -457,6 +457,16 @@ void abort_exclusive_wait(wait_queue_head_t *q, wait_queue_t *wait, int autoremove_wake_function(wait_queue_t *wait, unsigned mode, int sync, void *key); int wake_bit_function(wait_queue_t *wait, unsigned mode, int sync, void *key); +static inline int wait_bit_cleared(struct wait_bit_queue *wb, + struct wait_bit_key *key) +{ + if (wb->key.flags != key->flags || wb->key.bit_nr != key->bit_nr || + test_bit(key->bit_nr, key->flags)) + return 0; + + return 1; +} + #define DEFINE_WAIT_FUNC(name, function) \ wait_queue_t name = { \ .private = current, \ diff --git a/kernel/wait.c b/kernel/wait.c index ca0b832d5ff3..1c95aa386edc 100644 --- a/kernel/wait.c +++ b/kernel/wait.c @@ -178,12 +178,10 @@ int wake_bit_function(wait_queue_t *wait, unsigned mode, int sync, void *arg) struct wait_bit_queue *wait_bit = container_of(wait, struct wait_bit_queue, wait); - if (wait_bit->key.flags != key->flags || - wait_bit->key.bit_nr != key->bit_nr || - test_bit(key->bit_nr, key->flags)) + if (!wait_bit_cleared(wait_bit, key)) return 0; - else - return autoremove_wake_function(wait, mode, sync, key); + + return autoremove_wake_function(wait, mode, sync, key); } EXPORT_SYMBOL(wake_bit_function); -- 2.25.1