diff options
Diffstat (limited to 'src/mscorlib/src/System/Threading/Tasks/ThreadPoolTaskScheduler.cs')
-rw-r--r-- | src/mscorlib/src/System/Threading/Tasks/ThreadPoolTaskScheduler.cs | 24 |
1 files changed, 7 insertions, 17 deletions
diff --git a/src/mscorlib/src/System/Threading/Tasks/ThreadPoolTaskScheduler.cs b/src/mscorlib/src/System/Threading/Tasks/ThreadPoolTaskScheduler.cs index 5c6ca9bb76..e69a89fe66 100644 --- a/src/mscorlib/src/System/Threading/Tasks/ThreadPoolTaskScheduler.cs +++ b/src/mscorlib/src/System/Threading/Tasks/ThreadPoolTaskScheduler.cs @@ -23,7 +23,7 @@ namespace System.Threading.Tasks /// <summary> /// An implementation of TaskScheduler that uses the ThreadPool scheduler /// </summary> - internal sealed class ThreadPoolTaskScheduler: TaskScheduler + internal sealed class ThreadPoolTaskScheduler : TaskScheduler { /// <summary> /// Constructs a new ThreadPool task scheduler object @@ -34,15 +34,7 @@ namespace System.Threading.Tasks } // static delegate for threads allocated to handle LongRunning tasks. - private static readonly ParameterizedThreadStart s_longRunningThreadWork = new ParameterizedThreadStart(LongRunningThreadWork); - - private static void LongRunningThreadWork(object obj) - { - Contract.Requires(obj != null, "TaskScheduler.LongRunningThreadWork: obj is null"); - Task t = obj as Task; - Debug.Assert(t != null, "TaskScheduler.LongRunningThreadWork: t is null"); - t.ExecuteEntry(false); - } + private static readonly ParameterizedThreadStart s_longRunningThreadWork = s => ((Task)s).ExecuteEntryUnsafe(); /// <summary> /// Schedules a task to the ThreadPool. @@ -64,11 +56,11 @@ namespace System.Threading.Tasks ThreadPool.UnsafeQueueCustomWorkItem(task, forceToGlobalQueue); } } - + /// <summary> /// This internal function will do this: /// (1) If the task had previously been queued, attempt to pop it and return false if that fails. - /// (2) Propagate the return value from Task.ExecuteEntry() back to the caller. + /// (2) Return whether the task is executed /// /// IMPORTANT NOTE: TryExecuteTaskInline will NOT throw task exceptions itself. Any wait code path using this function needs /// to account for exceptions that need to be propagated, and throw themselves accordingly. @@ -79,19 +71,17 @@ namespace System.Threading.Tasks if (taskWasPreviouslyQueued && !ThreadPool.TryPopCustomWorkItem(task)) return false; - // Propagate the return value of Task.ExecuteEntry() - bool rval = false; try { - rval = task.ExecuteEntry(false); // handles switching Task.Current etc. + task.ExecuteEntryUnsafe(); // handles switching Task.Current etc. } finally { // Only call NWIP() if task was previously queued - if(taskWasPreviouslyQueued) NotifyWorkItemProgress(); + if (taskWasPreviouslyQueued) NotifyWorkItemProgress(); } - return rval; + return true; } protected internal override bool TryDequeue(Task task) |