Преглед изворни кода

Fix bug where if a task is Start-ed with a specific scheduler,
that scheduler is ignored if it is in a thread owned by another
scheduler. Tasks should not be locked to the scheduler that
owns the calling thread.

Fix bug where TryExecuteTask does not actually try to execute
the task. Instead, TryExecuteTaskInline is called, which is
abstract. The TpScheduler implementation, the default, then
calls the internal method Task.Execute which then actually
executes the task. The problem with this is that only 3rd
party schedulers, can't actually execute a task, thus making
extending TaskScheduler impossible. (Unless they use some
serious Mono specific reflection hacks as I am now.)

Koushik Dutta пре 15 година
родитељ
комит
98da8a2fc6

+ 2 - 1
mcs/class/corlib/System.Threading.Tasks/Task.cs

@@ -356,7 +356,8 @@ namespace System.Threading.Tasks
 			status = TaskStatus.WaitingToRun;
 			status = TaskStatus.WaitingToRun;
 			
 			
 			// If worker is null it means it is a local one, revert to the old behavior
 			// If worker is null it means it is a local one, revert to the old behavior
-			if (childWorkAdder == null || CheckTaskOptions (taskCreationOptions, TaskCreationOptions.PreferFairness)) {
+			// If TaskScheduler.Current is not being used, the scheduler was explicitly provided, so we must use that
+			if (scheduler != TaskScheduler.Current || childWorkAdder == null || CheckTaskOptions (taskCreationOptions, TaskCreationOptions.PreferFairness)) {
 				scheduler.QueueTask (this);
 				scheduler.QueueTask (this);
 			} else {
 			} else {
 				/* Like the semantic of the ABP paper describe it, we add ourselves to the bottom 
 				/* Like the semantic of the ABP paper describe it, we add ourselves to the bottom 

+ 9 - 1
mcs/class/corlib/System.Threading.Tasks/TaskScheduler.cs

@@ -113,7 +113,15 @@ namespace System.Threading.Tasks
 
 
 		internal protected bool TryExecuteTask (Task task)
 		internal protected bool TryExecuteTask (Task task)
 		{
 		{
-			return TryExecuteTaskInline (task, false);
+			if (task.IsCompleted)
+				return false;
+
+			if (task.Status == TaskStatus.WaitingToRun) {
+				task.Execute (null);
+				return true;
+			}
+
+			return false;
 		}
 		}
 
 
 		protected abstract bool TryExecuteTaskInline (Task task, bool taskWasPreviouslyQueued);
 		protected abstract bool TryExecuteTaskInline (Task task, bool taskWasPreviouslyQueued);

+ 1 - 9
mcs/class/corlib/System.Threading.Tasks/TpScheduler.cs

@@ -57,15 +57,7 @@ namespace System.Threading.Tasks
 
 
 		protected override bool TryExecuteTaskInline (Task task, bool taskWasPreviouslyQueued)
 		protected override bool TryExecuteTaskInline (Task task, bool taskWasPreviouslyQueued)
 		{
 		{
-			if (task.IsCompleted)
-				return false;
-
-			if (task.Status == TaskStatus.WaitingToRun) {
-				task.Execute (null);
-				return true;
-			}
-
-			return false;
+		    return TryExecuteTask(task);
 		}
 		}
 
 
 		public override int MaximumConcurrencyLevel {
 		public override int MaximumConcurrencyLevel {