fix: Fixes pooled timers orphaning each other (#809)

This commit is contained in:
Kamron Batman 2021-10-03 22:58:46 -07:00 • committed by GitHub
parent 8e4d5bb169
commit 4893094bb4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 55 additions and 43 deletions

View file

@ -62,22 +62,29 @@ namespace Server
_poolHead = head;
_poolCount += amount;
#if DEBUG_TIMERS
logger.Information($"Pool count: {_poolCount} / {_poolCapacity}");
logger.Information($"Returning to pool. ({_poolCount} / {_poolCapacity})");
#endif
}
private static DelayCallTimer GetFromPool()
{
if (_poolHead == null)
{
return null;
}
var timer = _poolHead;
_poolHead = _poolHead._nextTimer as DelayCallTimer;
timer.Detach();
_poolCount--;
return timer;
}
internal static void RefillPool(int amount, out DelayCallTimer head, out DelayCallTimer tail)
{
#if DEBUG_TIMERS
logger.Information($"Filling pool with {amount} timers.");
logger.Information($"Filling pool with {amount} timers.");
#endif
head = null;