@@ -4511,18 +4511,19 @@ internal void AddCompletionAction(ITaskCompletionAction action, bool addBeforeOt
4511
4511
4512
4512
// Support method for AddTaskContinuation that takes care of multi-continuation logic.
4513
4513
// 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().
4516
4514
private bool AddTaskContinuationComplex ( object tc , bool addBeforeOthers )
4517
4515
{
4518
4516
Debug . Assert ( tc != null , "Expected non-null tc object in AddTaskContinuationComplex" ) ;
4519
4517
4520
4518
object ? oldValue = m_continuationObject ;
4519
+ Debug . Assert ( oldValue is not null , "Expected non-null m_continuationObject object" ) ;
4521
4520
if ( oldValue == s_taskCompletionSentinel )
4522
- goto alreadyCompleted ;
4521
+ {
4522
+ return false ;
4523
+ }
4523
4524
4524
- List < object ? > ? list = oldValue as List < object ? > ;
4525
4525
// Logic for the case where we were previously storing a single continuation
4526
+ List < object ? > ? list = oldValue as List < object ? > ;
4526
4527
if ( list is null )
4527
4528
{
4528
4529
// Construct a new TaskContinuation list and CAS it in.
@@ -4552,7 +4553,7 @@ private bool AddTaskContinuationComplex(object tc, bool addBeforeOthers)
4552
4553
if ( list is null )
4553
4554
{
4554
4555
Debug . Assert ( oldValue == s_taskCompletionSentinel , "Expected m_continuationObject to be list or sentinel" ) ;
4555
- goto alreadyCompleted ;
4556
+ return false ;
4556
4557
}
4557
4558
}
4558
4559
@@ -4561,7 +4562,9 @@ private bool AddTaskContinuationComplex(object tc, bool addBeforeOthers)
4561
4562
// It is possible for the task to complete right after we snap the copy of
4562
4563
// the list. If so, then return false without queuing the continuation.
4563
4564
if ( m_continuationObject == s_taskCompletionSentinel )
4564
- goto alreadyCompleted ;
4565
+ {
4566
+ return false ;
4567
+ }
4565
4568
4566
4569
// Before growing the list we remove possible null entries that are the
4567
4570
// result from RemoveContinuations()
@@ -4571,14 +4574,16 @@ private bool AddTaskContinuationComplex(object tc, bool addBeforeOthers)
4571
4574
}
4572
4575
4573
4576
if ( addBeforeOthers )
4577
+ {
4574
4578
list . Insert ( 0 , tc ) ;
4579
+ }
4575
4580
else
4581
+ {
4576
4582
list . Add ( tc ) ;
4583
+ }
4577
4584
}
4578
- return true ; // continuation successfully queued, so return true.
4579
4585
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.
4582
4587
}
4583
4588
4584
4589
// Record a continuation task or action.
0 commit comments