Skip to content

Commit 759acdc

Browse files
committed
Skip over transparent non-user continuations
1 parent b802826 commit 759acdc

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -607,8 +607,15 @@ public static void HandleSuspended<T, TOps>(T task) where T : Task, ITaskComplet
607607
// the continuation chain builds from the innermost frame out and at the time when the
608608
// notifier is created we do not know yet if the caller wants to continue on a context.
609609
ValueTaskSourceOnCompletedFlags configFlags = ValueTaskSourceOnCompletedFlags.None;
610-
ContinuationFlags continuationFlags = headContinuation.Next!.Flags;
611610

611+
// skip over transparent non-user continuations.
612+
ref Continuation nextUserContinuaton = ref headContinuation.Next!;
613+
while ((nextUserContinuaton.Flags & continueFlags) == 0)
614+
{
615+
nextUserContinuaton = ref nextUserContinuaton.Next!;
616+
}
617+
618+
ContinuationFlags continuationFlags = nextUserContinuaton.Flags;
612619
const ContinuationFlags continueOnContextFlags =
613620
ContinuationFlags.ContinueOnCapturedSynchronizationContext |
614621
ContinuationFlags.ContinueOnCapturedTaskScheduler;
@@ -620,7 +627,7 @@ public static void HandleSuspended<T, TOps>(T task) where T : Task, ITaskComplet
620627
}
621628

622629
// Clear continuation flags, so that continuation runs transparently
623-
headContinuation.Next!.Flags &= ~continueFlags;
630+
nextUserContinuaton.Flags &= ~continueFlags;
624631
TOps.ValueTaskSourceOnCompleted(task, vtsNotifier, configFlags);
625632
}
626633
else

0 commit comments

Comments
 (0)