Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 29 Nov 2004 23:08:52 GMT
From:      Peter Wemm <peter@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 66066 for review
Message-ID:  <200411292308.iATN8q46037293@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=66066

Change 66066 by peter@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) {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200411292308.iATN8q46037293>