Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup
  • Loading branch information
BrennanConroy authored and github-actions committed Sep 1, 2022
commit 3a169d413559e948c8d99840b86419cbd9f52a5f
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,6 @@ private void ReplenishInternal(long nowTicks)
return;
}

// increment last tick by the number of replenish periods that occurred since the last replenish
// this way if replenish isn't being called every ReplenishmentPeriod we correctly track it so we know when replenishes should be occurring
_lastReplenishmentTick = nowTicks;

int availableRequestCounters = _requestCount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,29 +294,22 @@ private void ReplenishInternal(long nowTicks)
return;
}

// increment last tick by the number of replenish periods that occurred since the last replenish
// this way if replenish isn't being called every ReplenishmentPeriod we correctly track it so we know when replenishes should be occurring
_lastReplenishmentTick = nowTicks;

int initialRequestCount = _requestCount;
// Increment the current segment index while move the window
// We need to know the no. of requests that were acquired in a segment previously to ensure that we don't acquire more than the permit limit.
_currentSegmentIndex = (_currentSegmentIndex + 1) % _options.SegmentsPerWindow;
int oldSegmentRequestCount = _requestsPerSegment[_currentSegmentIndex];
_requestsPerSegment[_currentSegmentIndex] = 0;

if (oldSegmentRequestCount != 0)
if (oldSegmentRequestCount == 0)
{
_requestCount += oldSegmentRequestCount;
Debug.Assert(_requestCount <= _options.PermitLimit);
}

if (initialRequestCount == _requestCount)
{
// no requests added, queued items don't need updating
return;
}

_requestCount += oldSegmentRequestCount;
Debug.Assert(_requestCount <= _options.PermitLimit);

// Process queued requests
while (_queue.Count > 0)
{
Expand Down