Messages in this thread | | | Date | Thu, 10 Aug 2006 11:11:06 +1000 | From | "Darren Jenkins" <> | Subject | Re: [KJ] [patch] fix common mistake in polling loops |
| |
G'day,
On 8/10/06, Andrew James Wade <andrew.j.wade@gmail.com> 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) > break; > msleep(10); > 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@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
| |