fix: lock timing handle list while using

This commit is contained in:
goaaats 2022-06-26 16:18:58 +02:00
parent 36780f43a8
commit d079bc1fbf
No known key found for this signature in database
GPG key ID: 49E2AA8C6A76498B

View file

@ -19,7 +19,8 @@ public sealed class TimingHandle : TimingEvent, IDisposable, IComparable<TimingH
{ {
this.Stack = Timings.TaskTimingHandles; this.Stack = Timings.TaskTimingHandles;
this.Parent = this.Stack.LastOrDefault(); lock (this.Stack)
this.Parent = this.Stack.LastOrDefault();
if (this.Parent != null) if (this.Parent != null)
{ {
@ -36,7 +37,8 @@ public sealed class TimingHandle : TimingEvent, IDisposable, IComparable<TimingH
this.EndTime = this.StartTime; this.EndTime = this.StartTime;
this.IsMainThread = ThreadSafety.IsMainThread; this.IsMainThread = ThreadSafety.IsMainThread;
this.Stack.Add(this); lock (this.Stack)
this.Stack.Add(this);
} }
/// <summary> /// <summary>
@ -78,7 +80,10 @@ public sealed class TimingHandle : TimingEvent, IDisposable, IComparable<TimingH
public void Dispose() public void Dispose()
{ {
this.EndTime = Timings.Stopwatch.Elapsed.TotalMilliseconds; this.EndTime = Timings.Stopwatch.Elapsed.TotalMilliseconds;
this.Stack.Remove(this);
lock (this.Stack)
this.Stack.Remove(this);
if (this.Duration > 1 || this.ChildCount > 0) if (this.Duration > 1 || this.ChildCount > 0)
{ {
lock (Timings.AllTimings) lock (Timings.AllTimings)