[Nut-upsdev] patch: Replace many usleep and some sleep calls with nanosleep
Stuart D. Gathman
stuart at bmsi.com
Mon Oct 3 18:52:40 UTC 2011
On Mon, 3 Oct 2011, Regid Ichira wrote:
> I am not sure I understood:
> 1. Are you saying that usleep is already defined in terms of nanosleep?
Most likely, yes.
> Where?
Standard library
> 2. Are you suggesting to keep the current code, and use something like
> In any case, I think that using nanosleep directly, without any intermediate functions, is more readable.
If calling nanosleep was actually just a matter of nanosleep(time),
I would agree. However, it is actually a matter of
struct timespec delay = {0, 250e6}; nanosleep(&delay, NULL);
Which is rather wordy, and doesn't include checking for interruption
be signal (if sleeping the full amount is important).
int u_sleep(long time) {
struct timespec delay = {time/1000000, (time%1000000) * 1000};
return nanosleep(&delay, NULL);
/* FIXME: We should sleep remaining delay if interrupted by signal
to fully emulate usleep.
Otherwise, should we return remaining time in microseconds?
FIXME: For UPS driver purposes, millisecond precision would be more
convenient. Perhaps this should be millisleep.
*/
}
--
Stuart D. Gathman <stuart at bmsi.com>
Business Management Systems Inc. Phone: 703 591-0911 Fax: 703 591-6154
"Confutatis maledictis, flammis acribus addictis" - background song for
a Microsoft sponsored "Where do you want to go from here?" commercial.
More information about the Nut-upsdev
mailing list