changeset 5328:239ccb49852c HEAD

If timeout wait time was less than 1 millisecond, we wasted CPU calling poll() (or whatever) with zero timeout multiple times until the millisecond had passed. Now we round the waits up to next millisecond.
author Timo Sirainen <tss@iki.fi>
date Thu, 15 Mar 2007 16:28:00 +0200
parents 0c92499643ec
children a065a71da7d7
files src/lib/ioloop.c
diffstat 1 files changed, 4 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib/ioloop.c	Thu Mar 15 15:59:13 2007 +0200
+++ b/src/lib/ioloop.c	Thu Mar 15 16:28:00 2007 +0200
@@ -171,8 +171,10 @@
 		tv->tv_usec += 1000000;
 	}
 
-	if (tv->tv_sec > 0 || (tv->tv_sec == 0 && tv->tv_usec > 0))
-		return tv->tv_sec*1000 + tv->tv_usec/1000;
+	if (tv->tv_sec > 0 || (tv->tv_sec == 0 && tv->tv_usec > 0)) {
+		/* round wait times up to next millisecond */
+		return tv->tv_sec * 1000 + (tv->tv_usec + 999) / 1000;
+	}
 
 	/* no need to calculate the times again with this timeout */
         tv->tv_sec = tv->tv_usec = 0;