Skip to contentSkip to conversation

add poll_event*()

RFC PATCH In review Nishanth Aravamudan 2 participants 2 messages Mar 3, 2005

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/5 add poll_event*()

Hi,

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 +39 -0
@@ -47,4 +47,43 @@ static inline void ssleep(unsigned int s
 	msleep(seconds * 1000);
 }
 
+/*
+ * poll_event* check if an @cond is true every interval milliseconds, up
+ * to a @timeout maximum, if specified.
+ * The *_interruptible versions will sleep in TASK_INTERRUPTIBLE
+ * (instead of TASK_UNINTERRUPTIBLE) and will return early on signals
+ */
+
+#define poll_event(cond, interval)				\
+do {								\
+	while (cond)						\
+		msleep(interval);				\
+} while(0)
+
+#define poll_event_timeout(cond, interval, timeout)			\
+do {									\
+	unsigned long stop = jiffies + msecs_to_jiffies(timeout);	\
+	while (cond && time_before(jiffies, stop))			\
+		msleep(interval);					\
+} while(0)
+
+#define poll_event_interruptible(cond, interval)		\
+do {								\
+	while (cond) {						\
+		msleep_interruptible(interval);			\
+		if (signal_pending(current))			\
+			break;					\
+	}							\
+} while(0);
+
+#define poll_event_interruptible_timeout(cond, interval, timeout)	\
+do {									\
+	unsigned long stop = jiffies + msecs_to_jiffies(timeout);	\
+	while (cond && time_before(jiffies, stop)) {			\
+		msleep_interruptible(interval);				\
+		if (signal_pending(current))				\
+			break;						\
+	}								\
+} while(0);
+
 #endif /* defined(_LINUX_DELAY_H) */

_______________________________________________
Kernel-janitors mailing list
[email protected]
http://lists.osdl.org/mailman/listinfo/kernel-janitors

#1 lore raw

include/linux/delay.h static inline void ssleep(unsigned int s · line 66

Quoted 6 lines · Nishanth Aravamudan
include/linux/delay.h +4 -0
+#define poll_event_timeout(cond, interval, timeout)			\
+do {									\
+	unsigned long stop = jiffies + msecs_to_jiffies(timeout);	\
+	while (cond && time_before(jiffies, stop))			\

I believe "cond" should be bracketized to avoid surprises.

include/linux/delay.h static inline void ssleep(unsigned int s · line 82

Quoted 7 lines
include/linux/delay.h +6 -0
+		msleep(interval);					\
+} while(0)
 
+#define poll_event_interruptible_timeout(cond, interval, timeout)	\
+do {									\
+	unsigned long stop = jiffies + msecs_to_jiffies(timeout);	\
+	while (cond && time_before(jiffies, stop)) {			\
	      ^^^^^^

include/linux/delay.h static inline void ssleep(unsigned int s · line 77

Quoted 5 lines
include/linux/delay.h +5 -0
+		msleep_interruptible(interval);				\
+		if (signal_pending(current))				\
+			break;						\
+	}								\
+} while(0);

Alexey

_______________________________________________
Kernel-janitors mailing list
[email protected]
http://lists.osdl.org/mailman/listinfo/kernel-janitors