* Missing wait_event_killable_timeout?
@ 2015-10-21 7:20 Kilian, Jens
2015-10-21 14:08 ` Peter Hurley
0 siblings, 1 reply; 2+ messages in thread
From: Kilian, Jens @ 2015-10-21 7:20 UTC (permalink / raw)
To: linux-kernel@vger.kernel.org
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="utf-8", Size: 2355 bytes --]
I'd like to use a version of wait_event_killable() with a timeout, but it seems to be missing? I found a mention of it in a recent LKML message though:
https://lkml.org/lkml/2015/10/14/337
Does this patch look reasonable?
diff --git a/include/linux/wait.h b/include/linux/wait.h
index 1e1bf9f..8419986 100644
--- a/include/linux/wait.h
+++ b/include/linux/wait.h
@@ -738,6 +738,41 @@ do { \
__ret; \
})
+#define __wait_event_killable_timeout(wq, condition, timeout) \
+ ___wait_event(wq, ___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: 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 signal is received.
+ * 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.
+ *
+ * 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 signal.
+ */
+#define wait_event_killable_timeout(wq, condition, timeout) \
+({ \
+ long __ret = timeout; \
+ might_sleep(); \
+ if (!___wait_cond_timeout(condition)) \
+ __ret = __wait_event_killable_timeout(wq, \
+ condition, timeout); \
+ __ret; \
+})
+
#define __wait_event_lock_irq(wq, condition, lock, cmd) \
(void)___wait_event(wq, condition, TASK_UNINTERRUPTIBLE, 0, 0, \
--
Jens Kilian
Advantest Europe GmbH
Managing Directors / Geschaeftsfuehrer: Josef Schraetzenstaller, Hans-Juergen Wagner
Vorsitzender des Aufsichtsrats / Chairman of the Supervisory Board: Hiroshi Nakamura
Commercial Court / Handelsregister: Muenchen HRB 71083, Seat / Sitz: Muenchen
ÿôèº{.nÇ+·®+%Ëÿ±éݶ\x17¥wÿº{.nÇ+·¥{±þG«éÿ{ayº\x1dÊÚë,j\a¢f£¢·hïêÿêçz_è®\x03(éÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?¨èÚ&£ø§~á¶iOæ¬z·vØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?I¥
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: Missing wait_event_killable_timeout?
2015-10-21 7:20 Missing wait_event_killable_timeout? Kilian, Jens
@ 2015-10-21 14:08 ` Peter Hurley
0 siblings, 0 replies; 2+ messages in thread
From: Peter Hurley @ 2015-10-21 14:08 UTC (permalink / raw)
To: Kilian, Jens, linux-kernel@vger.kernel.org
Hi Jens,
On 10/21/2015 03:20 AM, Kilian, Jens wrote:
> I'd like to use a version of wait_event_killable() with a timeout, but it seems to be missing? I found a mention of it in a recent LKML message though:
>
> https://lkml.org/lkml/2015/10/14/337
>
> Does this patch look reasonable?
Where is the in-tree user? Without that, someone will notice this
isn't being used and will remove it.
Regards,
Peter Hurley
> diff --git a/include/linux/wait.h b/include/linux/wait.h
> index 1e1bf9f..8419986 100644
> --- a/include/linux/wait.h
> +++ b/include/linux/wait.h
> @@ -738,6 +738,41 @@ do { \
> __ret; \
> })
>
> +#define __wait_event_killable_timeout(wq, condition, timeout) \
> + ___wait_event(wq, ___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: 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 signal is received.
> + * 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.
> + *
> + * 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 signal.
> + */
> +#define wait_event_killable_timeout(wq, condition, timeout) \
> +({ \
> + long __ret = timeout; \
> + might_sleep(); \
> + if (!___wait_cond_timeout(condition)) \
> + __ret = __wait_event_killable_timeout(wq, \
> + condition, timeout); \
> + __ret; \
> +})
> +
>
> #define __wait_event_lock_irq(wq, condition, lock, cmd) \
> (void)___wait_event(wq, condition, TASK_UNINTERRUPTIBLE, 0, 0, \
>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-10-21 14:08 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-21 7:20 Missing wait_event_killable_timeout? Kilian, Jens
2015-10-21 14:08 ` Peter Hurley
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).