PERFORCE change 66066 for review

Peter Wemm peter at FreeBSD.org
Mon Nov 29 15:08:53 PST 2004


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

Change 66066 by peter at peter_daintree on 2004/11/29 23:08:30

	Really fix the timeout calculation.  This should even be bde-proof.

Affected files ...

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

Differences ...

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

@@ -1854,16 +1854,13 @@
 #undef diff
 		/*
 		 * Rounding down may make us wake up just short
-		 * of the target, so we round up.
+		 * of the target, so we round up.  The 32 bit arithmetic is
+		 * sufficient for the first calculation for hz < 169.
 		 */
-		if (slp <= LONG_MAX / 1000000)
-			slp = (slp * 1000000 + (tick - 1)) / tick + 1;
-		else if (slp <= LONG_MAX / hz)
-			slp = slp * hz + 1;
+		if (sizeof(u_long) > 4 || slp <= ULONG_MAX / hz)
+			slp = slp = (((u_long)slp * hz) + 999999) / 1000000;
 		else
-			slp = LONG_MAX;
-		if (slp > INT_MAX)
-			slp = INT_MAX;
+			slp = (slp + (tick - 1)) / tick;
 		goto sleep;
 	}
 	if (qp->c_cc <= 0) {


More information about the p4-projects mailing list