Fix bug in queue average with a very large number of entries.

Icarus is not actually fast enough to run into this issue in a
reasonable amount of time. I discovered this by thinking about
the algorithm and verified the fix with custom code.
This commit is contained in:
Cary R 2011-05-22 21:35:45 -07:00 committed by Stephen Williams
parent c69f4ef7e0
commit 35488ac254
1 changed files with 4 additions and 1 deletions

View File

@ -84,9 +84,12 @@ uint64_t calc_average_wait_time(uint64_t high, uint64_t low, uint64_t total)
/* It's a big value so calculate the average the long way. */
do {
unsigned carry = 0U;
/* Copy bits from low to high until we have a bit to place
* in the result or there are no bits left. */
while ((bit >= 0) && (high < total)) {
while ((bit >= 0) && (high < total) && !carry) {
/* If the MSB is set then we will have a carry. */
if (high > (UINT64_MAX >> 1)) carry = 1U;
high <<= 1;
high |= (low & 0x8000000000000000) != 0;
low <<= 1;