add poll_event*()
RFC PATCH 1/5 add poll_event*()
Quoted 10 lines · Nishanth Aravamudan
Quoted 6 lines · Nishanth Aravamudan
Hi,
Description: Add the
poll_event(),poll_event_timeout(),poll_event_interruptible()andpoll_event_interruptible_timeout()interfaces. These macros encapsulate typical sleeping code usage in a sane way.Macros broken in some subtle & not-so-subtle ways. I will try and get a cleaned-up new version for everyone to examine by tomorrow.
Hopefully this patch fixes some of the issues and makes the interfaces a little better, as recommended by Walter Harms and Alexey Dobriyan. I will update the examples I've given patches 2-5, as appropriate.
A further question, though, should I make the interfaces more similar in code to wait_event*() and have a called version and then that version call and __ version?
Thanks,
Nish
Description: Add the poll_event(), poll_event_timeout(), poll_event_interruptible() and poll_event_interruptible_timeout() interfaces. These macros encapsulate typical sleeping code usage in a sane way.
include/linux/delay.h +77 -0
@@ -47,4 +47,81 @@ static inline void ssleep(unsigned int s msleep(seconds * 1000); } +/* +* poll_event* check if an @condition is true every @interval milliseconds, +* up to a @timeout maximum, if specified, else forever. +* The *_interruptible versions will sleep in TASK_INTERRUPTIBLE +* (instead of TASK_UNINTERRUPTIBLE) and will return early on signals +* Note that these interfaces are distinctly different than +* wait_event*() in two ways: +* 1) No wait-queues +* 2) Specify the time you want to sleep, not when you want to +* wake-up. Thus, callers should not add the current time to +* @timeout before calling, as it will be done by the macro. +*/ + +/* no return value */ +#define poll_event (condition, interval) \ +do { \ + while (!(condition)) \ + msleep(interval); \ +} while(0) + +/* return 0 if condition caused return, -ETIME if timeout */ +#define poll_event_timeout (condition, interval, timeout) \ +({ \ + int __ret = 0; \ + unsigned long stop = jiffies + msecs_to_jiffies(timeout); \ + \ + for (;;) { \ + if (condition) \ + break; \ + msleep(interval); \ + if (time_after(jiffies, stop)) { \ + __ret = -ETIME; \ + break; \ + } \ + } \ + __ret; \ +}) + +/* return 0 if condition caused return, -EINTR if signal */ +#define poll_event_interruptible (condition, interval) \ +({ \ + int __ret = 0; \ + \ + for (;;) { \ + if (condition) \ + break; \ + msleep_interruptible(interval); \ + if (signal_pending(current)) { \ + __ret = -EINTR; \ + break; \ + } \ + } \ + __ret; +}) + +/* return 0 if condition caused return, -EINTR if signal, -ETIME if +* timeout */ +#define poll_event_interruptible_timeout (conditition, interval, timeout) \ +({ \ + int __ret = 0; \ + unsigned long stop = jiffies + msecs_to_jiffies(timeout); \ + \ + for (;;) { \ + if (condition) \ + break; \ + msleep_interruptible(interval); \ + if (signal_pending(current)) { \ + __ret = -EINTR; \ + break; \ + } \ + if (time_after(jiffies, stop)) { \ + __ret = -ETIME; \ + break; \ + } \ + } \ +}) +#endif /* defined(_LINUX_DELAY_H) */
_______________________________________________
Kernel-janitors mailing list
[email protected]
http://lists.osdl.org/mailman/listinfo/kernel-janitors
Quoted 15 lines · Nishanth Aravamudan
Add the
poll_event(),poll_event_timeout(),poll_event_interruptible()andpoll_event_interruptible_timeout()interfaces. These macros encapsulate typical sleeping code usage in a sane way.include/linux/delay.h +8
-0+#define poll_event_interruptible_timeout (conditition, interval, timeout) \ +({ \ + int __ret = 0; \ + unsigned long stop = jiffies + msecs_to_jiffies(timeout); \ + \ + for (;;) { \ + if (condition) \ + break; \
include/linux/delay.h static inline void ssleep(unsigned int s · line 124
Quoted 10 lines
include/linux/delay.h +10
-0+msleep_interruptible (interval); \ +if (signal_pending (current)) { \ + __ret = -EINTR ; \ +break ; \ + } \ +if (time_after (jiffies, stop)) { \ + __ret = -ETIME ; \ +break ; \ + } \ + } \
__ret;
Quoted 1 line
+})
Also, can you add kernel-doc comments? Rules are the same as for functions.
Alexey
_______________________________________________
Kernel-janitors mailing list
[email protected]
http://lists.osdl.org/mailman/listinfo/kernel-janitors
RFC PATCH 1/5 add poll_event*()
In reply to Nishanth AravamudanQuoted 30 lines · Alexey Dobriyan
Quoted 15 lines · Nishanth Aravamudan
Add the
poll_event(),poll_event_timeout(),poll_event_interruptible()andpoll_event_interruptible_timeout()interfaces. These macros encapsulate typical sleeping code usage in a sane way.include/linux/delay.h +8
-0+#define poll_event_interruptible_timeout (conditition, interval, timeout) \ +({ \ + int __ret = 0; \ + unsigned long stop = jiffies + msecs_to_jiffies(timeout); \ + \ + for (;;) { \ + if (condition) \ + break; \include/linux/delay.h
Quoted 10 lines
include/linux/delay.h +10
-0+msleep_interruptible (interval); \ +if (signal_pending (current)) { \ + __ret = -EINTR ; \ +break ; \ + } \ +if (time_after (jiffies, stop)) { \ + __ret = -ETIME ; \ +break ; \ + } \ + } \__ret;
Quoted 3 lines
Quoted 1 line
+})
Also, can you add kernel-doc comments? Rules are the same as for functions.
Code error fixed below.
This is my first try at kernel-doc style comments. Please indicate any problems.
Thanks,
Nish
Description: Add the poll_event(), poll_event_timeout(), poll_event_interruptible() and poll_event_interruptible_timeout() interfaces. These macros encapsulate typical sleeping code usage in a sane way.
include/linux/delay.h +102 -0
@@ -47,4 +47,106 @@ static inline void ssleep(unsigned int s msleep(seconds * 1000); } +/* +* poll_event* check if an @condition is true every @interval milliseconds, +* up to a @timeout maximum, if specified, else forever. +* The *_interruptible versions will sleep in TASK_INTERRUPTIBLE +* (instead of TASK_UNINTERRUPTIBLE) and will return early on signals +* Note that these interfaces are distinctly different than +* wait_event*() in two ways: +* 1) No wait-queues +* 2) Specify the time you want to sleep, not when you want to +* wake-up. Thus, callers should not add the current time to +* @timeout before calling, as it will be done by the macro. +*/ + +/** +* poll_event - check a condition at regular intervals +* @condition: Condition to check +* @interval: Number of milliseconds between checks +*/ +#define poll_event (condition, interval) \ +do { \ + while (!(condition)) \ + msleep(interval); \ +} while(0) + +/** +* poll_event_timeout - check a condition at regular intervals with a timeout +* @condition: Condition to check +* @interval: Number of milliseconds between checks +* @timeout: Maximum total number of milliseconds to take +* returns: 0, if condition caused return +* -ETIME, if timeout +*/ +#define poll_event_timeout (condition, interval, timeout) \ +({ \ + int __ret = 0; \ + unsigned long stop = jiffies + msecs_to_jiffies(timeout); \ + \ + for (;;) { \ + if (condition) \ + break; \ + msleep(interval); \ + if (time_after(jiffies, stop)) { \ + __ret = -ETIME; \ + break; \ + } \ + } \ + __ret; \ +}) + +/** +* poll_event_interruptible - check a condition at regular intervals, returning early on signals +* @condition: Condition to check +* @interval: Number of milliseconds between checks +* returns: 0, if condition caused return +* -EINTR, if a signal +*/ +#define poll_event_interruptible (condition, interval) \ +({ \ + int __ret = 0; \ + \ + for (;;) { \ + if (condition) \ + break; \ + msleep_interruptible(interval); \ + if (signal_pending(current)) { \ + __ret = -EINTR; \ + break; \ + } \ + } \ + __ret; +}) + +/** +* poll_event_interruptible_timeout - check a condition at regular intervals with a timeout, returning early on signals +* @condition: Condition to check +* @interval: Number of milliseconds between checks +* @timeout: Maximum total number of milliseconds to take +* returns 0, if condition caused return +* -EINTR, if a signal +* -ETIME, if timeout +*/ +#define poll_event_interruptible_timeout (conditition, interval, timeout) \ +({ \ + int __ret = 0; \ + unsigned long stop = jiffies + msecs_to_jiffies(timeout); \ + \ + for (;;) { \ + if (condition) \ + break; \ + msleep_interruptible(interval); \ + if (signal_pending(current)) { \ + __ret = -EINTR; \ + break; \ + } \ + if (time_after(jiffies, stop)) { \ + __ret = -ETIME; \ + break; \ + } \ + } \ + __ret; \ +}) +#endif /* defined(_LINUX_DELAY_H) */
_______________________________________________
Kernel-janitors mailing list
[email protected]
http://lists.osdl.org/mailman/listinfo/kernel-janitors