Commit 4ef83d4e authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Make TIM_sleep() use nanosleep(2) if we have it.

Make it respect Open Groups 1 second limit on usleep if not.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@3978 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 1bddcb7d
......@@ -108,6 +108,7 @@ AC_CHECK_FUNCS([fmtcheck])
AC_CHECK_FUNCS([getdtablesize])
AC_CHECK_FUNCS([abort2])
AC_CHECK_FUNCS([timegm])
AC_CHECK_FUNCS([nanosleep])
save_LIBS="${LIBS}"
LIBS="${PTHREAD_LIBS}"
......
......@@ -152,10 +152,20 @@ TIM_parse(const char *p)
void
TIM_sleep(double t)
{
if (t > 100.0)
(void)sleep((int)round(t));
else
(void)usleep((int)round(t * 1e6));
struct timespec ts;
ts.tv_sec = floor(t);
ts.tv_nsec = floor((t - ts.tv_sec) * 1e9);
#ifdef HAVE_NANOSLEEP
(void)nanosleep(&ts, NULL);
#else
if (ts.tv_sec > 0)
(void)sleep(ts.tv_sec);
ts.tv_nsec /= 1000;
if (ts.tv_nsec > 0)
(void)usleep(ts.tv_nsec);
#endif
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment