From 5c276c0ed3520459bcfe79b264ddf6cc36e805e3 Mon Sep 17 00:00:00 2001 From: Shaohua Li Date: Mon, 12 Aug 2013 10:24:36 +0800 Subject: [PATCH] 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. Signed-off-by: Shaohua Li Signed-off-by: NeilBrown --- include/linux/wait.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/include/linux/wait.h b/include/linux/wait.h index a67fc1635592..d9eff54c69cf 100644 --- a/include/linux/wait.h +++ b/include/linux/wait.h @@ -253,6 +253,42 @@ do { \ __ret; \ }) +#define __wait_event_cmd(wq, condition, cmd1, cmd2) \ +do { \ + DEFINE_WAIT(__wait); \ + \ + for (;;) { \ + prepare_to_wait(&wq, &__wait, TASK_UNINTERRUPTIBLE); \ + if (condition) \ + break; \ + cmd1; \ + schedule(); \ + cmd2; \ + } \ + finish_wait(&wq, &__wait); \ +} while (0) + +/** + * wait_event_cmd - sleep until a condition gets true + * @wq: the waitqueue to wait on + * @condition: a C expression for the event to wait for + * cmd1: the command will be executed before sleep + * cmd2: the command will be executed after sleep + * + * The process is put to sleep (TASK_UNINTERRUPTIBLE) until the + * @condition evaluates to true. The @condition is checked each time + * the waitqueue @wq is woken up. + * + * wake_up() has to be called after changing any variable that could + * change the result of the wait condition. + */ +#define wait_event_cmd(wq, condition, cmd1, cmd2) \ +do { \ + if (condition) \ + break; \ + __wait_event_cmd(wq, condition, cmd1, cmd2); \ +} while (0) + #define __wait_event_interruptible(wq, condition, ret) \ do { \ DEFINE_WAIT(__wait); \ -- 2.39.5