From: Stephen Toub Date: Tue, 18 Apr 2017 17:57:19 +0000 (-0400) Subject: Expose Task.IsCompletedSuccessfully X-Git-Tag: submit/tizen/20210909.063632~11030^2~7214^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1f0f6cf182a8cc39b79dd6ec102f424f36429e7c;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Expose Task.IsCompletedSuccessfully Commit migrated from https://github.com/dotnet/coreclr/commit/cbd3f54c7dbd3808e2d8b1e4dc1040f511147d19 --- diff --git a/src/coreclr/src/mscorlib/shared/System/Threading/Tasks/TaskExtensions.cs b/src/coreclr/src/mscorlib/shared/System/Threading/Tasks/TaskExtensions.cs index 1098299..97f2013 100644 --- a/src/coreclr/src/mscorlib/shared/System/Threading/Tasks/TaskExtensions.cs +++ b/src/coreclr/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/coreclr/src/mscorlib/src/System/IO/Stream.cs b/src/coreclr/src/mscorlib/src/System/IO/Stream.cs index 92fe374..65cc4dd 100644 --- a/src/coreclr/src/mscorlib/src/System/IO/Stream.cs +++ b/src/coreclr/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/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/TaskAwaiter.cs b/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/TaskAwaiter.cs index e2fa6ca..c35658e 100644 --- a/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/TaskAwaiter.cs +++ b/src/coreclr/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/coreclr/src/mscorlib/src/System/Threading/Tasks/Task.cs b/src/coreclr/src/mscorlib/src/System/Threading/Tasks/Task.cs index 8e2e6a4..0a9248c 100644 --- a/src/coreclr/src/mscorlib/src/System/Threading/Tasks/Task.cs +++ b/src/coreclr/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/coreclr/src/mscorlib/src/System/Threading/Tasks/TaskContinuation.cs b/src/coreclr/src/mscorlib/src/System/Threading/Tasks/TaskContinuation.cs index 848a0ec..de22235 100644 --- a/src/coreclr/src/mscorlib/src/System/Threading/Tasks/TaskContinuation.cs +++ b/src/coreclr/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/coreclr/src/mscorlib/src/System/Threading/Tasks/future.cs b/src/coreclr/src/mscorlib/src/System/Threading/Tasks/future.cs index 26c2388..bf9000e 100644 --- a/src/coreclr/src/mscorlib/src/System/Threading/Tasks/future.cs +++ b/src/coreclr/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; }