r3978 - in trunk/varnish-cache: . lib/libvarnish
phk at projects.linpro.no
phk at projects.linpro.no
Sun Mar 22 17:23:23 CET 2009
Author: phk
Date: 2009-03-22 17:23:23 +0100 (Sun, 22 Mar 2009)
New Revision: 3978
Modified:
trunk/varnish-cache/configure.ac
trunk/varnish-cache/lib/libvarnish/time.c
Log:
Make TIM_sleep() use nanosleep(2) if we have it.
Make it respect Open Groups 1 second limit on usleep if not.
Modified: trunk/varnish-cache/configure.ac
===================================================================
--- trunk/varnish-cache/configure.ac 2009-03-22 14:09:33 UTC (rev 3977)
+++ trunk/varnish-cache/configure.ac 2009-03-22 16:23:23 UTC (rev 3978)
@@ -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: trunk/varnish-cache/lib/libvarnish/time.c
===================================================================
--- trunk/varnish-cache/lib/libvarnish/time.c 2009-03-22 14:09:33 UTC (rev 3977)
+++ trunk/varnish-cache/lib/libvarnish/time.c 2009-03-22 16:23:23 UTC (rev 3978)
@@ -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