PERFORCE change 66061 for review

Peter Wemm peter at FreeBSD.org
Mon Nov 29 14:00:54 PST 2004


http://perforce.freebsd.org/chv.cgi?CH=66061

Change 66061 by peter at peter_daintree on 2004/11/29 21:59:55

	try and do the rounding properly.

Affected files ...

.. //depot/projects/hammer/sys/kern/tty.c#36 edit

Differences ...

==== //depot/projects/hammer/sys/kern/tty.c#36 (text+ko) ====

@@ -1855,21 +1855,15 @@
 		/*
 		 * Rounding down may make us wake up just short
 		 * of the target, so we round up.
-		 * The formula is ceiling(slp * hz/1000000).
-		 * 32-bit arithmetic is enough for hz < 169.
-		 * XXX see tvtohz() for how to avoid overflow if hz
-		 * is large (divide by `tick' and/or arrange to
-		 * use tvtohz() if hz is large).
 		 */
-		if ((sizeof(u_long) > 4) || hz < 169)
-			slp = (long) (((u_long)slp * hz) + 999999) / 1000000;
-		else {
-			struct timeval tv;
-
-			tv.tv_sec = slp;
-			tv.tv_usec = 0;
-			slp = tvtohz(&tv);
-		}
+		if (slp <= LONG_MAX / 1000000)
+			slp = (slp * 1000000 + (tick - 1)) / tick + 1;
+		else if (slp <= LONG_MAX / hz)
+			slp = slp * hz + 1;
+		else
+			slp = LONG_MAX;
+		if (slp > INT_MAX)
+			slp = INT_MAX;
 		goto sleep;
 	}
 	if (qp->c_cc <= 0) {


More information about the p4-projects mailing list