9
0
Fork 0

Add a timeout polling loop convenience wrapper

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
Sascha Hauer 2012-02-08 10:22:52 +01:00
parent 80116a24da
commit 3eb9672818
1 changed files with 19 additions and 0 deletions

View File

@ -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 */