From f1c5327533dcad53d3f43a021d15990c9be6492d Mon Sep 17 00:00:00 2001 From: David Chinner Date: Wed, 13 Aug 2008 16:40:43 +1000 Subject: [PATCH] --- yaml --- r: 108326 b: refs/heads/master c: 39d2f1ab2a36ac527a6c41cfe689f50c239eaca3 h: refs/heads/master v: v3 --- [refs] | 2 +- trunk/include/linux/completion.h | 45 ++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/[refs] b/[refs] index 9b33461a7e00..13edce3a88fd 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: b4dd330b9e0c9c78ebff754e72563b148f05e9e0 +refs/heads/master: 39d2f1ab2a36ac527a6c41cfe689f50c239eaca3 diff --git a/trunk/include/linux/completion.h b/trunk/include/linux/completion.h index d2961b66d53d..57faa60de9bd 100644 --- a/trunk/include/linux/completion.h +++ b/trunk/include/linux/completion.h @@ -55,4 +55,49 @@ extern void complete_all(struct completion *); #define INIT_COMPLETION(x) ((x).done = 0) + +/** + * try_wait_for_completion - try to decrement a completion without blocking + * @x: completion structure + * + * Returns: 0 if a decrement cannot be done without blocking + * 1 if a decrement succeeded. + * + * If a completion is being used as a counting completion, + * attempt to decrement the counter without blocking. This + * enables us to avoid waiting if the resource the completion + * is protecting is not available. + */ +static inline bool try_wait_for_completion(struct completion *x) +{ + int ret = 1; + + spin_lock_irq(&x->wait.lock); + if (!x->done) + ret = 0; + else + x->done--; + spin_unlock_irq(&x->wait.lock); + return ret; +} + +/** + * completion_done - Test to see if a completion has any waiters + * @x: completion structure + * + * Returns: 0 if there are waiters (wait_for_completion() in progress) + * 1 if there are no waiters. + * + */ +static inline bool completion_done(struct completion *x) +{ + int ret = 1; + + spin_lock_irq(&x->wait.lock); + if (!x->done) + ret = 0; + spin_unlock_irq(&x->wait.lock); + return ret; +} + #endif