Skip to content

Commit

Permalink
Fixed Clear
Browse files Browse the repository at this point in the history
  • Loading branch information
timcassell committed Nov 16, 2023
1 parent 16b998b commit 97e82fe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
10 changes: 8 additions & 2 deletions Package/Core/InternalShared/PoolInternal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,18 @@ private static class Type<T> where T : HandleablePromiseBase
private static void Clear()
{
#if PROMISE_DEBUG || PROTO_PROMISE_DEVELOPER_MODE
var instances = s_pool.MoveElementsToStack();
#pragma warning disable IDE0018 // Inline variable declaration
HandleablePromiseBase head;
#pragma warning restore IDE0018 // Inline variable declaration
var instances = s_pool.MoveElementsToStack(out head);
var instance = head;
// The pooled stack ends with InvalidAwaitSentinel instead of null.
for (var instance = instances.Pop(); instance != PromiseRefBase.InvalidAwaitSentinel.s_instance; instance = instances.Pop())
while (instance != PromiseRefBase.InvalidAwaitSentinel.s_instance)
{
MarkNotInPoolPrivate(instance);
Discard(instance);
instance = instance._next;
instances.Pop();
}
#else
s_pool.ClearUnsafe();
Expand Down
5 changes: 3 additions & 2 deletions Package/Core/InternalShared/ValueCollectionsInternal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,13 @@ internal void ClearUnsafe()
}

#if PROMISE_DEBUG || PROTO_PROMISE_DEVELOPER_MODE
internal ValueLinkedStack<HandleablePromiseBase> MoveElementsToStack()
internal ValueLinkedStack<HandleablePromiseBase> MoveElementsToStack(out HandleablePromiseBase head)
{
_locker.Enter();
var stack = new ValueLinkedStack<HandleablePromiseBase>(_head);
head = _head;
ClearUnsafe();
_locker.Exit();
var stack = new ValueLinkedStack<HandleablePromiseBase>(head);
return stack;
}
#endif
Expand Down

0 comments on commit 97e82fe

Please sign in to comment.