diff options
author | Shaohua Li <shli@kernel.org> | 2013-11-13 23:16:16 -0500 |
---|---|---|
committer | NeilBrown <neilb@suse.de> | 2013-11-13 23:16:16 -0500 |
commit | 82e06c811163c4d853ed335d56c3378088bc89cc (patch) | |
tree | 83ca8da3fcda9ebb1ec6ce5bb275533d8d4bd952 | |
parent | ba8805b97320416e7c5bb8f55d2bd06d5c319e7d (diff) |
wait: add wait_event_cmd()
Add a new API wait_event_cmd(). It's a variant of wait_even() with two
commands executed. One is executed before sleep, another after sleep.
Modified to match use wait.h approach based on suggestion by
Peter Zijlstra <peterz@infradead.org> - neilb
Signed-off-by: Shaohua Li <shli@fusionio.com>
Signed-off-by: NeilBrown <neilb@suse.de>
-rw-r--r-- | include/linux/wait.h | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/include/linux/wait.h b/include/linux/wait.h index 61939ba30aa0..eaa00b10abaa 100644 --- a/include/linux/wait.h +++ b/include/linux/wait.h | |||
@@ -278,6 +278,31 @@ do { \ | |||
278 | __ret; \ | 278 | __ret; \ |
279 | }) | 279 | }) |
280 | 280 | ||
281 | #define __wait_event_cmd(wq, condition, cmd1, cmd2) \ | ||
282 | (void)___wait_event(wq, condition, TASK_UNINTERRUPTIBLE, 0, 0, \ | ||
283 | cmd1; schedule(); cmd2) | ||
284 | |||
285 | /** | ||
286 | * wait_event_cmd - sleep until a condition gets true | ||
287 | * @wq: the waitqueue to wait on | ||
288 | * @condition: a C expression for the event to wait for | ||
289 | * cmd1: the command will be executed before sleep | ||
290 | * cmd2: the command will be executed after sleep | ||
291 | * | ||
292 | * The process is put to sleep (TASK_UNINTERRUPTIBLE) until the | ||
293 | * @condition evaluates to true. The @condition is checked each time | ||
294 | * the waitqueue @wq is woken up. | ||
295 | * | ||
296 | * wake_up() has to be called after changing any variable that could | ||
297 | * change the result of the wait condition. | ||
298 | */ | ||
299 | #define wait_event_cmd(wq, condition, cmd1, cmd2) \ | ||
300 | do { \ | ||
301 | if (condition) \ | ||
302 | break; \ | ||
303 | __wait_event_cmd(wq, condition, cmd1, cmd2); \ | ||
304 | } while (0) | ||
305 | |||
281 | #define __wait_event_interruptible(wq, condition) \ | 306 | #define __wait_event_interruptible(wq, condition) \ |
282 | ___wait_event(wq, condition, TASK_INTERRUPTIBLE, 0, 0, \ | 307 | ___wait_event(wq, condition, TASK_INTERRUPTIBLE, 0, 0, \ |
283 | schedule()) | 308 | schedule()) |