Skip to content

Commit

Permalink
Make TryExecuteTaskInline a bit smarter
Browse files Browse the repository at this point in the history
  • Loading branch information
garuma committed Feb 23, 2011
1 parent 4e37530 commit df12cf4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Expand Up @@ -63,8 +63,15 @@ protected internal override bool TryDequeue (Task task)

protected override bool TryExecuteTaskInline (Task task, bool taskWasPreviouslyQueued)
{
task.Execute (null);
return true;
if (task.IsCompleted)
return false;

if (task.Status == TaskStatus.WaitingToRun) {
task.Execute (null);
return true;
}

return false;
}

public override int MaximumConcurrencyLevel {
Expand Down
11 changes: 9 additions & 2 deletions mcs/class/corlib/System.Threading.Tasks/TpScheduler.cs
Expand Up @@ -70,8 +70,15 @@ protected internal override bool TryDequeue (Task task)

protected override bool TryExecuteTaskInline (Task task, bool taskWasPreviouslyQueued)
{
task.Execute (null);
return true;
if (task.IsCompleted)
return false;

if (task.Status == TaskStatus.WaitingToRun) {
task.Execute (null);
return true;
}

return false;
}

public override int MaximumConcurrencyLevel {
Expand Down

0 comments on commit df12cf4

Please sign in to comment.