From cbd3f54c7dbd3808e2d8b1e4dc1040f511147d19 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Tue, 18 Apr 2017 13:57:19 -0400 Subject: [PATCH] Expose Task.IsCompletedSuccessfully --- .../shared/System/Threading/Tasks/TaskExtensions.cs | 4 ++-- src/mscorlib/src/System/IO/Stream.cs | 4 ++-- .../src/System/Runtime/CompilerServices/TaskAwaiter.cs | 2 +- src/mscorlib/src/System/Threading/Tasks/Task.cs | 3 +-- src/mscorlib/src/System/Threading/Tasks/TaskContinuation.cs | 2 +- src/mscorlib/src/System/Threading/Tasks/future.cs | 6 +++--- 6 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/mscorlib/shared/System/Threading/Tasks/TaskExtensions.cs b/src/mscorlib/shared/System/Threading/Tasks/TaskExtensions.cs index 1098299517..97f2013d79 100644 --- a/src/mscorlib/shared/System/Threading/Tasks/TaskExtensions.cs +++ b/src/mscorlib/shared/System/Threading/Tasks/TaskExtensions.cs @@ -21,7 +21,7 @@ namespace System.Threading.Tasks // it completed successfully. Return its inner task to avoid unnecessary wrapping, or if the inner // task is null, return a canceled task to match the same semantics as CreateUnwrapPromise. return - !task.IsRanToCompletion ? Task.CreateUnwrapPromise(task, lookForOce: false) : + !task.IsCompletedSuccessfully ? Task.CreateUnwrapPromise(task, lookForOce: false) : task.Result ?? Task.FromCanceled(new CancellationToken(true)); } @@ -40,7 +40,7 @@ namespace System.Threading.Tasks // it completed successfully. Return its inner task to avoid unnecessary wrapping, or if the inner // task is null, return a canceled task to match the same semantics as CreateUnwrapPromise. return - !task.IsRanToCompletion ? Task.CreateUnwrapPromise(task, lookForOce: false) : + !task.IsCompletedSuccessfully ? Task.CreateUnwrapPromise(task, lookForOce: false) : task.Result ?? Task.FromCanceled(new CancellationToken(true)); } diff --git a/src/mscorlib/src/System/IO/Stream.cs b/src/mscorlib/src/System/IO/Stream.cs index 92fe374f19..65cc4ddcb9 100644 --- a/src/mscorlib/src/System/IO/Stream.cs +++ b/src/mscorlib/src/System/IO/Stream.cs @@ -522,14 +522,14 @@ namespace System.IO // If the wait has already completed, run the task. if (asyncWaiter.IsCompleted) { - Debug.Assert(asyncWaiter.IsRanToCompletion, "The semaphore wait should always complete successfully."); + Debug.Assert(asyncWaiter.IsCompletedSuccessfully, "The semaphore wait should always complete successfully."); RunReadWriteTask(readWriteTask); } else // Otherwise, wait for our turn, and then run the task. { asyncWaiter.ContinueWith((t, state) => { - Debug.Assert(t.IsRanToCompletion, "The semaphore wait should always complete successfully."); + Debug.Assert(t.IsCompletedSuccessfully, "The semaphore wait should always complete successfully."); var rwt = (ReadWriteTask)state; rwt._stream.RunReadWriteTask(rwt); // RunReadWriteTask(readWriteTask); }, readWriteTask, default(CancellationToken), TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default); diff --git a/src/mscorlib/src/System/Runtime/CompilerServices/TaskAwaiter.cs b/src/mscorlib/src/System/Runtime/CompilerServices/TaskAwaiter.cs index e2fa6caa2d..c35658e54c 100644 --- a/src/mscorlib/src/System/Runtime/CompilerServices/TaskAwaiter.cs +++ b/src/mscorlib/src/System/Runtime/CompilerServices/TaskAwaiter.cs @@ -146,7 +146,7 @@ namespace System.Runtime.CompilerServices task.NotifyDebuggerOfWaitCompletionIfNecessary(); // And throw an exception if the task is faulted or canceled. - if (!task.IsRanToCompletion) ThrowForNonSuccess(task); + if (!task.IsCompletedSuccessfully) ThrowForNonSuccess(task); } /// Throws an exception to handle a task that completed in a state other than RanToCompletion. diff --git a/src/mscorlib/src/System/Threading/Tasks/Task.cs b/src/mscorlib/src/System/Threading/Tasks/Task.cs index 8e2e6a4cb0..0a9248cba8 100644 --- a/src/mscorlib/src/System/Threading/Tasks/Task.cs +++ b/src/mscorlib/src/System/Threading/Tasks/Task.cs @@ -1467,8 +1467,7 @@ namespace System.Threading.Tasks return (flags & TASK_STATE_COMPLETED_MASK) != 0; } - // For use in InternalWait -- marginally faster than (Task.Status == TaskStatus.RanToCompletion) - internal bool IsRanToCompletion + public bool IsCompletedSuccessfully { get { return (m_stateFlags & TASK_STATE_COMPLETED_MASK) == TASK_STATE_RAN_TO_COMPLETION; } } diff --git a/src/mscorlib/src/System/Threading/Tasks/TaskContinuation.cs b/src/mscorlib/src/System/Threading/Tasks/TaskContinuation.cs index 848a0ecbc2..de222352c9 100644 --- a/src/mscorlib/src/System/Threading/Tasks/TaskContinuation.cs +++ b/src/mscorlib/src/System/Threading/Tasks/TaskContinuation.cs @@ -320,7 +320,7 @@ namespace System.Threading.Tasks // activation criteria of the TaskContinuationOptions. TaskContinuationOptions options = m_options; bool isRightKind = - completedTask.IsRanToCompletion ? + completedTask.IsCompletedSuccessfully ? (options & TaskContinuationOptions.NotOnRanToCompletion) == 0 : (completedTask.IsCanceled ? (options & TaskContinuationOptions.NotOnCanceled) == 0 : diff --git a/src/mscorlib/src/System/Threading/Tasks/future.cs b/src/mscorlib/src/System/Threading/Tasks/future.cs index 26c2388e6b..bf9000ea00 100644 --- a/src/mscorlib/src/System/Threading/Tasks/future.cs +++ b/src/mscorlib/src/System/Threading/Tasks/future.cs @@ -374,7 +374,7 @@ namespace System.Threading.Tasks { get { - return IsRanToCompletion ? "" + m_result : SR.TaskT_DebuggerNoResult; + return IsCompletedSuccessfully ? "" + m_result : SR.TaskT_DebuggerNoResult; } } @@ -491,10 +491,10 @@ namespace System.Threading.Tasks if (waitCompletionNotification) NotifyDebuggerOfWaitCompletionIfNecessary(); // Throw an exception if appropriate. - if (!IsRanToCompletion) ThrowIfExceptional(includeTaskCanceledExceptions: true); + if (!IsCompletedSuccessfully) ThrowIfExceptional(includeTaskCanceledExceptions: true); // We shouldn't be here if the result has not been set. - Debug.Assert(IsRanToCompletion, "Task.Result getter: Expected result to have been set."); + Debug.Assert(IsCompletedSuccessfully, "Task.Result getter: Expected result to have been set."); return m_result; } -- 2.34.1