fix: Adds more debugging to the timer system. Simplifies the timer pool. (#1195)

This commit is contained in:
Kamron Batman 2022-10-17 23:25:49 -07:00 • committed by GitHub
parent d5416b6dec
commit 919b7e9416
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 99 additions and 38 deletions

View file

@ -14,6 +14,7 @@
*************************************************************************/
using System;
using System.Diagnostics;
using Server.Diagnostics;
using Server.Logging;
@ -51,6 +52,8 @@ public partial class Timer
_nextTimer = null;
_prevTimer = null;
Next = Core.Now + Delay;
_ring = -1;
_slot = -1;
var prof = GetProfile();
@ -76,6 +79,29 @@ public partial class Timer
public Timer Start()
{
if (World.WorldState is WorldState.Initial or WorldState.Saving)
{
logger.Error(
"Attempted to start timer {Timer} ({HashCode}) while world is {State}\n{StackTrace}",
GetType(),
GetHashCode(),
World.WorldState,
new StackTrace()
);
}
#if THREADGUARD
if (Thread.CurrentThread != Core.Thread)
{
logger.Error(
"Attempted to start timer {Timer} ({HashCode}) from an invalid thread!\n{StackTrace}",
GetType(),
GetHashCode(),
new StackTrace()
);
}
#endif
if (Running)
{
return this;
@ -97,6 +123,29 @@ public partial class Timer
public void Stop()
{
if (World.WorldState is WorldState.Initial or WorldState.Saving)
{
logger.Error(
"Attempted to stop timer {Timer} ({HashCode}) while world is {State}\n{StackTrace}",
GetType(),
GetHashCode(),
World.WorldState,
new StackTrace()
);
}
#if THREADGUARD
if (Thread.CurrentThread != Core.Thread)
{
logger.Error(
"Attempted to stop timer {Timer} ({HashCode}) from an invalid thread!\n{StackTrace}",
GetType(),
GetHashCode(),
new StackTrace()
);
}
#endif
if (!Running)
{
return;
@ -132,9 +181,39 @@ public partial class Timer
private void Attach(Timer timer)
{
#if DEBUG_TIMERS
if (_prevTimer != null)
{
logger.Error(
"{Timer} ({HashCode}) attached with a previous timer already set!",
this,
GetHashCode()
);
}
if (_nextTimer != null)
{
logger.Error(
"{Timer} ({HashCode}) attached with a next timer already set!",
this,
GetHashCode()
);
}
#endif
_nextTimer = timer;
if (timer != null)
{
#if DEBUG_TIMERS
if (timer._prevTimer != null)
{
logger.Error(
"{Timer} ({HashCode}) attached from with a previous timer already set!",
timer,
timer.GetHashCode()
);
}
#endif
timer._prevTimer = this;
}
}
@ -157,5 +236,13 @@ public partial class Timer
internal virtual void OnDetach()
{
if (Running)
{
logger.Error("{Timer} detached while still running!\n{StackTrace}", this, new StackTrace());
return;
}
_ring = -1;
_slot = -1;
}
}