Skip to content

Commit 79ced18

Browse files
committed
Enhance comments for Task field in AsyncHelpers
Added comments to clarify the purpose of the Task field.
1 parent 6bc980b commit 79ced18

File tree

2 files changed

+13
-8
lines changed
  • src
    • coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices
    • libraries/System.Private.CoreLib/src/System/Threading/Tasks

2 files changed

+13
-8
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ internal unsafe ref struct AsyncDispatcherInfo
186186
[FieldOffset(8)]
187187
#endif
188188
// The runtime async Task being dispatched.
189+
// This is used by debuggers in the case of nested dispatcher info (multiple runtime-async Tasks on the same thread)
190+
// to match an inflight Task to the corresponding Continuation chain.
189191
public Task Task;
190192

191193
// Information about current task dispatching, to be used for async
@@ -500,9 +502,10 @@ private unsafe void DispatchContinuations()
500502
asyncDispatcherInfo.NextContinuation = nextContinuation;
501503

502504
ref byte resultLoc = ref nextContinuation != null ? ref nextContinuation.GetResultStorageOrNull() : ref GetResultStorage();
505+
RuntimeAsyncContinuationDebugInfo? debugInfo = null;
503506
if (Task.s_asyncDebuggingEnabled)
504507
{
505-
RuntimeAsyncContinuationDebugInfo debugInfo = Task.GetRuntimeAsyncContinuationDebugInfo(curContinuation, out RuntimeAsyncContinuationDebugInfo? debugInfoVal) ? debugInfoVal : new RuntimeAsyncContinuationDebugInfo(Stopwatch.GetTimestamp());
508+
debugInfo = Task.GetRuntimeAsyncContinuationDebugInfo(curContinuation, out RuntimeAsyncContinuationDebugInfo? debugInfoVal) ? debugInfoVal : new RuntimeAsyncContinuationDebugInfo(Stopwatch.GetTimestamp());
506509
// we have dequeued curContinuation; update task tick info so that we can track its start time from a debugger
507510
Task.UpdateRuntimeAsyncTaskTicks(this, debugInfo.TickCount);
508511
}
@@ -515,7 +518,7 @@ private unsafe void DispatchContinuations()
515518
{
516519
// we have a new Continuation that belongs to the same logical invocation as the previous; propagate debug info from previous continuation
517520
if (Task.s_asyncDebuggingEnabled)
518-
Task.UpdateRuntimeAsyncContinuationDebugInfo(newContinuation, debugInfo);
521+
Task.UpdateRuntimeAsyncContinuationDebugInfo(newContinuation, debugInfo!);
519522
newContinuation.Next = nextContinuation;
520523
HandleSuspended();
521524
contexts.Pop();
@@ -551,7 +554,7 @@ private unsafe void DispatchContinuations()
551554

552555
if (asyncDispatcherInfo.NextContinuation == null)
553556
{
554-
if (TplEventSource.Log.IsEnabled())
557+
if (isTplEnabled)
555558
{
556559
TplEventSource.Log.TraceOperationEnd(this.Id, AsyncCausalityStatus.Completed);
557560
}
@@ -595,8 +598,8 @@ private unsafe void DispatchContinuations()
595598
{
596599
if (continuation == null || (continuation.Flags & ContinuationFlags.HasException) != 0)
597600
return continuation;
598-
599-
RemoveRuntimeAsyncContinuationTicks(continuation);
601+
if (Task.s_asyncDebuggingEnabled)
602+
Task.RemoveRuntimeAsyncContinuationTicks(continuation);
600603
continuation = continuation.Next;
601604
}
602605
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7628,15 +7628,17 @@ private void ProcessInnerTask(Task? task)
76287628
public bool InvokeMayRunArbitraryCode => true;
76297629
}
76307630

7631+
#if !MONO
76317632
internal sealed class RuntimeAsyncContinuationDebugInfo
76327633
{
7633-
public long TickCount;
7634-
public int Id;
7634+
internal long TickCount;
7635+
internal int Id;
76357636

7636-
public RuntimeAsyncContinuationDebugInfo(long tickCount)
7637+
internal RuntimeAsyncContinuationDebugInfo(long tickCount)
76377638
{
76387639
TickCount = tickCount;
76397640
Id = Task.NewId();
76407641
}
76417642
}
7643+
#endif
76427644
}

0 commit comments

Comments
 (0)