r3998 - in branches/2.0/varnish-cache: . lib/libvarnish
tfheen at projects.linpro.no
tfheen at projects.linpro.no
Mon Mar 23 15:45:32 CET 2009
Author: tfheen
Date: 2009-03-23 15:45:32 +0100 (Mon, 23 Mar 2009)
New Revision: 3998
Modified:
branches/2.0/varnish-cache/configure.ac
branches/2.0/varnish-cache/lib/libvarnish/time.c
Log:
Merge r3978: Make TIM_sleep() use nanosleep(2) if we have it.
Make it respect Open Groups 1 second limit on usleep if not.
Modified: branches/2.0/varnish-cache/configure.ac
===================================================================
--- branches/2.0/varnish-cache/configure.ac 2009-03-23 14:40:52 UTC (rev 3997)
+++ branches/2.0/varnish-cache/configure.ac 2009-03-23 14:45:32 UTC (rev 3998)
@@ -108,6 +108,7 @@
AC_CHECK_FUNCS([getdtablesize])
AC_CHECK_FUNCS([abort2])
AC_CHECK_FUNCS([timegm])
+AC_CHECK_FUNCS([nanosleep])
save_LIBS="${LIBS}"
LIBS="${PTHREAD_LIBS}"
Modified: branches/2.0/varnish-cache/lib/libvarnish/time.c
===================================================================
--- branches/2.0/varnish-cache/lib/libvarnish/time.c 2009-03-23 14:40:52 UTC (rev 3997)
+++ branches/2.0/varnish-cache/lib/libvarnish/time.c 2009-03-23 14:45:32 UTC (rev 3998)
@@ -152,10 +152,20 @@
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
}
More information about the varnish-commit
mailing list