Re: [KJ] [patch] fix common mistake in polling loops

From: Darren Jenkins
Date: Wed Aug 09 2006 - 21:08:45 EST


On 8/10/06, Andrew James Wade <andrew.j.wade@xxxxxxxxx> wrote:
You're getting duplicated code there. That'll be an issue in more
complex loops. How about:

unsigned long timeout = jiffies + HZ/2;
int timeup = 0;

for (;;;) {
if (ready())
return 0;
if (timeup)
timeup = time_after(timeout, jiffies);
... timeout ...

Nice, looks better than my idea.
Removes the code duplication and reduces complexity(a little) at the
cost of an extra variable.

The only Nitpick is

- int timeup = 0;
+ unsigned char timeup = 0;

Andrew Wade

Darren J.
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at