fixed a strange bug when the .wait delay is really accurate (too accurrate..). thanks ZeroCool for help debugging this!

This commit is contained in:
jrandom
2004-07-24 01:10:11 +00:00
committed by zzz
parent 481ef56e74
commit 85c8e56417

View File

@ -56,9 +56,10 @@ class FIFOBandwidthRefiller implements Runnable {
_lastCheckConfigTime = now; _lastCheckConfigTime = now;
} }
updateQueues(now); boolean updated = updateQueues(now);
if (updated) {
_lastRefillTime = now; _lastRefillTime = now;
}
try { Thread.sleep(_replenishFrequency); } catch (InterruptedException ie) {} try { Thread.sleep(_replenishFrequency); } catch (InterruptedException ie) {}
} }
@ -70,7 +71,7 @@ class FIFOBandwidthRefiller implements Runnable {
_lastCheckConfigTime = _lastRefillTime; _lastCheckConfigTime = _lastRefillTime;
} }
private void updateQueues(long now) { private boolean updateQueues(long now) {
long numMs = (now - _lastRefillTime); long numMs = (now - _lastRefillTime);
if (_log.shouldLog(Log.INFO)) if (_log.shouldLog(Log.INFO))
_log.info("Updating bandwidth after " + numMs + " (available in=" _log.info("Updating bandwidth after " + numMs + " (available in="
@ -78,7 +79,7 @@ class FIFOBandwidthRefiller implements Runnable {
+ _limiter.getAvailableOutboundBytes()+ ", rate in=" + _limiter.getAvailableOutboundBytes()+ ", rate in="
+ _inboundKBytesPerSecond + ", out=" + _inboundKBytesPerSecond + ", out="
+ _outboundKBytesPerSecond +")"); + _outboundKBytesPerSecond +")");
if (numMs > 1000) { if (numMs >= 1000) {
long inboundToAdd = 1024*_inboundKBytesPerSecond * (numMs/1000); long inboundToAdd = 1024*_inboundKBytesPerSecond * (numMs/1000);
long outboundToAdd = 1024*_outboundKBytesPerSecond * (numMs/1000); long outboundToAdd = 1024*_outboundKBytesPerSecond * (numMs/1000);
@ -104,6 +105,9 @@ class FIFOBandwidthRefiller implements Runnable {
_log.debug("Adding " + inboundToAdd + " bytes to inboundAvailable"); _log.debug("Adding " + inboundToAdd + " bytes to inboundAvailable");
_log.debug("Adding " + outboundToAdd + " bytes to outboundAvailable"); _log.debug("Adding " + outboundToAdd + " bytes to outboundAvailable");
} }
return true;
} else {
return false;
} }
} }