Skip to content

Commit 6f585b1

Browse files
committed
Address PR feedback
1 parent bd7e686 commit 6f585b1

File tree

1 file changed

+14
-9
lines changed
  • src/libraries/System.Private.CoreLib/src/System/Threading/Tasks

1 file changed

+14
-9
lines changed

src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4511,18 +4511,19 @@ internal void AddCompletionAction(ITaskCompletionAction action, bool addBeforeOt
45114511

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

45204518
object? oldValue = m_continuationObject;
4519+
Debug.Assert(oldValue is not null, "Expected non-null m_continuationObject object");
45214520
if (oldValue == s_taskCompletionSentinel)
4522-
goto alreadyCompleted;
4521+
{
4522+
return false;
4523+
}
45234524

4524-
List<object?>? list = oldValue as List<object?>;
45254525
// Logic for the case where we were previously storing a single continuation
4526+
List<object?>? list = oldValue as List<object?>;
45264527
if (list is null)
45274528
{
45284529
// Construct a new TaskContinuation list and CAS it in.
@@ -4552,7 +4553,7 @@ private bool AddTaskContinuationComplex(object tc, bool addBeforeOthers)
45524553
if (list is null)
45534554
{
45544555
Debug.Assert(oldValue == s_taskCompletionSentinel, "Expected m_continuationObject to be list or sentinel");
4555-
goto alreadyCompleted;
4556+
return false;
45564557
}
45574558
}
45584559

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

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

45734576
if (addBeforeOthers)
4577+
{
45744578
list.Insert(0, tc);
4579+
}
45754580
else
4581+
{
45764582
list.Add(tc);
4583+
}
45774584
}
4578-
return true; // continuation successfully queued, so return true.
45794585

4580-
// We didn't succeed in queuing the continuation, so return false.
4581-
alreadyCompleted: return false;
4586+
return true; // continuation successfully queued, so return true.
45824587
}
45834588

45844589
// Record a continuation task or action.

0 commit comments

Comments
 (0)