Skip to content

Commit

Permalink
Add private Task.StateFlags property to help with debugging (#55297)
Browse files Browse the repository at this point in the history
It's a pain when you want to debug something with tasks, you look at its m_stateFlags, and you're met with an integer you have to decode by looking at consts defined in Task.  This changes those consts to be an enum and adds a private property that returns the flags as that enum, to help with debugging.
  • Loading branch information
stephentoub authored Jul 9, 2021
1 parent 46a8608 commit e4e942f
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<type fullname="System.Threading.Tasks.Task">
<property name="ParentForDebugger" />
<property name="StateFlagsForDebugger" />
<property name="StateFlags" />
<method name="GetDelegateContinuationsForDebugger" />
<method name="SetNotificationForWaitCompletion" />
</type>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,8 @@ internal bool TrySetResult(TResult? result)
// been recorded, and (4) Cancellation has not been requested.
//
// If the reservation is successful, then set the result and finish completion processing.
if (AtomicStateUpdate(TASK_STATE_COMPLETION_RESERVED,
TASK_STATE_COMPLETION_RESERVED | TASK_STATE_RAN_TO_COMPLETION | TASK_STATE_FAULTED | TASK_STATE_CANCELED))
if (AtomicStateUpdate((int)TaskStateFlags.CompletionReserved,
(int)TaskStateFlags.CompletionReserved | (int)TaskStateFlags.RanToCompletion | (int)TaskStateFlags.Faulted | (int)TaskStateFlags.Canceled))
{
m_result = result;

Expand All @@ -390,7 +390,7 @@ internal bool TrySetResult(TResult? result)
// However, that goes through a windy code path, involves many non-inlineable functions
// and which can be summarized more concisely with the following snippet from
// FinishStageTwo, omitting everything that doesn't pertain to TrySetResult.
Interlocked.Exchange(ref m_stateFlags, m_stateFlags | TASK_STATE_RAN_TO_COMPLETION);
Interlocked.Exchange(ref m_stateFlags, m_stateFlags | (int)TaskStateFlags.RanToCompletion);
ContingentProperties? props = m_contingentProperties;
if (props != null)
{
Expand Down Expand Up @@ -425,7 +425,7 @@ internal void DangerousSetResult(TResult result)
else
{
m_result = result;
m_stateFlags |= TASK_STATE_RAN_TO_COMPLETION;
m_stateFlags |= (int)TaskStateFlags.RanToCompletion;
}
}

Expand Down
Loading

0 comments on commit e4e942f

Please sign in to comment.