From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752658AbdHIXre (ORCPT ); Wed, 9 Aug 2017 19:47:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:40838 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752169AbdHIXqm (ORCPT ); Wed, 9 Aug 2017 19:46:42 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F1C4F22C8B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=mcgrof@kernel.org From: "Luis R. Rodriguez" To: akpm@linux-foundation.org Cc: mingo@redhat.com, peterz@infradead.org, keescook@chromium.org, dmitry.torokhov@gmail.com, jeyu@redhat.com, rusty@rustcorp.com.au, mmarek@suse.com, pmladek@suse.com, mbenes@suse.cz, jpoimboe@redhat.com, ebiederm@xmission.com, shuah@kernel.org, matt.redfearn@imgtec.com, dan.carpenter@oracle.com, colin.king@canonical.com, danielmentz@google.com, dcb314@hotmail.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, "Luis R. Rodriguez" Subject: [PATCH 1/3] wait: add wait_event_killable_timeout() Date: Wed, 9 Aug 2017 16:46:33 -0700 Message-Id: <20170809234635.13443-2-mcgrof@kernel.org> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20170809234635.13443-1-mcgrof@kernel.org> References: <20170809234635.13443-1-mcgrof@kernel.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This wait is similar to wait_event_interruptable_timeout() but only accepts SIGKILL interrupt signal. Other signals are ignored. Signed-off-by: Luis R. Rodriguez --- include/linux/wait.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/include/linux/wait.h b/include/linux/wait.h index 5b74e36c0ca8..dc19880c02f5 100644 --- a/include/linux/wait.h +++ b/include/linux/wait.h @@ -757,6 +757,43 @@ extern int do_wait_intr_irq(wait_queue_head_t *, wait_queue_entry_t *); __ret; \ }) +#define __wait_event_killable_timeout(wq_head, condition, timeout) \ + ___wait_event(wq_head, ___wait_cond_timeout(condition), \ + TASK_KILLABLE, 0, timeout, \ + __ret = schedule_timeout(__ret)) + +/** + * wait_event_killable_timeout - sleep until a condition gets true or a timeout elapses + * @wq_head: the waitqueue to wait on + * @condition: a C expression for the event to wait for + * @timeout: timeout, in jiffies + * + * The process is put to sleep (TASK_KILLABLE) until the + * @condition evaluates to true or a kill signal is received. + * The @condition is checked each time the waitqueue @wq_head is woken up. + * + * wake_up() has to be called after changing any variable that could + * change the result of the wait condition. + * + * Returns: + * 0 if the @condition evaluated to %false after the @timeout elapsed, + * 1 if the @condition evaluated to %true after the @timeout elapsed, + * the remaining jiffies (at least 1) if the @condition evaluated + * to %true before the @timeout elapsed, or -%ERESTARTSYS if it was + * interrupted by a kill signal. + * + * Only kill signals interrupt this process. + */ +#define wait_event_killable_timeout(wq_head, condition, timeout) \ +({ \ + long __ret = timeout; \ + might_sleep(); \ + if (!___wait_cond_timeout(condition)) \ + __ret = __wait_event_killable_timeout(wq_head, \ + condition, timeout); \ + __ret; \ +}) + #define __wait_event_lock_irq(wq_head, condition, lock, cmd) \ (void)___wait_event(wq_head, condition, TASK_UNINTERRUPTIBLE, 0, 0, \ -- 2.14.0