Skip to content

Commit

Permalink
Address PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
stephentoub committed Feb 21, 2024
1 parent bd7e686 commit 6f585b1
Showing 1 changed file with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4511,18 +4511,19 @@ internal void AddCompletionAction(ITaskCompletionAction action, bool addBeforeOt

// Support method for AddTaskContinuation that takes care of multi-continuation logic.
// Returns true if and only if the continuation was successfully queued.
// THIS METHOD ASSUMES THAT m_continuationObject IS NOT NULL. That case was taken
// care of in the calling method, AddTaskContinuation().
private bool AddTaskContinuationComplex(object tc, bool addBeforeOthers)
{
Debug.Assert(tc != null, "Expected non-null tc object in AddTaskContinuationComplex");

object? oldValue = m_continuationObject;
Debug.Assert(oldValue is not null, "Expected non-null m_continuationObject object");
if (oldValue == s_taskCompletionSentinel)
goto alreadyCompleted;
{
return false;
}

List<object?>? list = oldValue as List<object?>;
// Logic for the case where we were previously storing a single continuation
List<object?>? list = oldValue as List<object?>;
if (list is null)
{
// Construct a new TaskContinuation list and CAS it in.
Expand Down Expand Up @@ -4552,7 +4553,7 @@ private bool AddTaskContinuationComplex(object tc, bool addBeforeOthers)
if (list is null)
{
Debug.Assert(oldValue == s_taskCompletionSentinel, "Expected m_continuationObject to be list or sentinel");
goto alreadyCompleted;
return false;
}
}

Expand All @@ -4561,7 +4562,9 @@ private bool AddTaskContinuationComplex(object tc, bool addBeforeOthers)
// It is possible for the task to complete right after we snap the copy of
// the list. If so, then return false without queuing the continuation.
if (m_continuationObject == s_taskCompletionSentinel)
goto alreadyCompleted;
{
return false;
}

// Before growing the list we remove possible null entries that are the
// result from RemoveContinuations()
Expand All @@ -4571,14 +4574,16 @@ private bool AddTaskContinuationComplex(object tc, bool addBeforeOthers)
}

if (addBeforeOthers)
{
list.Insert(0, tc);
}
else
{
list.Add(tc);
}
}
return true; // continuation successfully queued, so return true.

// We didn't succeed in queuing the continuation, so return false.
alreadyCompleted: return false;
return true; // continuation successfully queued, so return true.
}

// Record a continuation task or action.
Expand Down

0 comments on commit 6f585b1

Please sign in to comment.