lkml.org 
[lkml]   [2021]   [May]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: [PATCH] tools/nolibc: Implement msleep()
    Hi Mark,

    On Tue, May 11, 2021 at 12:01:59PM +0100, Mark Brown wrote:
    > +static __attribute__((unused))
    > +void msleep(unsigned int msecs)
    > +{
    > + struct timeval my_timeval = { 0, msecs * 1000 };
    > +
    > + sys_select(0, 0, 0, 0, &my_timeval);
    > +}
    > +

    Just a quick question, is there any reason for not keeping most of the
    precision like this and allow applications to use it beyond 4294 seconds
    like this ?

    struct timeval my_timeval = { msecs / 1000, (msecs % 1000) * 1000 };

    Another thing that comes to my mind is that sleep() returns the remaining
    number of seconds if the syscall was interrupted, and I think it could be
    very useful in small tests programs to do the same at the subsecond level
    in simple scheduling loops for example. Copying what we're doing in sleep()
    we could have this:

    if (sys_select(0, 0, 0, 0, &my_timeval) < 0)
    return my_timeval.tv_sec * 1000 + (my_timeval.tv_usec + 999) / 1000;
    else
    return 0;

    And since that's an inline function it will be optimized away if the result
    is not used anyway, resulting in the same code as the void version in this
    case.

    What do you think ?

    Thanks!
    Willy

    \
     
     \ /
      Last update: 2021-05-12 07:35    [W:4.348 / U:0.000 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site