Deleted preserveRemoveSelf because Remove() should always remove a trigger for pooling to work correctly

master
Artem Kolesnykov 2023-02-12 17:26:27 +02:00
parent 663fa737f3
commit 019f8aaf30
1 changed files with 55 additions and 78 deletions

View File

@ -20,8 +20,6 @@ namespace Cysharp.Threading.Tasks
{ {
ITriggerHandler<T> head; // head.prev is last ITriggerHandler<T> head; // head.prev is last
ITriggerHandler<T> iteratingHead; ITriggerHandler<T> iteratingHead;
bool preserveRemoveSelf;
ITriggerHandler<T> iteratingNode; ITriggerHandler<T> iteratingNode;
void LogError(Exception ex) void LogError(Exception ex)
@ -44,6 +42,7 @@ namespace Cysharp.Threading.Tasks
while (h != null) while (h != null)
{ {
iteratingNode = h; iteratingNode = h;
var next = h.Next;
try try
{ {
@ -55,18 +54,7 @@ namespace Cysharp.Threading.Tasks
Remove(h); Remove(h);
} }
if (preserveRemoveSelf) h = next;
{
preserveRemoveSelf = false;
iteratingNode = null;
var next = h.Next;
Remove(h);
h = next;
}
else
{
h = h.Next;
}
} }
iteratingNode = null; iteratingNode = null;
@ -97,7 +85,6 @@ namespace Cysharp.Threading.Tasks
LogError(ex); LogError(ex);
} }
preserveRemoveSelf = false;
iteratingNode = null; iteratingNode = null;
var next = h.Next; var next = h.Next;
Remove(h); Remove(h);
@ -132,7 +119,6 @@ namespace Cysharp.Threading.Tasks
LogError(ex); LogError(ex);
} }
preserveRemoveSelf = false;
iteratingNode = null; iteratingNode = null;
var next = h.Next; var next = h.Next;
Remove(h); Remove(h);
@ -167,7 +153,6 @@ namespace Cysharp.Threading.Tasks
LogError(ex); LogError(ex);
} }
preserveRemoveSelf = false;
iteratingNode = null; iteratingNode = null;
var next = h.Next; var next = h.Next;
Remove(h); Remove(h);
@ -241,71 +226,63 @@ namespace Cysharp.Threading.Tasks
{ {
if (handler == null) throw new ArgumentNullException(nameof(handler)); if (handler == null) throw new ArgumentNullException(nameof(handler));
if (iteratingNode != null && iteratingNode == handler) var prev = handler.Prev;
var next = handler.Next;
if (next != null)
{ {
// if remove self, reserve remove self after invoke completed. next.Prev = prev;
preserveRemoveSelf = true; }
if (handler == head)
{
head = next;
}
else if (handler == iteratingHead)
{
iteratingHead = next;
} }
else else
{ {
var prev = handler.Prev; // when handler is head, prev indicate last so don't use it.
var next = handler.Next; if (prev != null)
if (next != null)
{ {
next.Prev = prev; prev.Next = next;
} }
if (handler == head)
{
head = next;
}
else if (handler == iteratingHead)
{
iteratingHead = next;
}
else
{
// when handler is head, prev indicate last so don't use it.
if (prev != null)
{
prev.Next = next;
}
}
if (head != null)
{
if (head.Prev == handler)
{
if (prev != head)
{
head.Prev = prev;
}
else
{
head.Prev = null;
}
}
}
if (iteratingHead != null)
{
if (iteratingHead.Prev == handler)
{
if (prev != iteratingHead.Prev)
{
iteratingHead.Prev = prev;
}
else
{
iteratingHead.Prev = null;
}
}
}
handler.Prev = null;
handler.Next = null;
} }
if (head != null)
{
if (head.Prev == handler)
{
if (prev != head)
{
head.Prev = prev;
}
else
{
head.Prev = null;
}
}
}
if (iteratingHead != null)
{
if (iteratingHead.Prev == handler)
{
if (prev != iteratingHead.Prev)
{
iteratingHead.Prev = prev;
}
else
{
iteratingHead.Prev = null;
}
}
}
handler.Prev = null;
handler.Next = null;
} }
} }
} }