Change the type of Task.m_action to Delegate
authorPetr Onderka <gsvick@gmail.com>
Mon, 28 Nov 2016 18:18:00 +0000 (19:18 +0100)
committerPetr Onderka <gsvick@gmail.com>
Mon, 28 Nov 2016 18:21:17 +0000 (19:21 +0100)
This makes the code more strongly typed and avoids some casts.

Commit migrated from https://github.com/dotnet/coreclr/commit/9968cfef536000d04b2ade6994392de4e6de06da

src/coreclr/src/mscorlib/src/System/Threading/Tasks/Task.cs
src/coreclr/src/mscorlib/src/System/Threading/Tasks/TaskContinuation.cs
src/coreclr/src/mscorlib/src/System/Threading/Tasks/future.cs

index 36f8401..c48d3c4 100644 (file)
@@ -152,7 +152,7 @@ namespace System.Threading.Tasks
 
         private volatile int m_taskId; // this task's unique ID. initialized only if it is ever requested
 
-        internal object m_action;    // The body of the task.  Might be Action<object>, Action<TState> or Action.  Or possibly a Func.
+        internal Delegate m_action;    // The body of the task.  Might be Action<object>, Action<TState> or Action.  Or possibly a Func.
         // If m_action is set to null it will indicate that we operate in the
         // "externally triggered completion" mode, which is exclusively meant 
         // for the signalling Task<TResult> (aka. promise). In this mode,
@@ -580,7 +580,7 @@ namespace System.Threading.Tasks
         /// <param name="cancellationToken">A CancellationToken for the Task.</param>
         /// <param name="creationOptions">Options to customize behavior of Task.</param>
         /// <param name="internalOptions">Internal options to customize behavior of Task.</param>
-        internal void TaskConstructorCore(object action, object state, CancellationToken cancellationToken,
+        internal void TaskConstructorCore(Delegate action, object state, CancellationToken cancellationToken,
             TaskCreationOptions creationOptions, InternalTaskOptions internalOptions, TaskScheduler scheduler)
         {
             m_action = action;
@@ -753,7 +753,7 @@ namespace System.Threading.Tasks
         {
             get
             {
-                Delegate d = (Delegate)m_action;
+                Delegate d = m_action;
                 return d != null ? d.Method.ToString() : "{null}";
             }
         }
@@ -1912,7 +1912,7 @@ namespace System.Threading.Tasks
             if (AsyncCausalityTracer.LoggingOn && (Options & (TaskCreationOptions)InternalTaskOptions.ContinuationTask) == 0)
             {
                 //For all other task than TaskContinuations we want to log. TaskContinuations log in their constructor
-                AsyncCausalityTracer.TraceOperationCreation(CausalityTraceLevel.Required, this.Id, "Task: "+((Delegate)m_action).Method.Name, 0);
+                AsyncCausalityTracer.TraceOperationCreation(CausalityTraceLevel.Required, this.Id, "Task: " + m_action.Method.Name, 0);
             }
 
 
index 4c035df..b078d27 100644 (file)
@@ -305,7 +305,7 @@ namespace System.Threading.Tasks
             m_options = options;
             m_taskScheduler = scheduler;
             if (AsyncCausalityTracer.LoggingOn)
-                AsyncCausalityTracer.TraceOperationCreation(CausalityTraceLevel.Required, m_task.Id, "Task.ContinueWith: " + ((Delegate)task.m_action).Method.Name, 0);
+                AsyncCausalityTracer.TraceOperationCreation(CausalityTraceLevel.Required, m_task.Id, "Task.ContinueWith: " + task.m_action.Method.Name, 0);
 
             if (Task.s_asyncDebuggingEnabled)
             {
@@ -374,7 +374,7 @@ namespace System.Threading.Tasks
                 return m_task.GetDelegateContinuationsForDebugger();
             }
 
-            return new Delegate[] { m_task.m_action as Delegate };
+            return new Delegate[] { m_task.m_action };
         }
     }
 
index 39e6ca1..d5b2bdb 100644 (file)
@@ -447,7 +447,7 @@ namespace System.Threading.Tasks
         {
             get
             {
-                Delegate d = (Delegate)m_action;
+                Delegate d = m_action;
                 return d != null ? d.Method.ToString() : "{null}";
             }
         }