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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



G'day,

On 8/10/06, Andrew James Wade <[email protected]> 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 [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux