aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/linux/completion.h45
1 files changed, 45 insertions, 0 deletions
diff --git a/include/linux/completion.h b/include/linux/completion.h
index d2961b66d53d..57faa60de9bd 100644
--- a/include/linux/completion.h
+++ b/include/linux/completion.h
@@ -55,4 +55,49 @@ extern void complete_all(struct completion *);
55 55
56#define INIT_COMPLETION(x) ((x).done = 0) 56#define INIT_COMPLETION(x) ((x).done = 0)
57 57
58
59/**
60 * try_wait_for_completion - try to decrement a completion without blocking
61 * @x: completion structure
62 *
63 * Returns: 0 if a decrement cannot be done without blocking
64 * 1 if a decrement succeeded.
65 *
66 * If a completion is being used as a counting completion,
67 * attempt to decrement the counter without blocking. This
68 * enables us to avoid waiting if the resource the completion
69 * is protecting is not available.
70 */
71static inline bool try_wait_for_completion(struct completion *x)
72{
73 int ret = 1;
74
75 spin_lock_irq(&x->wait.lock);
76 if (!x->done)
77 ret = 0;
78 else
79 x->done--;
80 spin_unlock_irq(&x->wait.lock);
81 return ret;
82}
83
84/**
85 * completion_done - Test to see if a completion has any waiters
86 * @x: completion structure
87 *
88 * Returns: 0 if there are waiters (wait_for_completion() in progress)
89 * 1 if there are no waiters.
90 *
91 */
92static inline bool completion_done(struct completion *x)
93{
94 int ret = 1;
95
96 spin_lock_irq(&x->wait.lock);
97 if (!x->done)
98 ret = 0;
99 spin_unlock_irq(&x->wait.lock);
100 return ret;
101}
102
58#endif 103#endif