summaryrefslogtreecommitdiffstats
path: root/include/clock.h
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2012-02-08 10:22:52 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2012-02-09 14:35:06 +0100
commit3eb96728182b9b48ee6902c3b87c9e6433d1f25e (patch)
tree332585c9b17d67dd554b9321c4ada4c543e90b00 /include/clock.h
parent80116a24dacd145ab4b00ad24688807dea7eeda4 (diff)
downloadbarebox-3eb96728182b9b48ee6902c3b87c9e6433d1f25e.tar.gz
barebox-3eb96728182b9b48ee6902c3b87c9e6433d1f25e.tar.xz
Add a timeout polling loop convenience wrapper
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'include/clock.h')
-rw-r--r--include/clock.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/include/clock.h b/include/clock.h
index af5b9395bd..123f8747a8 100644
--- a/include/clock.h
+++ b/include/clock.h
@@ -40,4 +40,23 @@ void mdelay(unsigned long msecs);
#define MSECOND ((uint64_t)(1000 * 1000))
#define USECOND ((uint64_t)(1000))
+/*
+ * Convenience wrapper to implement a typical polling loop with
+ * timeout. returns 0 if the condition became true within the
+ * timeout or -ETIMEDOUT otherwise
+ */
+#define wait_on_timeout(timeout, condition) \
+({ \
+ int __ret = 0; \
+ uint64_t __to_start = get_time_ns(); \
+ \
+ while (!(condition)) { \
+ if (is_timeout(__to_start, (timeout))) { \
+ __ret = -ETIMEDOUT; \
+ break; \
+ } \
+ } \
+ __ret; \
+})
+
#endif /* CLOCK_H */