lkml.org 
[lkml]   [2006]   [Aug]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: [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/

    \
     
     \ /
      Last update: 2006-08-10 03:13    [W:0.020 / U:1.228 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site