wait: add wait_bit_cleared() helper
authorJens Axboe <jens.axboe@oracle.com>
Sat, 26 Sep 2009 15:31:32 +0000 (17:31 +0200)
committerJens Axboe <jens.axboe@oracle.com>
Sat, 26 Sep 2009 15:31:32 +0000 (17:31 +0200)
Check whether we got woken because our bit cleared or not.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
fs/aio.c
include/linux/wait.h
kernel/wait.c

index 36ee51a6d76157e4e53c339130f996eae4bd84d8..961f62a321091efafdb0fe7dd6279ff52d4c8ab2 100644 (file)
--- 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);
index d6a073f3c3e0c7d26b2ad33551fed6979a1ce170..586198803c0d658145347e12a952d9c32eb3c351 100644 (file)
@@ -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,                              \
index ca0b832d5ff3aa186c12791941ad947d77e2bc96..1c95aa386edc223ffc6a85267d460635bb565e3b 100644 (file)
@@ -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);