[Nut-upsdev] patch: Replace many usleep and some sleep calls with nanosleep
Regid Ichira
regid23 at yahoo.com
Sun Nov 13 20:32:48 UTC 2011
--- On Sat, 11/12/11, Arnaud Quette <aquette.dev at gmail.com> wrote:
> >>> - usleep(250000);
>
> >>> + struct timespec delay = {0, 250e6}; nanosleep(&delay, NULL);
>
> >> Would it be better to define a local version of usleep in terms of
> >> nanosleep? I suspect the library version already does that, but if the
> >> library version is going away, a local version is much more concise and
> >> readable than calling nanosleep directly. If there are concerns about
> >> linking, the local version could be, e.g, u_sleep, since all the calls
> >> are getting touched anyway.
>
> > Using AC_REPLACE_FUNCS(... usleep ...) in configure.in and providing a
> > common/usleep.c->usleep() replacement implementation, in case the
> > system doesn't provide it, is a better way to go. At least for now.
> > That way, we avoid regression, while supporting systems that do not
> > provide usleep.
>
> What would be more worthwhile (IMHO) is to modify the code to make use
> of the remaining time returned by nanosleep. Otherwise, I am not sure
> I see the benefit of this change.
>
Does that summarize to:
1. Have a valid C code for:
int
substitution_usleep(delay, remaining_time)
{
if configure claims nanosleep is available {
call nanosleep to sleep delay;
if nanosleep was interrupted
arrange for the caller to be able to get back the remaining_time;
return the code that (real)usleep would have returned;
}
else return (real)usleep(delay);
};
in common/substitution_usleep.c
2. With the help of configure, arrange to call substitution_usleep
instead of (real)usleep
?
More information about the Nut-upsdev
mailing list