From f338eaae1d696e414632ba8f630457f7a0d562ab Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Sat, 4 Feb 2017 14:10:34 -0500 Subject: [PATCH 1/2] Remove NoInlining/StackCrawlMarks from Tasks These crawl marks in Tasks aren't relevant in coreclr (they're passed down to ExecutionContext, which in coreclr just ignores them), yet they required NoInlining, which does impact coreclr. Removing them all from tasks. --- src/mscorlib/src/System/IO/Stream.cs | 6 +- .../Runtime/CompilerServices/TaskAwaiter.cs | 6 +- .../src/System/Threading/CancellationToken.cs | 6 +- .../System/Threading/Tasks/FutureFactory.cs | 144 ++++------- .../src/System/Threading/Tasks/Task.cs | 181 ++++---------- .../Threading/Tasks/TaskContinuation.cs | 38 +-- .../src/System/Threading/Tasks/TaskFactory.cs | 227 +++++------------- .../src/System/Threading/Tasks/future.cs | 150 +++--------- 8 files changed, 183 insertions(+), 575 deletions(-) diff --git a/src/mscorlib/src/System/IO/Stream.cs b/src/mscorlib/src/System/IO/Stream.cs index 3cdfad613ef5..a7dbe4811d92 100644 --- a/src/mscorlib/src/System/IO/Stream.cs +++ b/src/mscorlib/src/System/IO/Stream.cs @@ -617,7 +617,6 @@ private sealed class ReadWriteTask : Task, ITaskCompletionAction _buffer = null; } - [MethodImpl(MethodImplOptions.NoInlining)] public ReadWriteTask( bool isRead, bool apm, @@ -630,8 +629,6 @@ public ReadWriteTask( Contract.Requires(buffer != null); Contract.EndContractBlock(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - // Store the arguments _isRead = isRead; _apm = apm; @@ -648,8 +645,7 @@ public ReadWriteTask( if (callback != null) { _callback = callback; - _context = ExecutionContext.Capture(ref stackMark, - ExecutionContext.CaptureOptions.OptimizeDefaultCase | ExecutionContext.CaptureOptions.IgnoreSyncCtx); + _context = ExecutionContext.Capture(); base.AddCompletionAction(this); } } diff --git a/src/mscorlib/src/System/Runtime/CompilerServices/TaskAwaiter.cs b/src/mscorlib/src/System/Runtime/CompilerServices/TaskAwaiter.cs index 3799f00e2346..f8d33eb80619 100644 --- a/src/mscorlib/src/System/Runtime/CompilerServices/TaskAwaiter.cs +++ b/src/mscorlib/src/System/Runtime/CompilerServices/TaskAwaiter.cs @@ -198,21 +198,19 @@ private static void ThrowForNonSuccess(Task task) /// The argument is null (Nothing in Visual Basic). /// The awaiter was not properly initialized. /// This method is intended for compiler user rather than use directly in code. - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable internal static void OnCompletedInternal(Task task, Action continuation, bool continueOnCapturedContext, bool flowExecutionContext) { if (continuation == null) throw new ArgumentNullException(nameof(continuation)); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; // If TaskWait* ETW events are enabled, trace a beginning event for this await // and set up an ending event to be traced when the asynchronous await completes. - if ( TplEtwProvider.Log.IsEnabled() || Task.s_asyncDebuggingEnabled) + if (TplEtwProvider.Log.IsEnabled() || Task.s_asyncDebuggingEnabled) { continuation = OutputWaitEtwEvents(task, continuation); } // Set the continuation onto the awaited task. - task.SetContinuationForAwait(continuation, continueOnCapturedContext, flowExecutionContext, ref stackMark); + task.SetContinuationForAwait(continuation, continueOnCapturedContext, flowExecutionContext); } /// diff --git a/src/mscorlib/src/System/Threading/CancellationToken.cs b/src/mscorlib/src/System/Threading/CancellationToken.cs index 5b78f20900f1..2ebdb08d7123 100644 --- a/src/mscorlib/src/System/Threading/CancellationToken.cs +++ b/src/mscorlib/src/System/Threading/CancellationToken.cs @@ -317,11 +317,8 @@ internal CancellationTokenRegistration InternalRegisterWithoutEC(Action } // the real work.. - [MethodImpl(MethodImplOptions.NoInlining)] private CancellationTokenRegistration Register(Action callback, Object state, bool useSynchronizationContext, bool useExecutionContext) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - if (callback == null) throw new ArgumentNullException(nameof(callback)); @@ -341,8 +338,7 @@ private CancellationTokenRegistration Register(Action callback, Object s if (useSynchronizationContext) capturedSyncContext = SynchronizationContext.Current; if (useExecutionContext) - capturedExecutionContext = ExecutionContext.Capture( - ref stackMark, ExecutionContext.CaptureOptions.OptimizeDefaultCase); // ideally we'd also use IgnoreSyncCtx, but that could break compat + capturedExecutionContext = ExecutionContext.Capture(); } // Register the callback with the source. diff --git a/src/mscorlib/src/System/Threading/Tasks/FutureFactory.cs b/src/mscorlib/src/System/Threading/Tasks/FutureFactory.cs index c98e219e8686..4d722703994a 100644 --- a/src/mscorlib/src/System/Threading/Tasks/FutureFactory.cs +++ b/src/mscorlib/src/System/Threading/Tasks/FutureFactory.cs @@ -277,13 +277,11 @@ public TaskFactory(CancellationToken cancellationToken, TaskCreationOptions crea /// However, unless creation and scheduling must be separated, StartNew is the recommended approach /// for both simplicity and performance. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task StartNew(Func function) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; Task currTask = Task.InternalCurrent; return Task.StartNew(currTask, function, m_defaultCancellationToken, - m_defaultCreationOptions, InternalTaskOptions.None, GetDefaultScheduler(currTask), ref stackMark); + m_defaultCreationOptions, InternalTaskOptions.None, GetDefaultScheduler(currTask)); } /// @@ -306,13 +304,11 @@ public Task StartNew(Func function) /// However, unless creation and scheduling must be separated, StartNew is the recommended approach /// for both simplicity and performance. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task StartNew(Func function, CancellationToken cancellationToken) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; Task currTask = Task.InternalCurrent; return Task.StartNew(currTask, function, cancellationToken, - m_defaultCreationOptions, InternalTaskOptions.None, GetDefaultScheduler(currTask), ref stackMark); + m_defaultCreationOptions, InternalTaskOptions.None, GetDefaultScheduler(currTask)); } /// @@ -337,13 +333,11 @@ public Task StartNew(Func function, CancellationToken cancella /// However, unless creation and scheduling must be separated, StartNew is the recommended approach /// for both simplicity and performance. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task StartNew(Func function, TaskCreationOptions creationOptions) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; Task currTask = Task.InternalCurrent; return Task.StartNew(currTask, function, m_defaultCancellationToken, - creationOptions, InternalTaskOptions.None, GetDefaultScheduler(currTask), ref stackMark); + creationOptions, InternalTaskOptions.None, GetDefaultScheduler(currTask)); } /// @@ -379,13 +373,11 @@ public Task StartNew(Func function, TaskCreationOptions creati /// However, unless creation and scheduling must be separated, StartNew is the recommended approach /// for both simplicity and performance. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task StartNew(Func function, CancellationToken cancellationToken, TaskCreationOptions creationOptions, TaskScheduler scheduler) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; return Task.StartNew( Task.InternalCurrentIfAttached(creationOptions), function, cancellationToken, - creationOptions, InternalTaskOptions.None, scheduler, ref stackMark); + creationOptions, InternalTaskOptions.None, scheduler); } /// @@ -406,13 +398,11 @@ public Task StartNew(Func function, CancellationToken cancella /// However, unless creation and scheduling must be separated, StartNew is the recommended approach /// for both simplicity and performance. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task StartNew(Func function, Object state) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; Task currTask = Task.InternalCurrent; return Task.StartNew(currTask, function, state, m_defaultCancellationToken, - m_defaultCreationOptions, InternalTaskOptions.None, GetDefaultScheduler(currTask), ref stackMark); + m_defaultCreationOptions, InternalTaskOptions.None, GetDefaultScheduler(currTask)); } /// @@ -437,13 +427,11 @@ public Task StartNew(Func function, Object state) /// However, unless creation and scheduling must be separated, StartNew is the recommended approach /// for both simplicity and performance. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task StartNew(Func function, Object state, CancellationToken cancellationToken) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; Task currTask = Task.InternalCurrent; return Task.StartNew(currTask, function, state, cancellationToken, - m_defaultCreationOptions, InternalTaskOptions.None, GetDefaultScheduler(currTask), ref stackMark); + m_defaultCreationOptions, InternalTaskOptions.None, GetDefaultScheduler(currTask)); } /// @@ -470,13 +458,11 @@ public Task StartNew(Func function, Object state, Canc /// However, unless creation and scheduling must be separated, StartNew is the recommended approach /// for both simplicity and performance. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task StartNew(Func function, Object state, TaskCreationOptions creationOptions) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; Task currTask = Task.InternalCurrent; return Task.StartNew(currTask, function, state, m_defaultCancellationToken, - creationOptions, InternalTaskOptions.None, GetDefaultScheduler(currTask), ref stackMark); + creationOptions, InternalTaskOptions.None, GetDefaultScheduler(currTask)); } /// @@ -514,12 +500,10 @@ public Task StartNew(Func function, Object state, Task /// However, unless creation and scheduling must be separated, StartNew is the recommended approach /// for both simplicity and performance. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task StartNew(Func function, Object state, CancellationToken cancellationToken, TaskCreationOptions creationOptions, TaskScheduler scheduler) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; return Task.StartNew(Task.InternalCurrentIfAttached(creationOptions), function, state, cancellationToken, - creationOptions, InternalTaskOptions.None, scheduler, ref stackMark); + creationOptions, InternalTaskOptions.None, scheduler); } // @@ -604,11 +588,9 @@ private static void FromAsyncCoreLogic( /// argument is null. /// A Task that represents the /// asynchronous operation. - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task FromAsync(IAsyncResult asyncResult, Func endMethod) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return FromAsyncImpl(asyncResult, endMethod, null, m_defaultCreationOptions, DefaultScheduler, ref stackMark); + return FromAsyncImpl(asyncResult, endMethod, null, m_defaultCreationOptions, DefaultScheduler); } /// @@ -630,14 +612,12 @@ public Task FromAsync(IAsyncResult asyncResult, Func /// A Task that represents the /// asynchronous operation. - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task FromAsync( IAsyncResult asyncResult, Func endMethod, TaskCreationOptions creationOptions) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return FromAsyncImpl(asyncResult, endMethod, null, creationOptions, DefaultScheduler, ref stackMark); + return FromAsyncImpl(asyncResult, endMethod, null, creationOptions, DefaultScheduler); } @@ -665,27 +645,23 @@ public Task FromAsync( /// value. /// A Task that represents the /// asynchronous operation. - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task FromAsync( IAsyncResult asyncResult, Func endMethod, TaskCreationOptions creationOptions, TaskScheduler scheduler) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return FromAsyncImpl(asyncResult, endMethod, null, creationOptions, scheduler, ref stackMark); + return FromAsyncImpl(asyncResult, endMethod, null, creationOptions, scheduler); } - // internal overload that supports StackCrawlMark - // We also need this logic broken out into a static method so that the similar TaskFactory.FromAsync() + // We need this logic broken out into a static method so that the similar TaskFactory.FromAsync() // method can access the logic w/o declaring a TaskFactory instance. internal static Task FromAsyncImpl( IAsyncResult asyncResult, Func endFunction, Action endAction, TaskCreationOptions creationOptions, - TaskScheduler scheduler, - ref StackCrawlMark stackMark) + TaskScheduler scheduler) { if (asyncResult == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.asyncResult); @@ -714,12 +690,12 @@ internal static Task FromAsyncImpl( // Just specify this task as detached. No matter what happens, we want endMethod // to be called -- even if the parent is canceled. So we don't want to flow // RespectParentCancellation. - Task t = new Task(delegate + Task t = new Task(new Action(delegate { FromAsyncCoreLogic(asyncResult, endFunction, endAction, promise, requiresSynchronization:true); - }, + }), (object)null, null, - default(CancellationToken), TaskCreationOptions.None, InternalTaskOptions.None, null, ref stackMark); + default(CancellationToken), TaskCreationOptions.None, InternalTaskOptions.None, null); if (AsyncCausalityTracer.LoggingOn) AsyncCausalityTracer.TraceOperationCreation(CausalityTraceLevel.Verbose, t.Id, "TaskFactory.FromAsync Callback", 0); @@ -1428,14 +1404,12 @@ private static Task CreateCanceledTask(TaskContinuationOptions continua /// array contains a null value. /// The exception that is thrown when the /// array is empty. - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAll(Task[] tasks, Func continuationFunction) { if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction); Contract.EndContractBlock(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWhenAllImpl(tasks, continuationFunction, null, m_defaultContinuationOptions, m_defaultCancellationToken, DefaultScheduler, ref stackMark); + return ContinueWhenAllImpl(tasks, continuationFunction, null, m_defaultContinuationOptions, m_defaultCancellationToken, DefaultScheduler); } /// @@ -1459,14 +1433,12 @@ public Task ContinueWhenAll(Task[] tasks, Func continu /// The provided CancellationToken /// has already been disposed. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAll(Task[] tasks, Func continuationFunction, CancellationToken cancellationToken) { if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction); Contract.EndContractBlock(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWhenAllImpl(tasks, continuationFunction, null, m_defaultContinuationOptions, cancellationToken, DefaultScheduler, ref stackMark); + return ContinueWhenAllImpl(tasks, continuationFunction, null, m_defaultContinuationOptions, cancellationToken, DefaultScheduler); } /// @@ -1496,14 +1468,12 @@ public Task ContinueWhenAll(Task[] tasks, Func continu /// which constrain for which TaskStatus states a continuation /// will be executed, are illegal with ContinueWhenAll. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAll(Task[] tasks, Func continuationFunction, TaskContinuationOptions continuationOptions) { if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction); Contract.EndContractBlock(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWhenAllImpl(tasks, continuationFunction, null, continuationOptions, m_defaultCancellationToken, DefaultScheduler, ref stackMark); + return ContinueWhenAllImpl(tasks, continuationFunction, null, continuationOptions, m_defaultCancellationToken, DefaultScheduler); } /// @@ -1543,15 +1513,13 @@ public Task ContinueWhenAll(Task[] tasks, Func continu /// which constrain for which TaskStatus states a continuation /// will be executed, are illegal with ContinueWhenAll. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAll(Task[] tasks, Func continuationFunction, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler) { if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction); Contract.EndContractBlock(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWhenAllImpl(tasks, continuationFunction, null, continuationOptions, cancellationToken, scheduler, ref stackMark); + return ContinueWhenAllImpl(tasks, continuationFunction, null, continuationOptions, cancellationToken, scheduler); } /// @@ -1571,14 +1539,12 @@ public Task ContinueWhenAll(Task[] tasks, Func continu /// array contains a null value. /// The exception that is thrown when the /// array is empty. - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAll(Task[] tasks, Func[], TResult> continuationFunction) { if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction); Contract.EndContractBlock(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWhenAllImpl(tasks, continuationFunction, null, m_defaultContinuationOptions, m_defaultCancellationToken, DefaultScheduler, ref stackMark); + return ContinueWhenAllImpl(tasks, continuationFunction, null, m_defaultContinuationOptions, m_defaultCancellationToken, DefaultScheduler); } /// @@ -1603,15 +1569,13 @@ public Task ContinueWhenAll(Task[ /// The provided CancellationToken /// has already been disposed. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAll(Task[] tasks, Func[], TResult> continuationFunction, CancellationToken cancellationToken) { if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction); Contract.EndContractBlock(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWhenAllImpl(tasks, continuationFunction, null, m_defaultContinuationOptions, cancellationToken, DefaultScheduler, ref stackMark); + return ContinueWhenAllImpl(tasks, continuationFunction, null, m_defaultContinuationOptions, cancellationToken, DefaultScheduler); } /// @@ -1642,15 +1606,13 @@ public Task ContinueWhenAll(Task[ /// which constrain for which TaskStatus states a continuation /// will be executed, are illegal with ContinueWhenAll. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAll(Task[] tasks, Func[], TResult> continuationFunction, TaskContinuationOptions continuationOptions) { if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction); Contract.EndContractBlock(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWhenAllImpl(tasks, continuationFunction, null, continuationOptions, m_defaultCancellationToken, DefaultScheduler, ref stackMark); + return ContinueWhenAllImpl(tasks, continuationFunction, null, continuationOptions, m_defaultCancellationToken, DefaultScheduler); } /// @@ -1691,15 +1653,13 @@ public Task ContinueWhenAll(Task[ /// which constrain for which TaskStatus states a continuation /// will be executed, are illegal with ContinueWhenAll. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAll(Task[] tasks, Func[], TResult> continuationFunction, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler) { if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction); Contract.EndContractBlock(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWhenAllImpl(tasks, continuationFunction, null, continuationOptions, cancellationToken, scheduler, ref stackMark); + return ContinueWhenAllImpl(tasks, continuationFunction, null, continuationOptions, cancellationToken, scheduler); } @@ -1707,7 +1667,7 @@ public Task ContinueWhenAll(Task[ // Note: if you make any changes to this method, please do the same to the non-generic version too. internal static Task ContinueWhenAllImpl(Task[] tasks, Func[], TResult> continuationFunction, Action[]> continuationAction, - TaskContinuationOptions continuationOptions, CancellationToken cancellationToken, TaskScheduler scheduler, ref StackCrawlMark stackMark) + TaskContinuationOptions continuationOptions, CancellationToken cancellationToken, TaskScheduler scheduler) { // check arguments TaskFactory.CheckMultiTaskContinuationOptions(continuationOptions); @@ -1737,7 +1697,7 @@ internal static Task ContinueWhenAllImpl(Task( // use a cached delegate GenericDelegateCache.CWAllFuncDelegate, - continuationFunction, scheduler, cancellationToken, continuationOptions, ref stackMark); + continuationFunction, scheduler, cancellationToken, continuationOptions); } else { @@ -1746,7 +1706,7 @@ internal static Task ContinueWhenAllImpl(Task( // use a cached delegate GenericDelegateCache.CWAllActionDelegate, - continuationAction, scheduler, cancellationToken, continuationOptions, ref stackMark); + continuationAction, scheduler, cancellationToken, continuationOptions); } } @@ -1754,7 +1714,7 @@ internal static Task ContinueWhenAllImpl(Task ContinueWhenAllImpl(Task[] tasks, Func continuationFunction, Action continuationAction, - TaskContinuationOptions continuationOptions, CancellationToken cancellationToken, TaskScheduler scheduler, ref StackCrawlMark stackMark) + TaskContinuationOptions continuationOptions, CancellationToken cancellationToken, TaskScheduler scheduler) { // check arguments TaskFactory.CheckMultiTaskContinuationOptions(continuationOptions); @@ -1790,7 +1750,7 @@ internal static Task ContinueWhenAllImpl(Task[] tasks, completedTasks.NotifyDebuggerOfWaitCompletionIfNecessary(); return ((Func)state)(completedTasks.Result); }, - continuationFunction, scheduler, cancellationToken, continuationOptions, ref stackMark); + continuationFunction, scheduler, cancellationToken, continuationOptions); } else { @@ -1804,7 +1764,7 @@ internal static Task ContinueWhenAllImpl(Task[] tasks, completedTasks.NotifyDebuggerOfWaitCompletionIfNecessary(); ((Action)state)(completedTasks.Result); return default(TResult); }, - continuationAction, scheduler, cancellationToken, continuationOptions, ref stackMark); + continuationAction, scheduler, cancellationToken, continuationOptions); } } @@ -1828,14 +1788,12 @@ internal static Task ContinueWhenAllImpl(Task[] tasks, /// array contains a null value. /// The exception that is thrown when the /// array is empty. - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAny(Task[] tasks, Func continuationFunction) { if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction); Contract.EndContractBlock(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWhenAnyImpl(tasks, continuationFunction, null, m_defaultContinuationOptions, m_defaultCancellationToken, DefaultScheduler, ref stackMark); + return ContinueWhenAnyImpl(tasks, continuationFunction, null, m_defaultContinuationOptions, m_defaultCancellationToken, DefaultScheduler); } /// @@ -1859,14 +1817,12 @@ public Task ContinueWhenAny(Task[] tasks, Func continuat /// The provided CancellationToken /// has already been disposed. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAny(Task[] tasks, Func continuationFunction, CancellationToken cancellationToken) { if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction); Contract.EndContractBlock(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWhenAnyImpl(tasks, continuationFunction, null, m_defaultContinuationOptions, cancellationToken, DefaultScheduler, ref stackMark); + return ContinueWhenAnyImpl(tasks, continuationFunction, null, m_defaultContinuationOptions, cancellationToken, DefaultScheduler); } /// @@ -1896,14 +1852,12 @@ public Task ContinueWhenAny(Task[] tasks, Func continuat /// which constrain for which TaskStatus states a continuation /// will be executed, are illegal with ContinueWhenAny. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAny(Task[] tasks, Func continuationFunction, TaskContinuationOptions continuationOptions) { if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction); Contract.EndContractBlock(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWhenAnyImpl(tasks, continuationFunction, null, continuationOptions, m_defaultCancellationToken, DefaultScheduler, ref stackMark); + return ContinueWhenAnyImpl(tasks, continuationFunction, null, continuationOptions, m_defaultCancellationToken, DefaultScheduler); } /// @@ -1943,15 +1897,13 @@ public Task ContinueWhenAny(Task[] tasks, Func continuat /// which constrain for which TaskStatus states a continuation /// will be executed, are illegal with ContinueWhenAny. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAny(Task[] tasks, Func continuationFunction, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler) { if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction); Contract.EndContractBlock(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWhenAnyImpl(tasks, continuationFunction, null, continuationOptions, cancellationToken, scheduler, ref stackMark); + return ContinueWhenAnyImpl(tasks, continuationFunction, null, continuationOptions, cancellationToken, scheduler); } /// @@ -1971,14 +1923,12 @@ public Task ContinueWhenAny(Task[] tasks, Func continuat /// array contains a null value. /// The exception that is thrown when the /// array is empty. - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAny(Task[] tasks, Func, TResult> continuationFunction) { if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction); Contract.EndContractBlock(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWhenAnyImpl(tasks, continuationFunction, null, m_defaultContinuationOptions, m_defaultCancellationToken, DefaultScheduler, ref stackMark); + return ContinueWhenAnyImpl(tasks, continuationFunction, null, m_defaultContinuationOptions, m_defaultCancellationToken, DefaultScheduler); } /// @@ -2003,15 +1953,13 @@ public Task ContinueWhenAny(Task[ /// The provided CancellationToken /// has already been disposed. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAny(Task[] tasks, Func, TResult> continuationFunction, CancellationToken cancellationToken) { if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction); Contract.EndContractBlock(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWhenAnyImpl(tasks, continuationFunction, null, m_defaultContinuationOptions, cancellationToken, DefaultScheduler, ref stackMark); + return ContinueWhenAnyImpl(tasks, continuationFunction, null, m_defaultContinuationOptions, cancellationToken, DefaultScheduler); } /// @@ -2042,15 +1990,13 @@ public Task ContinueWhenAny(Task[ /// which constrain for which TaskStatus states a continuation /// will be executed, are illegal with ContinueWhenAny. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAny(Task[] tasks, Func, TResult> continuationFunction, TaskContinuationOptions continuationOptions) { if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction); Contract.EndContractBlock(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWhenAnyImpl(tasks, continuationFunction, null, continuationOptions, m_defaultCancellationToken, DefaultScheduler, ref stackMark); + return ContinueWhenAnyImpl(tasks, continuationFunction, null, continuationOptions, m_defaultCancellationToken, DefaultScheduler); } /// @@ -2091,22 +2037,20 @@ public Task ContinueWhenAny(Task[ /// which constrain for which TaskStatus states a continuation /// will be executed, are illegal with ContinueWhenAny. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAny(Task[] tasks, Func, TResult> continuationFunction, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler) { if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction); Contract.EndContractBlock(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWhenAnyImpl(tasks, continuationFunction, null, continuationOptions, cancellationToken, scheduler, ref stackMark); + return ContinueWhenAnyImpl(tasks, continuationFunction, null, continuationOptions, cancellationToken, scheduler); } // Core implementation of ContinueWhenAny, non-generic version // Note: if you make any changes to this method, be sure to do the same to the generic version internal static Task ContinueWhenAnyImpl(Task[] tasks, Func continuationFunction, Action continuationAction, - TaskContinuationOptions continuationOptions, CancellationToken cancellationToken, TaskScheduler scheduler, ref StackCrawlMark stackMark) + TaskContinuationOptions continuationOptions, CancellationToken cancellationToken, TaskScheduler scheduler) { // check arguments TaskFactory.CheckMultiTaskContinuationOptions(continuationOptions); @@ -2136,7 +2080,7 @@ internal static Task ContinueWhenAnyImpl(Task[] tasks, //the following delegate avoids closure capture as much as possible //completedTask.Result is the winning task; state == continuationAction (completedTask, state) => { return ((Func)state)(completedTask.Result); }, - continuationFunction, scheduler, cancellationToken, continuationOptions, ref stackMark); + continuationFunction, scheduler, cancellationToken, continuationOptions); } else { @@ -2145,7 +2089,7 @@ internal static Task ContinueWhenAnyImpl(Task[] tasks, //the following delegate avoids closure capture as much as possible //completedTask.Result is the winning task; state == continuationAction (completedTask, state) => { ((Action)state)(completedTask.Result); return default(TResult); }, - continuationAction, scheduler, cancellationToken, continuationOptions, ref stackMark); + continuationAction, scheduler, cancellationToken, continuationOptions); } } @@ -2154,7 +2098,7 @@ internal static Task ContinueWhenAnyImpl(Task[] tasks, // Note: if you make any changes to this method, be sure to do the same to the non-generic version internal static Task ContinueWhenAnyImpl(Task[] tasks, Func, TResult> continuationFunction, Action> continuationAction, - TaskContinuationOptions continuationOptions, CancellationToken cancellationToken, TaskScheduler scheduler, ref StackCrawlMark stackMark) + TaskContinuationOptions continuationOptions, CancellationToken cancellationToken, TaskScheduler scheduler) { // check arguments TaskFactory.CheckMultiTaskContinuationOptions(continuationOptions); @@ -2182,7 +2126,7 @@ internal static Task ContinueWhenAnyImpl(Task( // Use a cached delegate GenericDelegateCache.CWAnyFuncDelegate, - continuationFunction, scheduler, cancellationToken, continuationOptions, ref stackMark); + continuationFunction, scheduler, cancellationToken, continuationOptions); } else { @@ -2190,7 +2134,7 @@ internal static Task ContinueWhenAnyImpl(Task( // Use a cached delegate GenericDelegateCache.CWAnyActionDelegate, - continuationAction, scheduler, cancellationToken, continuationOptions, ref stackMark); + continuationAction, scheduler, cancellationToken, continuationOptions); } } } diff --git a/src/mscorlib/src/System/Threading/Tasks/Task.cs b/src/mscorlib/src/System/Threading/Tasks/Task.cs index 5618f5981389..1426f71da2b7 100644 --- a/src/mscorlib/src/System/Threading/Tasks/Task.cs +++ b/src/mscorlib/src/System/Threading/Tasks/Task.cs @@ -364,12 +364,9 @@ internal Task(object state, TaskCreationOptions creationOptions, bool promiseSty /// /// The delegate that represents the code to execute in the Task. /// The argument is null. - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task(Action action) : this(action, null, null, default(CancellationToken), TaskCreationOptions.None, InternalTaskOptions.None, null) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - PossiblyCaptureContext(ref stackMark); } /// @@ -382,12 +379,9 @@ public Task(Action action) /// The provided CancellationToken /// has already been disposed. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task(Action action, CancellationToken cancellationToken) : this(action, null, null, cancellationToken, TaskCreationOptions.None, InternalTaskOptions.None, null) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - PossiblyCaptureContext(ref stackMark); } /// @@ -405,12 +399,9 @@ public Task(Action action, CancellationToken cancellationToken) /// The argument specifies an invalid value for . /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task(Action action, TaskCreationOptions creationOptions) : this(action, null, Task.InternalCurrentIfAttached(creationOptions), default(CancellationToken), creationOptions, InternalTaskOptions.None, null) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - PossiblyCaptureContext(ref stackMark); } /// @@ -432,12 +423,9 @@ public Task(Action action, TaskCreationOptions creationOptions) /// The provided CancellationToken /// has already been disposed. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task(Action action, CancellationToken cancellationToken, TaskCreationOptions creationOptions) : this(action, null, Task.InternalCurrentIfAttached(creationOptions), cancellationToken, creationOptions, InternalTaskOptions.None, null) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - PossiblyCaptureContext(ref stackMark); } @@ -449,12 +437,9 @@ public Task(Action action, CancellationToken cancellationToken, TaskCreationOpti /// /// The argument is null. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task(Action action, object state) : this(action, state, null, default(CancellationToken), TaskCreationOptions.None, InternalTaskOptions.None, null) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - PossiblyCaptureContext(ref stackMark); } /// @@ -469,12 +454,9 @@ public Task(Action action, object state) /// The provided CancellationToken /// has already been disposed. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task(Action action, object state, CancellationToken cancellationToken) : this(action, state, null, cancellationToken, TaskCreationOptions.None, InternalTaskOptions.None, null) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - PossiblyCaptureContext(ref stackMark); } /// @@ -493,12 +475,9 @@ public Task(Action action, object state, CancellationToken cancellationT /// The argument specifies an invalid value for . /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task(Action action, object state, TaskCreationOptions creationOptions) : this(action, state, Task.InternalCurrentIfAttached(creationOptions), default(CancellationToken), creationOptions, InternalTaskOptions.None, null) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - PossiblyCaptureContext(ref stackMark); } /// @@ -521,19 +500,9 @@ public Task(Action action, object state, TaskCreationOptions creationOpt /// The provided CancellationToken /// has already been disposed. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task(Action action, object state, CancellationToken cancellationToken, TaskCreationOptions creationOptions) : this(action, state, Task.InternalCurrentIfAttached(creationOptions), cancellationToken, creationOptions, InternalTaskOptions.None, null) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - PossiblyCaptureContext(ref stackMark); - } - - internal Task(Action action, object state, Task parent, CancellationToken cancellationToken, - TaskCreationOptions creationOptions, InternalTaskOptions internalOptions, TaskScheduler scheduler, ref StackCrawlMark stackMark) - : this(action, state, parent, cancellationToken, creationOptions, internalOptions, scheduler) - { - PossiblyCaptureContext(ref stackMark); } /// @@ -583,6 +552,10 @@ internal void TaskConstructorCore(Delegate action, object state, CancellationTok m_stateObject = state; m_taskScheduler = scheduler; + Debug.Assert(m_contingentProperties == null || m_contingentProperties.m_capturedContext == null, + "Captured an ExecutionContext when one was already captured."); + CapturedContext = ExecutionContext.Capture(); + // Check for validity of options if ((creationOptions & ~(TaskCreationOptions.AttachedToParent | @@ -743,24 +716,6 @@ private string DebuggerDisplayMethodDescription } } - - /// - /// Captures the ExecutionContext so long as flow isn't suppressed. - /// - /// A stack crawl mark pointing to the frame of the caller. - - internal void PossiblyCaptureContext(ref StackCrawlMark stackMark) - { - Debug.Assert(m_contingentProperties == null || m_contingentProperties.m_capturedContext == null, - "Captured an ExecutionContext when one was already captured."); - - // In the legacy .NET 3.5 build, we don't have the optimized overload of Capture() - // available, so we call the parameterless overload. - CapturedContext = ExecutionContext.Capture( - ref stackMark, - ExecutionContext.CaptureOptions.IgnoreSyncCtx | ExecutionContext.CaptureOptions.OptimizeDefaultCase); - } - // Internal property to process TaskCreationOptions access and mutation. internal TaskCreationOptions Options { @@ -1248,7 +1203,7 @@ internal void InternalRunSynchronously(TaskScheduler scheduler, bool waitForComp // Implicitly converts action to object and handles the meat of the StartNew() logic. internal static Task InternalStartNew( Task creatingTask, Delegate action, object state, CancellationToken cancellationToken, TaskScheduler scheduler, - TaskCreationOptions options, InternalTaskOptions internalOptions, ref StackCrawlMark stackMark) + TaskCreationOptions options, InternalTaskOptions internalOptions) { // Validate arguments. if (scheduler == null) @@ -1260,7 +1215,6 @@ internal static Task InternalStartNew( // Create and schedule the task. This throws an InvalidOperationException if already shut down. // Here we add the InternalTaskOptions.QueuedByRuntime to the internalOptions, so that TaskConstructorCore can skip the cancellation token registration Task t = new Task(action, state, creatingTask, cancellationToken, options, internalOptions | InternalTaskOptions.QueuedByRuntime, scheduler); - t.PossiblyCaptureContext(ref stackMark); t.ScheduleAndStart(false); return t; @@ -2633,10 +2587,9 @@ public ConfiguredTaskAwaitable ConfigureAwait(bool continueOnCapturedContext) /// true to attempt to marshal the continuation back to the original context captured; otherwise, false. /// /// Whether to flow ExecutionContext across the await. - /// A stack crawl mark tied to execution context. /// The awaiter was not properly initialized. internal void SetContinuationForAwait( - Action continuationAction, bool continueOnCapturedContext, bool flowExecutionContext, ref StackCrawlMark stackMark) + Action continuationAction, bool continueOnCapturedContext, bool flowExecutionContext) { Contract.Requires(continuationAction != null); @@ -2657,7 +2610,7 @@ internal void SetContinuationForAwait( var syncCtx = SynchronizationContext.CurrentNoFlow; if (syncCtx != null && syncCtx.GetType() != typeof(SynchronizationContext)) { - tc = new SynchronizationContextAwaitTaskContinuation(syncCtx, continuationAction, flowExecutionContext, ref stackMark); + tc = new SynchronizationContextAwaitTaskContinuation(syncCtx, continuationAction, flowExecutionContext); } else { @@ -2666,7 +2619,7 @@ internal void SetContinuationForAwait( var scheduler = TaskScheduler.InternalCurrent; if (scheduler != null && scheduler != TaskScheduler.Default) { - tc = new TaskSchedulerAwaitTaskContinuation(scheduler, continuationAction, flowExecutionContext, ref stackMark); + tc = new TaskSchedulerAwaitTaskContinuation(scheduler, continuationAction, flowExecutionContext); } } } @@ -2678,7 +2631,7 @@ internal void SetContinuationForAwait( // ExecutionContext, we need to capture it and wrap it in an AwaitTaskContinuation. // Otherwise, we're targeting the default scheduler and we don't need to flow ExecutionContext, so // we don't actually need a continuation object. We can just store/queue the action itself. - tc = new AwaitTaskContinuation(continuationAction, flowExecutionContext: true, stackMark: ref stackMark); + tc = new AwaitTaskContinuation(continuationAction, flowExecutionContext: true); } // Now register the continuation, and if we couldn't register it because the task is already completing, @@ -3431,11 +3384,9 @@ private void LogFinishCompletionNotification() /// /// The argument is null. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWith(Action continuationAction) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWith(continuationAction, TaskScheduler.Current, default(CancellationToken), TaskContinuationOptions.None, ref stackMark); + return ContinueWith(continuationAction, TaskScheduler.Current, default(CancellationToken), TaskContinuationOptions.None); } /// @@ -3458,11 +3409,9 @@ public Task ContinueWith(Action continuationAction) /// The provided CancellationToken /// has already been disposed. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWith(Action continuationAction, CancellationToken cancellationToken) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWith(continuationAction, TaskScheduler.Current, cancellationToken, TaskContinuationOptions.None, ref stackMark); + return ContinueWith(continuationAction, TaskScheduler.Current, cancellationToken, TaskContinuationOptions.None); } /// @@ -3487,11 +3436,9 @@ public Task ContinueWith(Action continuationAction, CancellationToken canc /// /// The argument is null. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWith(Action continuationAction, TaskScheduler scheduler) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWith(continuationAction, scheduler, default(CancellationToken), TaskContinuationOptions.None, ref stackMark); + return ContinueWith(continuationAction, scheduler, default(CancellationToken), TaskContinuationOptions.None); } /// @@ -3522,11 +3469,9 @@ public Task ContinueWith(Action continuationAction, TaskScheduler schedule /// The argument specifies an invalid value for TaskContinuationOptions. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWith(Action continuationAction, TaskContinuationOptions continuationOptions) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWith(continuationAction, TaskScheduler.Current, default(CancellationToken), continuationOptions, ref stackMark); + return ContinueWith(continuationAction, TaskScheduler.Current, default(CancellationToken), continuationOptions); } /// @@ -3567,17 +3512,15 @@ public Task ContinueWith(Action continuationAction, TaskContinuationOption /// The provided CancellationToken /// has already been disposed. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWith(Action continuationAction, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWith(continuationAction, scheduler, cancellationToken, continuationOptions, ref stackMark); + return ContinueWith(continuationAction, scheduler, cancellationToken, continuationOptions); } // Same as the above overload, just with a stack mark parameter. private Task ContinueWith(Action continuationAction, TaskScheduler scheduler, - CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, ref StackCrawlMark stackMark) + CancellationToken cancellationToken, TaskContinuationOptions continuationOptions) { // Throw on continuation with null action if (continuationAction == null) @@ -3598,8 +3541,7 @@ private Task ContinueWith(Action continuationAction, TaskScheduler schedul Task continuationTask = new ContinuationTaskFromTask( this, continuationAction, null, - creationOptions, internalOptions, - ref stackMark + creationOptions, internalOptions ); // Register the continuation. If synchronous execution is requested, this may @@ -3629,11 +3571,9 @@ ref stackMark /// /// The argument is null. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWith(Action continuationAction, Object state) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWith(continuationAction, state, TaskScheduler.Current, default(CancellationToken), TaskContinuationOptions.None, ref stackMark); + return ContinueWith(continuationAction, state, TaskScheduler.Current, default(CancellationToken), TaskContinuationOptions.None); } /// @@ -3657,11 +3597,9 @@ public Task ContinueWith(Action continuationAction, Object state) /// The provided CancellationToken /// has already been disposed. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWith(Action continuationAction, Object state, CancellationToken cancellationToken) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWith(continuationAction, state, TaskScheduler.Current, cancellationToken, TaskContinuationOptions.None, ref stackMark); + return ContinueWith(continuationAction, state, TaskScheduler.Current, cancellationToken, TaskContinuationOptions.None); } /// @@ -3687,11 +3625,9 @@ public Task ContinueWith(Action continuationAction, Object state, /// /// The argument is null. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWith(Action continuationAction, Object state, TaskScheduler scheduler) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWith(continuationAction, state, scheduler, default(CancellationToken), TaskContinuationOptions.None, ref stackMark); + return ContinueWith(continuationAction, state, scheduler, default(CancellationToken), TaskContinuationOptions.None); } /// @@ -3723,11 +3659,9 @@ public Task ContinueWith(Action continuationAction, Object state, /// The argument specifies an invalid value for TaskContinuationOptions. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWith(Action continuationAction, Object state, TaskContinuationOptions continuationOptions) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWith(continuationAction, state, TaskScheduler.Current, default(CancellationToken), continuationOptions, ref stackMark); + return ContinueWith(continuationAction, state, TaskScheduler.Current, default(CancellationToken), continuationOptions); } /// @@ -3769,17 +3703,15 @@ public Task ContinueWith(Action continuationAction, Object state, /// The provided CancellationToken /// has already been disposed. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWith(Action continuationAction, Object state, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWith(continuationAction, state, scheduler, cancellationToken, continuationOptions, ref stackMark); + return ContinueWith(continuationAction, state, scheduler, cancellationToken, continuationOptions); } // Same as the above overload, just with a stack mark parameter. private Task ContinueWith(Action continuationAction, Object state, TaskScheduler scheduler, - CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, ref StackCrawlMark stackMark) + CancellationToken cancellationToken, TaskContinuationOptions continuationOptions) { // Throw on continuation with null action if (continuationAction == null) @@ -3800,8 +3732,7 @@ private Task ContinueWith(Action continuationAction, Object state, Task continuationTask = new ContinuationTaskFromTask( this, continuationAction, state, - creationOptions, internalOptions, - ref stackMark + creationOptions, internalOptions ); // Register the continuation. If synchronous execution is requested, this may @@ -3834,12 +3765,10 @@ ref stackMark /// /// The argument is null. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWith(Func continuationFunction) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; return ContinueWith(continuationFunction, TaskScheduler.Current, default(CancellationToken), - TaskContinuationOptions.None, ref stackMark); + TaskContinuationOptions.None); } @@ -3866,11 +3795,9 @@ public Task ContinueWith(Func continuationFunct /// The provided CancellationToken /// has already been disposed. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWith(Func continuationFunction, CancellationToken cancellationToken) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWith(continuationFunction, TaskScheduler.Current, cancellationToken, TaskContinuationOptions.None, ref stackMark); + return ContinueWith(continuationFunction, TaskScheduler.Current, cancellationToken, TaskContinuationOptions.None); } /// @@ -3898,11 +3825,9 @@ public Task ContinueWith(Func continuationFunct /// /// The argument is null. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWith(Func continuationFunction, TaskScheduler scheduler) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWith(continuationFunction, scheduler, default(CancellationToken), TaskContinuationOptions.None, ref stackMark); + return ContinueWith(continuationFunction, scheduler, default(CancellationToken), TaskContinuationOptions.None); } /// @@ -3936,11 +3861,9 @@ public Task ContinueWith(Func continuationFunct /// The argument specifies an invalid value for TaskContinuationOptions. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWith(Func continuationFunction, TaskContinuationOptions continuationOptions) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWith(continuationFunction, TaskScheduler.Current, default(CancellationToken), continuationOptions, ref stackMark); + return ContinueWith(continuationFunction, TaskScheduler.Current, default(CancellationToken), continuationOptions); } /// @@ -3984,17 +3907,15 @@ public Task ContinueWith(Func continuationFunct /// The provided CancellationToken /// has already been disposed. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWith(Func continuationFunction, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWith(continuationFunction, scheduler, cancellationToken, continuationOptions, ref stackMark); + return ContinueWith(continuationFunction, scheduler, cancellationToken, continuationOptions); } // Same as the above overload, just with a stack mark parameter. private Task ContinueWith(Func continuationFunction, TaskScheduler scheduler, - CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, ref StackCrawlMark stackMark) + CancellationToken cancellationToken, TaskContinuationOptions continuationOptions) { // Throw on continuation with null function if (continuationFunction == null) @@ -4015,8 +3936,7 @@ private Task ContinueWith(Func continuationFunc Task continuationTask = new ContinuationResultTaskFromTask( this, continuationFunction, null, - creationOptions, internalOptions, - ref stackMark + creationOptions, internalOptions ); // Register the continuation. If synchronous execution is requested, this may @@ -4049,12 +3969,10 @@ ref stackMark /// /// The argument is null. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWith(Func continuationFunction, Object state) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; return ContinueWith(continuationFunction, state, TaskScheduler.Current, default(CancellationToken), - TaskContinuationOptions.None, ref stackMark); + TaskContinuationOptions.None); } @@ -4082,11 +4000,9 @@ public Task ContinueWith(Func continuat /// The provided CancellationToken /// has already been disposed. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWith(Func continuationFunction, Object state, CancellationToken cancellationToken) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWith(continuationFunction, state, TaskScheduler.Current, cancellationToken, TaskContinuationOptions.None, ref stackMark); + return ContinueWith(continuationFunction, state, TaskScheduler.Current, cancellationToken, TaskContinuationOptions.None); } /// @@ -4115,11 +4031,9 @@ public Task ContinueWith(Func continuat /// /// The argument is null. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWith(Func continuationFunction, Object state, TaskScheduler scheduler) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWith(continuationFunction, state, scheduler, default(CancellationToken), TaskContinuationOptions.None, ref stackMark); + return ContinueWith(continuationFunction, state, scheduler, default(CancellationToken), TaskContinuationOptions.None); } /// @@ -4154,11 +4068,9 @@ public Task ContinueWith(Func continuat /// The argument specifies an invalid value for TaskContinuationOptions. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWith(Func continuationFunction, Object state, TaskContinuationOptions continuationOptions) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWith(continuationFunction, state, TaskScheduler.Current, default(CancellationToken), continuationOptions, ref stackMark); + return ContinueWith(continuationFunction, state, TaskScheduler.Current, default(CancellationToken), continuationOptions); } /// @@ -4203,17 +4115,15 @@ public Task ContinueWith(Func continuat /// The provided CancellationToken /// has already been disposed. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWith(Func continuationFunction, Object state, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWith(continuationFunction, state, scheduler, cancellationToken, continuationOptions, ref stackMark); + return ContinueWith(continuationFunction, state, scheduler, cancellationToken, continuationOptions); } // Same as the above overload, just with a stack mark parameter. private Task ContinueWith(Func continuationFunction, Object state, TaskScheduler scheduler, - CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, ref StackCrawlMark stackMark) + CancellationToken cancellationToken, TaskContinuationOptions continuationOptions) { // Throw on continuation with null function if (continuationFunction == null) @@ -4234,8 +4144,7 @@ private Task ContinueWith(Func continua Task continuationTask = new ContinuationResultTaskFromTask( this, continuationFunction, state, - creationOptions, internalOptions, - ref stackMark + creationOptions, internalOptions ); // Register the continuation. If synchronous execution is requested, this may @@ -5255,12 +5164,10 @@ internal static Task FromCancellation(CancellationToken cancel /// /// The parameter was null. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public static Task Run(Action action) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; return Task.InternalStartNew(null, action, null, default(CancellationToken), TaskScheduler.Default, - TaskCreationOptions.DenyChildAttach, InternalTaskOptions.None, ref stackMark); + TaskCreationOptions.DenyChildAttach, InternalTaskOptions.None); } /// @@ -5275,12 +5182,10 @@ public static Task Run(Action action) /// /// The associated with was disposed. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public static Task Run(Action action, CancellationToken cancellationToken) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; return Task.InternalStartNew(null, action, null, cancellationToken, TaskScheduler.Default, - TaskCreationOptions.DenyChildAttach, InternalTaskOptions.None, ref stackMark); + TaskCreationOptions.DenyChildAttach, InternalTaskOptions.None); } /// @@ -5291,12 +5196,10 @@ public static Task Run(Action action, CancellationToken cancellationToken) /// /// The parameter was null. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public static Task Run(Func function) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; return Task.StartNew(null, function, default(CancellationToken), - TaskCreationOptions.DenyChildAttach, InternalTaskOptions.None, TaskScheduler.Default, ref stackMark); + TaskCreationOptions.DenyChildAttach, InternalTaskOptions.None, TaskScheduler.Default); } /// @@ -5311,12 +5214,10 @@ public static Task Run(Func function) /// /// The associated with was disposed. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public static Task Run(Func function, CancellationToken cancellationToken) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; return Task.StartNew(null, function, cancellationToken, - TaskCreationOptions.DenyChildAttach, InternalTaskOptions.None, TaskScheduler.Default, ref stackMark); + TaskCreationOptions.DenyChildAttach, InternalTaskOptions.None, TaskScheduler.Default); } /// diff --git a/src/mscorlib/src/System/Threading/Tasks/TaskContinuation.cs b/src/mscorlib/src/System/Threading/Tasks/TaskContinuation.cs index 70b9418dbf09..9cf0142b6510 100644 --- a/src/mscorlib/src/System/Threading/Tasks/TaskContinuation.cs +++ b/src/mscorlib/src/System/Threading/Tasks/TaskContinuation.cs @@ -29,13 +29,12 @@ internal sealed class ContinuationTaskFromTask : Task private Task m_antecedent; public ContinuationTaskFromTask( - Task antecedent, Delegate action, object state, TaskCreationOptions creationOptions, InternalTaskOptions internalOptions, ref StackCrawlMark stackMark) : + Task antecedent, Delegate action, object state, TaskCreationOptions creationOptions, InternalTaskOptions internalOptions) : base(action, state, Task.InternalCurrentIfAttached(creationOptions), default(CancellationToken), creationOptions, internalOptions, null) { Contract.Requires(action is Action || action is Action, "Invalid delegate type in ContinuationTaskFromTask"); m_antecedent = antecedent; - PossiblyCaptureContext(ref stackMark); } /// @@ -77,13 +76,12 @@ internal sealed class ContinuationResultTaskFromTask : Task private Task m_antecedent; public ContinuationResultTaskFromTask( - Task antecedent, Delegate function, object state, TaskCreationOptions creationOptions, InternalTaskOptions internalOptions, ref StackCrawlMark stackMark) : + Task antecedent, Delegate function, object state, TaskCreationOptions creationOptions, InternalTaskOptions internalOptions) : base(function, state, Task.InternalCurrentIfAttached(creationOptions), default(CancellationToken), creationOptions, internalOptions, null) { Contract.Requires(function is Func || function is Func, "Invalid delegate type in ContinuationResultTaskFromTask"); m_antecedent = antecedent; - PossiblyCaptureContext(ref stackMark); } /// @@ -125,13 +123,12 @@ internal sealed class ContinuationTaskFromResultTask : Task private Task m_antecedent; public ContinuationTaskFromResultTask( - Task antecedent, Delegate action, object state, TaskCreationOptions creationOptions, InternalTaskOptions internalOptions, ref StackCrawlMark stackMark) : + Task antecedent, Delegate action, object state, TaskCreationOptions creationOptions, InternalTaskOptions internalOptions) : base(action, state, Task.InternalCurrentIfAttached(creationOptions), default(CancellationToken), creationOptions, internalOptions, null) { Contract.Requires(action is Action> || action is Action, object>, "Invalid delegate type in ContinuationTaskFromResultTask"); m_antecedent = antecedent; - PossiblyCaptureContext(ref stackMark); } /// @@ -173,13 +170,12 @@ internal sealed class ContinuationResultTaskFromResultTask m_antecedent; public ContinuationResultTaskFromResultTask( - Task antecedent, Delegate function, object state, TaskCreationOptions creationOptions, InternalTaskOptions internalOptions, ref StackCrawlMark stackMark) : + Task antecedent, Delegate function, object state, TaskCreationOptions creationOptions, InternalTaskOptions internalOptions) : base(function, state, Task.InternalCurrentIfAttached(creationOptions), default(CancellationToken), creationOptions, internalOptions, null) { Contract.Requires(function is Func, TResult> || function is Func, object, TResult>, "Invalid delegate type in ContinuationResultTaskFromResultTask"); m_antecedent = antecedent; - PossiblyCaptureContext(ref stackMark); } /// @@ -392,10 +388,9 @@ internal sealed class SynchronizationContextAwaitTaskContinuation : AwaitTaskCon /// The synchronization context with which to invoke the action. Must not be null. /// The action to invoke. Must not be null. /// Whether to capture and restore ExecutionContext. - /// The captured stack mark. internal SynchronizationContextAwaitTaskContinuation( - SynchronizationContext context, Action action, bool flowExecutionContext, ref StackCrawlMark stackMark) : - base(action, flowExecutionContext, ref stackMark) + SynchronizationContext context, Action action, bool flowExecutionContext) : + base(action, flowExecutionContext) { Debug.Assert(context != null); m_syncContext = context; @@ -479,10 +474,9 @@ internal sealed class TaskSchedulerAwaitTaskContinuation : AwaitTaskContinuation /// The task scheduler with which to invoke the action. Must not be null. /// The action to invoke. Must not be null. /// Whether to capture and restore ExecutionContext. - /// The captured stack mark. internal TaskSchedulerAwaitTaskContinuation( - TaskScheduler scheduler, Action action, bool flowExecutionContext, ref StackCrawlMark stackMark) : - base(action, flowExecutionContext, ref stackMark) + TaskScheduler scheduler, Action action, bool flowExecutionContext) : + base(action, flowExecutionContext) { Debug.Assert(scheduler != null); m_scheduler = scheduler; @@ -540,22 +534,6 @@ internal class AwaitTaskContinuation : TaskContinuation, IThreadPoolWorkItem protected int m_continuationId; - /// Initializes the continuation. - /// The action to invoke. Must not be null. - /// Whether to capture and restore ExecutionContext. - /// The captured stack mark with which to construct an ExecutionContext. - internal AwaitTaskContinuation(Action action, bool flowExecutionContext, ref StackCrawlMark stackMark) - { - Contract.Requires(action != null); - m_action = action; - if (flowExecutionContext) - { - m_capturedContext = ExecutionContext.Capture( - ref stackMark, - ExecutionContext.CaptureOptions.IgnoreSyncCtx | ExecutionContext.CaptureOptions.OptimizeDefaultCase); - } - } - /// Initializes the continuation. /// The action to invoke. Must not be null. /// Whether to capture and restore ExecutionContext. diff --git a/src/mscorlib/src/System/Threading/Tasks/TaskFactory.cs b/src/mscorlib/src/System/Threading/Tasks/TaskFactory.cs index c8785865e232..417a6bb0bc5f 100644 --- a/src/mscorlib/src/System/Threading/Tasks/TaskFactory.cs +++ b/src/mscorlib/src/System/Threading/Tasks/TaskFactory.cs @@ -293,13 +293,11 @@ internal static void CheckCreationOptions(TaskCreationOptions creationOptions) /// unless creation and scheduling must be separated, StartNew is the recommended /// approach for both simplicity and performance. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task StartNew(Action action) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; Task currTask = Task.InternalCurrent; return Task.InternalStartNew(currTask, action, null, m_defaultCancellationToken, GetDefaultScheduler(currTask), - m_defaultCreationOptions, InternalTaskOptions.None, ref stackMark); + m_defaultCreationOptions, InternalTaskOptions.None); } /// @@ -320,13 +318,11 @@ public Task StartNew(Action action) /// unless creation and scheduling must be separated, StartNew is the recommended /// approach for both simplicity and performance. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task StartNew(Action action, CancellationToken cancellationToken) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; Task currTask = Task.InternalCurrent; return Task.InternalStartNew(currTask, action, null, cancellationToken, GetDefaultScheduler(currTask), - m_defaultCreationOptions, InternalTaskOptions.None, ref stackMark); + m_defaultCreationOptions, InternalTaskOptions.None); } /// @@ -350,13 +346,11 @@ public Task StartNew(Action action, CancellationToken cancellationToken) /// However, unless creation and scheduling must be separated, StartNew is the recommended approach /// for both simplicity and performance. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task StartNew(Action action, TaskCreationOptions creationOptions) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; Task currTask = Task.InternalCurrent; return Task.InternalStartNew(currTask, action, null, m_defaultCancellationToken, GetDefaultScheduler(currTask), creationOptions, - InternalTaskOptions.None, ref stackMark); + InternalTaskOptions.None); } /// @@ -391,13 +385,11 @@ public Task StartNew(Action action, TaskCreationOptions creationOptions) /// However, unless creation and scheduling must be separated, StartNew is the recommended approach /// for both simplicity and performance. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task StartNew(Action action, CancellationToken cancellationToken, TaskCreationOptions creationOptions, TaskScheduler scheduler) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; return Task.InternalStartNew( Task.InternalCurrentIfAttached(creationOptions), action, null, cancellationToken, scheduler, creationOptions, - InternalTaskOptions.None, ref stackMark); + InternalTaskOptions.None); } @@ -418,13 +410,11 @@ public Task StartNew(Action action, CancellationToken cancellationToken, TaskCre /// However, unless creation and scheduling must be separated, StartNew is the recommended approach /// for both simplicity and performance. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task StartNew(Action action, Object state) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; Task currTask = Task.InternalCurrent; return Task.InternalStartNew(currTask, action, state, m_defaultCancellationToken, GetDefaultScheduler(currTask), - m_defaultCreationOptions, InternalTaskOptions.None, ref stackMark); + m_defaultCreationOptions, InternalTaskOptions.None); } @@ -449,13 +439,11 @@ public Task StartNew(Action action, Object state) /// However, unless creation and scheduling must be separated, StartNew is the recommended approach /// for both simplicity and performance. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task StartNew(Action action, Object state, CancellationToken cancellationToken) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; Task currTask = Task.InternalCurrent; return Task.InternalStartNew(currTask, action, state, cancellationToken, GetDefaultScheduler(currTask), - m_defaultCreationOptions, InternalTaskOptions.None, ref stackMark); + m_defaultCreationOptions, InternalTaskOptions.None); } /// @@ -481,13 +469,11 @@ public Task StartNew(Action action, Object state, CancellationToken canc /// However, unless creation and scheduling must be separated, StartNew is the recommended approach /// for both simplicity and performance. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task StartNew(Action action, Object state, TaskCreationOptions creationOptions) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; Task currTask = Task.InternalCurrent; return Task.InternalStartNew(currTask, action, state, m_defaultCancellationToken, GetDefaultScheduler(currTask), - creationOptions, InternalTaskOptions.None, ref stackMark); + creationOptions, InternalTaskOptions.None); } /// @@ -524,14 +510,12 @@ public Task StartNew(Action action, Object state, TaskCreationOptions cr /// However, unless creation and scheduling must be separated, StartNew is the recommended approach /// for both simplicity and performance. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task StartNew(Action action, Object state, CancellationToken cancellationToken, TaskCreationOptions creationOptions, TaskScheduler scheduler) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; return Task.InternalStartNew( Task.InternalCurrentIfAttached(creationOptions), action, state, cancellationToken, scheduler, - creationOptions, InternalTaskOptions.None, ref stackMark); + creationOptions, InternalTaskOptions.None); } /// @@ -553,13 +537,11 @@ public Task StartNew(Action action, Object state, CancellationToken canc /// However, unless creation and scheduling must be separated, StartNew is the recommended approach /// for both simplicity and performance. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task StartNew(Func function) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; Task currTask = Task.InternalCurrent; return Task.StartNew(currTask, function, m_defaultCancellationToken, - m_defaultCreationOptions, InternalTaskOptions.None, GetDefaultScheduler(currTask), ref stackMark); + m_defaultCreationOptions, InternalTaskOptions.None, GetDefaultScheduler(currTask)); } @@ -586,13 +568,11 @@ public Task StartNew(Func function) /// However, unless creation and scheduling must be separated, StartNew is the recommended approach /// for both simplicity and performance. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task StartNew(Func function, CancellationToken cancellationToken) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; Task currTask = Task.InternalCurrent; return Task.StartNew(currTask, function, cancellationToken, - m_defaultCreationOptions, InternalTaskOptions.None, GetDefaultScheduler(currTask), ref stackMark); + m_defaultCreationOptions, InternalTaskOptions.None, GetDefaultScheduler(currTask)); } /// @@ -620,13 +600,11 @@ public Task StartNew(Func function, CancellationToken /// However, unless creation and scheduling must be separated, StartNew is the recommended approach /// for both simplicity and performance. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task StartNew(Func function, TaskCreationOptions creationOptions) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; Task currTask = Task.InternalCurrent; return Task.StartNew(currTask, function, m_defaultCancellationToken, - creationOptions, InternalTaskOptions.None, GetDefaultScheduler(currTask), ref stackMark); + creationOptions, InternalTaskOptions.None, GetDefaultScheduler(currTask)); } /// @@ -665,13 +643,11 @@ public Task StartNew(Func function, TaskCreationOptio /// However, unless creation and scheduling must be separated, StartNew is the recommended approach /// for both simplicity and performance. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task StartNew(Func function, CancellationToken cancellationToken, TaskCreationOptions creationOptions, TaskScheduler scheduler) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; return Task.StartNew( Task.InternalCurrentIfAttached(creationOptions), function, cancellationToken, - creationOptions, InternalTaskOptions.None, scheduler, ref stackMark); + creationOptions, InternalTaskOptions.None, scheduler); } /// @@ -695,13 +671,11 @@ public Task StartNew(Func function, CancellationToken /// However, unless creation and scheduling must be separated, StartNew is the recommended approach /// for both simplicity and performance. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task StartNew(Func function, Object state) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; Task currTask = Task.InternalCurrent; return Task.StartNew(currTask, function, state, m_defaultCancellationToken, - m_defaultCreationOptions, InternalTaskOptions.None, GetDefaultScheduler(currTask), ref stackMark); + m_defaultCreationOptions, InternalTaskOptions.None, GetDefaultScheduler(currTask)); } @@ -730,13 +704,11 @@ public Task StartNew(Func function, Object st /// However, unless creation and scheduling must be separated, StartNew is the recommended approach /// for both simplicity and performance. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task StartNew(Func function, Object state, CancellationToken cancellationToken) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; Task currTask = Task.InternalCurrent; return Task.StartNew(currTask, function, state, cancellationToken, - m_defaultCreationOptions, InternalTaskOptions.None, GetDefaultScheduler(currTask), ref stackMark); + m_defaultCreationOptions, InternalTaskOptions.None, GetDefaultScheduler(currTask)); } /// @@ -766,13 +738,11 @@ public Task StartNew(Func function, Object st /// However, unless creation and scheduling must be separated, StartNew is the recommended approach /// for both simplicity and performance. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task StartNew(Func function, Object state, TaskCreationOptions creationOptions) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; Task currTask = Task.InternalCurrent; return Task.StartNew(currTask, function, state, m_defaultCancellationToken, - creationOptions, InternalTaskOptions.None, GetDefaultScheduler(currTask), ref stackMark); + creationOptions, InternalTaskOptions.None, GetDefaultScheduler(currTask)); } /// @@ -813,14 +783,12 @@ public Task StartNew(Func function, Object st /// However, unless creation and scheduling must be separated, StartNew is the recommended approach /// for both simplicity and performance. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task StartNew(Func function, Object state, CancellationToken cancellationToken, TaskCreationOptions creationOptions, TaskScheduler scheduler) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; return Task.StartNew( Task.InternalCurrentIfAttached(creationOptions), function, state, cancellationToken, - creationOptions, InternalTaskOptions.None, scheduler, ref stackMark); + creationOptions, InternalTaskOptions.None, scheduler); } // @@ -841,13 +809,11 @@ public Task StartNew(Func function, Object st /// argument is null. /// A Task that represents the asynchronous /// operation. - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task FromAsync( IAsyncResult asyncResult, Action endMethod) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return FromAsync(asyncResult, endMethod, m_defaultCreationOptions, DefaultScheduler, ref stackMark); + return FromAsync(asyncResult, endMethod, m_defaultCreationOptions, DefaultScheduler); } /// @@ -869,14 +835,12 @@ public Task FromAsync( /// value. /// A Task that represents the asynchronous /// operation. - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task FromAsync( IAsyncResult asyncResult, Action endMethod, TaskCreationOptions creationOptions) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return FromAsync(asyncResult, endMethod, creationOptions, DefaultScheduler, ref stackMark); + return FromAsync(asyncResult, endMethod, creationOptions, DefaultScheduler); } /// @@ -902,26 +866,13 @@ public Task FromAsync( /// value. /// A Task that represents the asynchronous /// operation. - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task FromAsync( IAsyncResult asyncResult, Action endMethod, TaskCreationOptions creationOptions, TaskScheduler scheduler) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return FromAsync(asyncResult, endMethod, creationOptions, scheduler, ref stackMark); - } - - // private version that supports StackCrawlMark. - private Task FromAsync( - IAsyncResult asyncResult, - Action endMethod, - TaskCreationOptions creationOptions, - TaskScheduler scheduler, - ref StackCrawlMark stackMark) - { - return TaskFactory.FromAsyncImpl(asyncResult, null, endMethod, creationOptions, scheduler, ref stackMark); + return TaskFactory.FromAsyncImpl(asyncResult, null, endMethod, creationOptions, scheduler); } /// @@ -1219,12 +1170,10 @@ public Task FromAsync( /// argument is null. /// A Task that represents the /// asynchronous operation. - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task FromAsync( IAsyncResult asyncResult, Func endMethod) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return TaskFactory.FromAsyncImpl(asyncResult, endMethod, null, m_defaultCreationOptions, DefaultScheduler, ref stackMark); + return TaskFactory.FromAsyncImpl(asyncResult, endMethod, null, m_defaultCreationOptions, DefaultScheduler); } /// @@ -1249,12 +1198,10 @@ public Task FromAsync( /// value. /// A Task that represents the /// asynchronous operation. - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task FromAsync( IAsyncResult asyncResult, Func endMethod, TaskCreationOptions creationOptions) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return TaskFactory.FromAsyncImpl(asyncResult, endMethod, null, creationOptions, DefaultScheduler, ref stackMark); + return TaskFactory.FromAsyncImpl(asyncResult, endMethod, null, creationOptions, DefaultScheduler); } /// @@ -1283,12 +1230,10 @@ public Task FromAsync( /// value. /// A Task that represents the /// asynchronous operation. - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task FromAsync( IAsyncResult asyncResult, Func endMethod, TaskCreationOptions creationOptions, TaskScheduler scheduler) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return TaskFactory.FromAsyncImpl(asyncResult, endMethod, null, creationOptions, scheduler, ref stackMark); + return TaskFactory.FromAsyncImpl(asyncResult, endMethod, null, creationOptions, scheduler); } /// @@ -1789,14 +1734,12 @@ internal static Task[]> CommonCWAllLogic(Task[] tasksCopy) /// array contains a null value. /// The exception that is thrown when the /// array is empty. - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAll(Task[] tasks, Action continuationAction) { if (continuationAction == null) throw new ArgumentNullException(nameof(continuationAction)); Contract.EndContractBlock(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return TaskFactory.ContinueWhenAllImpl(tasks, null, continuationAction, m_defaultContinuationOptions, m_defaultCancellationToken, DefaultScheduler, ref stackMark); + return TaskFactory.ContinueWhenAllImpl(tasks, null, continuationAction, m_defaultContinuationOptions, m_defaultCancellationToken, DefaultScheduler); } @@ -1821,14 +1764,12 @@ public Task ContinueWhenAll(Task[] tasks, Action continuationAction) /// The provided CancellationToken /// has already been disposed. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAll(Task[] tasks, Action continuationAction, CancellationToken cancellationToken) { if (continuationAction == null) throw new ArgumentNullException(nameof(continuationAction)); Contract.EndContractBlock(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return TaskFactory.ContinueWhenAllImpl(tasks, null, continuationAction, m_defaultContinuationOptions, cancellationToken, DefaultScheduler, ref stackMark); + return TaskFactory.ContinueWhenAllImpl(tasks, null, continuationAction, m_defaultContinuationOptions, cancellationToken, DefaultScheduler); } /// @@ -1858,14 +1799,12 @@ public Task ContinueWhenAll(Task[] tasks, Action continuationAction, Can /// which constrain for which TaskStatus states a continuation /// will be executed, are illegal with ContinueWhenAll. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAll(Task[] tasks, Action continuationAction, TaskContinuationOptions continuationOptions) { if (continuationAction == null) throw new ArgumentNullException(nameof(continuationAction)); Contract.EndContractBlock(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return TaskFactory.ContinueWhenAllImpl(tasks, null, continuationAction, continuationOptions, m_defaultCancellationToken, DefaultScheduler, ref stackMark); + return TaskFactory.ContinueWhenAllImpl(tasks, null, continuationAction, continuationOptions, m_defaultCancellationToken, DefaultScheduler); } /// @@ -1905,15 +1844,13 @@ public Task ContinueWhenAll(Task[] tasks, Action continuationAction, Tas /// which constrain for which TaskStatus states a continuation /// will be executed, are illegal with ContinueWhenAll. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAll(Task[] tasks, Action continuationAction, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler) { if (continuationAction == null) throw new ArgumentNullException(nameof(continuationAction)); Contract.EndContractBlock(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return TaskFactory.ContinueWhenAllImpl(tasks, null, continuationAction, continuationOptions, cancellationToken, scheduler, ref stackMark); + return TaskFactory.ContinueWhenAllImpl(tasks, null, continuationAction, continuationOptions, cancellationToken, scheduler); } /// @@ -1933,14 +1870,12 @@ public Task ContinueWhenAll(Task[] tasks, Action continuationAction, Can /// array contains a null value. /// The exception that is thrown when the /// array is empty. - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAll(Task[] tasks, Action[]> continuationAction) { if (continuationAction == null) throw new ArgumentNullException(nameof(continuationAction)); Contract.EndContractBlock(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return TaskFactory.ContinueWhenAllImpl(tasks, null, continuationAction, m_defaultContinuationOptions, m_defaultCancellationToken, DefaultScheduler, ref stackMark); + return TaskFactory.ContinueWhenAllImpl(tasks, null, continuationAction, m_defaultContinuationOptions, m_defaultCancellationToken, DefaultScheduler); } @@ -1966,15 +1901,13 @@ public Task ContinueWhenAll(Task[] tasks, /// The provided CancellationToken /// has already been disposed. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAll(Task[] tasks, Action[]> continuationAction, CancellationToken cancellationToken) { if (continuationAction == null) throw new ArgumentNullException(nameof(continuationAction)); Contract.EndContractBlock(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return TaskFactory.ContinueWhenAllImpl(tasks, null, continuationAction, m_defaultContinuationOptions, cancellationToken, DefaultScheduler, ref stackMark); + return TaskFactory.ContinueWhenAllImpl(tasks, null, continuationAction, m_defaultContinuationOptions, cancellationToken, DefaultScheduler); } /// @@ -2005,15 +1938,13 @@ public Task ContinueWhenAll(Task[] tasks, /// which constrain for which TaskStatus states a continuation /// will be executed, are illegal with ContinueWhenAll. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAll(Task[] tasks, Action[]> continuationAction, TaskContinuationOptions continuationOptions) { if (continuationAction == null) throw new ArgumentNullException(nameof(continuationAction)); Contract.EndContractBlock(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return TaskFactory.ContinueWhenAllImpl(tasks, null, continuationAction, continuationOptions, m_defaultCancellationToken, DefaultScheduler, ref stackMark); + return TaskFactory.ContinueWhenAllImpl(tasks, null, continuationAction, continuationOptions, m_defaultCancellationToken, DefaultScheduler); } /// @@ -2054,15 +1985,13 @@ public Task ContinueWhenAll(Task[] tasks, /// which constrain for which TaskStatus states a continuation /// will be executed, are illegal with ContinueWhenAll. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAll(Task[] tasks, Action[]> continuationAction, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler) { if (continuationAction == null) throw new ArgumentNullException(nameof(continuationAction)); Contract.EndContractBlock(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return TaskFactory.ContinueWhenAllImpl(tasks, null, continuationAction, continuationOptions, cancellationToken, scheduler, ref stackMark); + return TaskFactory.ContinueWhenAllImpl(tasks, null, continuationAction, continuationOptions, cancellationToken, scheduler); } /// @@ -2085,14 +2014,12 @@ public Task ContinueWhenAll(Task[] tasks, /// array contains a null value. /// The exception that is thrown when the /// array is empty. - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAll(Task[] tasks, Func continuationFunction) { if (continuationFunction == null) throw new ArgumentNullException(nameof(continuationFunction)); Contract.EndContractBlock(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return TaskFactory.ContinueWhenAllImpl(tasks, continuationFunction, null, m_defaultContinuationOptions, m_defaultCancellationToken, DefaultScheduler, ref stackMark); + return TaskFactory.ContinueWhenAllImpl(tasks, continuationFunction, null, m_defaultContinuationOptions, m_defaultCancellationToken, DefaultScheduler); } @@ -2121,14 +2048,12 @@ public Task ContinueWhenAll(Task[] tasks, FuncThe provided CancellationToken /// has already been disposed. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAll(Task[] tasks, Func continuationFunction, CancellationToken cancellationToken) { if (continuationFunction == null) throw new ArgumentNullException(nameof(continuationFunction)); Contract.EndContractBlock(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return TaskFactory.ContinueWhenAllImpl(tasks, continuationFunction, null, m_defaultContinuationOptions, cancellationToken, DefaultScheduler, ref stackMark); + return TaskFactory.ContinueWhenAllImpl(tasks, continuationFunction, null, m_defaultContinuationOptions, cancellationToken, DefaultScheduler); } /// @@ -2162,14 +2087,12 @@ public Task ContinueWhenAll(Task[] tasks, FuncTaskStatus states a continuation /// will be executed, are illegal with ContinueWhenAll. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAll(Task[] tasks, Func continuationFunction, TaskContinuationOptions continuationOptions) { if (continuationFunction == null) throw new ArgumentNullException(nameof(continuationFunction)); Contract.EndContractBlock(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return TaskFactory.ContinueWhenAllImpl(tasks, continuationFunction, null, continuationOptions, m_defaultCancellationToken, DefaultScheduler, ref stackMark); + return TaskFactory.ContinueWhenAllImpl(tasks, continuationFunction, null, continuationOptions, m_defaultCancellationToken, DefaultScheduler); } /// @@ -2213,15 +2136,13 @@ public Task ContinueWhenAll(Task[] tasks, FuncTaskStatus states a continuation /// will be executed, are illegal with ContinueWhenAll. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAll(Task[] tasks, Func continuationFunction, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler) { if (continuationFunction == null) throw new ArgumentNullException(nameof(continuationFunction)); Contract.EndContractBlock(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return TaskFactory.ContinueWhenAllImpl(tasks, continuationFunction, null, continuationOptions, cancellationToken, scheduler, ref stackMark); + return TaskFactory.ContinueWhenAllImpl(tasks, continuationFunction, null, continuationOptions, cancellationToken, scheduler); } @@ -2246,14 +2167,12 @@ public Task ContinueWhenAll(Task[] tasks, Func array contains a null value. /// The exception that is thrown when the /// array is empty. - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAll(Task[] tasks, Func[], TResult> continuationFunction) { if (continuationFunction == null) throw new ArgumentNullException(nameof(continuationFunction)); Contract.EndContractBlock(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return TaskFactory.ContinueWhenAllImpl(tasks, continuationFunction, null, m_defaultContinuationOptions, m_defaultCancellationToken, DefaultScheduler, ref stackMark); + return TaskFactory.ContinueWhenAllImpl(tasks, continuationFunction, null, m_defaultContinuationOptions, m_defaultCancellationToken, DefaultScheduler); } /// @@ -2282,15 +2201,13 @@ public Task ContinueWhenAll(TaskThe provided CancellationToken /// has already been disposed. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAll(Task[] tasks, Func[], TResult> continuationFunction, CancellationToken cancellationToken) { if (continuationFunction == null) throw new ArgumentNullException(nameof(continuationFunction)); Contract.EndContractBlock(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return TaskFactory.ContinueWhenAllImpl(tasks, continuationFunction, null, m_defaultContinuationOptions, cancellationToken, DefaultScheduler, ref stackMark); + return TaskFactory.ContinueWhenAllImpl(tasks, continuationFunction, null, m_defaultContinuationOptions, cancellationToken, DefaultScheduler); } /// @@ -2325,15 +2242,13 @@ public Task ContinueWhenAll(TaskTaskStatus states a continuation /// will be executed, are illegal with ContinueWhenAll. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAll(Task[] tasks, Func[], TResult> continuationFunction, TaskContinuationOptions continuationOptions) { if (continuationFunction == null) throw new ArgumentNullException(nameof(continuationFunction)); Contract.EndContractBlock(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return TaskFactory.ContinueWhenAllImpl(tasks, continuationFunction, null, continuationOptions, m_defaultCancellationToken, DefaultScheduler, ref stackMark); + return TaskFactory.ContinueWhenAllImpl(tasks, continuationFunction, null, continuationOptions, m_defaultCancellationToken, DefaultScheduler); } /// @@ -2378,15 +2293,13 @@ public Task ContinueWhenAll(TaskTaskStatus states a continuation /// will be executed, are illegal with ContinueWhenAll. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAll(Task[] tasks, Func[], TResult> continuationFunction, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler) { if (continuationFunction == null) throw new ArgumentNullException(nameof(continuationFunction)); Contract.EndContractBlock(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return TaskFactory.ContinueWhenAllImpl(tasks, continuationFunction, null, continuationOptions, cancellationToken, scheduler, ref stackMark); + return TaskFactory.ContinueWhenAllImpl(tasks, continuationFunction, null, continuationOptions, cancellationToken, scheduler); } // @@ -2535,14 +2448,12 @@ internal static Task CommonCWAnyLogic(IList tasks) /// array contains a null value. /// The exception that is thrown when the /// array is empty. - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAny(Task[] tasks, Action continuationAction) { if (continuationAction == null) throw new ArgumentNullException(nameof(continuationAction)); Contract.EndContractBlock(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return TaskFactory.ContinueWhenAnyImpl(tasks, null, continuationAction, m_defaultContinuationOptions, m_defaultCancellationToken, DefaultScheduler, ref stackMark); + return TaskFactory.ContinueWhenAnyImpl(tasks, null, continuationAction, m_defaultContinuationOptions, m_defaultCancellationToken, DefaultScheduler); } /// @@ -2566,14 +2477,12 @@ public Task ContinueWhenAny(Task[] tasks, Action continuationAction) /// The provided CancellationToken /// has already been disposed. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAny(Task[] tasks, Action continuationAction, CancellationToken cancellationToken) { if (continuationAction == null) throw new ArgumentNullException(nameof(continuationAction)); Contract.EndContractBlock(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return TaskFactory.ContinueWhenAnyImpl(tasks, null, continuationAction, m_defaultContinuationOptions, cancellationToken, DefaultScheduler, ref stackMark); + return TaskFactory.ContinueWhenAnyImpl(tasks, null, continuationAction, m_defaultContinuationOptions, cancellationToken, DefaultScheduler); } /// @@ -2603,14 +2512,12 @@ public Task ContinueWhenAny(Task[] tasks, Action continuationAction, Cance /// which constrain for which TaskStatus states a continuation /// will be executed, are illegal with ContinueWhenAny. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAny(Task[] tasks, Action continuationAction, TaskContinuationOptions continuationOptions) { if (continuationAction == null) throw new ArgumentNullException(nameof(continuationAction)); Contract.EndContractBlock(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return TaskFactory.ContinueWhenAnyImpl(tasks, null, continuationAction, continuationOptions, m_defaultCancellationToken, DefaultScheduler, ref stackMark); + return TaskFactory.ContinueWhenAnyImpl(tasks, null, continuationAction, continuationOptions, m_defaultCancellationToken, DefaultScheduler); } /// @@ -2650,15 +2557,13 @@ public Task ContinueWhenAny(Task[] tasks, Action continuationAction, TaskC /// which constrain for which TaskStatus states a continuation /// will be executed, are illegal with ContinueWhenAny. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAny(Task[] tasks, Action continuationAction, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler) { if (continuationAction == null) throw new ArgumentNullException(nameof(continuationAction)); Contract.EndContractBlock(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return TaskFactory.ContinueWhenAnyImpl(tasks, null, continuationAction, continuationOptions, cancellationToken, scheduler, ref stackMark); + return TaskFactory.ContinueWhenAnyImpl(tasks, null, continuationAction, continuationOptions, cancellationToken, scheduler); } @@ -2682,14 +2587,12 @@ public Task ContinueWhenAny(Task[] tasks, Action continuationAction, Cance /// array contains a null value. /// The exception that is thrown when the /// array is empty. - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAny(Task[] tasks, Func continuationFunction) { if (continuationFunction == null) throw new ArgumentNullException(nameof(continuationFunction)); Contract.EndContractBlock(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return TaskFactory.ContinueWhenAnyImpl(tasks, continuationFunction, null, m_defaultContinuationOptions, m_defaultCancellationToken, DefaultScheduler, ref stackMark); + return TaskFactory.ContinueWhenAnyImpl(tasks, continuationFunction, null, m_defaultContinuationOptions, m_defaultCancellationToken, DefaultScheduler); } /// @@ -2717,14 +2620,12 @@ public Task ContinueWhenAny(Task[] tasks, Func /// The provided CancellationToken /// has already been disposed. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAny(Task[] tasks, Func continuationFunction, CancellationToken cancellationToken) { if (continuationFunction == null) throw new ArgumentNullException(nameof(continuationFunction)); Contract.EndContractBlock(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return TaskFactory.ContinueWhenAnyImpl(tasks, continuationFunction, null, m_defaultContinuationOptions, cancellationToken, DefaultScheduler, ref stackMark); + return TaskFactory.ContinueWhenAnyImpl(tasks, continuationFunction, null, m_defaultContinuationOptions, cancellationToken, DefaultScheduler); } /// @@ -2758,14 +2659,12 @@ public Task ContinueWhenAny(Task[] tasks, Func /// which constrain for which TaskStatus states a continuation /// will be executed, are illegal with ContinueWhenAny. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAny(Task[] tasks, Func continuationFunction, TaskContinuationOptions continuationOptions) { if (continuationFunction == null) throw new ArgumentNullException(nameof(continuationFunction)); Contract.EndContractBlock(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return TaskFactory.ContinueWhenAnyImpl(tasks, continuationFunction, null,continuationOptions, m_defaultCancellationToken, DefaultScheduler, ref stackMark); + return TaskFactory.ContinueWhenAnyImpl(tasks, continuationFunction, null,continuationOptions, m_defaultCancellationToken, DefaultScheduler); } /// @@ -2809,15 +2708,13 @@ public Task ContinueWhenAny(Task[] tasks, Func /// which constrain for which TaskStatus states a continuation /// will be executed, are illegal with ContinueWhenAny. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAny(Task[] tasks, Func continuationFunction, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler) { if (continuationFunction == null) throw new ArgumentNullException(nameof(continuationFunction)); Contract.EndContractBlock(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return TaskFactory.ContinueWhenAnyImpl(tasks, continuationFunction, null, continuationOptions, cancellationToken, scheduler, ref stackMark); + return TaskFactory.ContinueWhenAnyImpl(tasks, continuationFunction, null, continuationOptions, cancellationToken, scheduler); } /// @@ -2841,12 +2738,10 @@ public Task ContinueWhenAny(Task[] tasks, Func /// array contains a null value. /// The exception that is thrown when the /// array is empty. - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAny(Task[] tasks, Func, TResult> continuationFunction) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; if (continuationFunction == null) throw new ArgumentNullException(nameof(continuationFunction)); - return TaskFactory.ContinueWhenAnyImpl(tasks, continuationFunction, null, m_defaultContinuationOptions, m_defaultCancellationToken, DefaultScheduler, ref stackMark); + return TaskFactory.ContinueWhenAnyImpl(tasks, continuationFunction, null, m_defaultContinuationOptions, m_defaultCancellationToken, DefaultScheduler); } /// @@ -2875,15 +2770,13 @@ public Task ContinueWhenAny(TaskThe provided CancellationToken /// has already been disposed. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAny(Task[] tasks, Func, TResult> continuationFunction, CancellationToken cancellationToken) { if (continuationFunction == null) throw new ArgumentNullException(nameof(continuationFunction)); Contract.EndContractBlock(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return TaskFactory.ContinueWhenAnyImpl(tasks, continuationFunction, null, m_defaultContinuationOptions, cancellationToken, DefaultScheduler, ref stackMark); + return TaskFactory.ContinueWhenAnyImpl(tasks, continuationFunction, null, m_defaultContinuationOptions, cancellationToken, DefaultScheduler); } /// @@ -2918,15 +2811,13 @@ public Task ContinueWhenAny(TaskTaskStatus states a continuation /// will be executed, are illegal with ContinueWhenAny. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAny(Task[] tasks, Func, TResult> continuationFunction, TaskContinuationOptions continuationOptions) { if (continuationFunction == null) throw new ArgumentNullException(nameof(continuationFunction)); Contract.EndContractBlock(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return TaskFactory.ContinueWhenAnyImpl(tasks, continuationFunction, null, continuationOptions, m_defaultCancellationToken, DefaultScheduler, ref stackMark); + return TaskFactory.ContinueWhenAnyImpl(tasks, continuationFunction, null, continuationOptions, m_defaultCancellationToken, DefaultScheduler); } /// @@ -2971,15 +2862,13 @@ public Task ContinueWhenAny(TaskTaskStatus states a continuation /// will be executed, are illegal with ContinueWhenAny. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAny(Task[] tasks, Func, TResult> continuationFunction, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler) { if (continuationFunction == null) throw new ArgumentNullException(nameof(continuationFunction)); Contract.EndContractBlock(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return TaskFactory.ContinueWhenAnyImpl(tasks, continuationFunction, null, continuationOptions, cancellationToken, scheduler, ref stackMark); + return TaskFactory.ContinueWhenAnyImpl(tasks, continuationFunction, null, continuationOptions, cancellationToken, scheduler); } @@ -3000,14 +2889,12 @@ public Task ContinueWhenAny(Task array contains a null value. /// The exception that is thrown when the /// array is empty. - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAny(Task[] tasks, Action> continuationAction) { if (continuationAction == null) throw new ArgumentNullException(nameof(continuationAction)); Contract.EndContractBlock(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return TaskFactory.ContinueWhenAnyImpl(tasks, null, continuationAction, m_defaultContinuationOptions, m_defaultCancellationToken, DefaultScheduler, ref stackMark); + return TaskFactory.ContinueWhenAnyImpl(tasks, null, continuationAction, m_defaultContinuationOptions, m_defaultCancellationToken, DefaultScheduler); } /// @@ -3032,15 +2919,13 @@ public Task ContinueWhenAny(Task[] tasks, /// The provided CancellationToken /// has already been disposed. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAny(Task[] tasks, Action> continuationAction, CancellationToken cancellationToken) { if (continuationAction == null) throw new ArgumentNullException(nameof(continuationAction)); Contract.EndContractBlock(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return TaskFactory.ContinueWhenAnyImpl(tasks, null, continuationAction, m_defaultContinuationOptions, cancellationToken, DefaultScheduler, ref stackMark); + return TaskFactory.ContinueWhenAnyImpl(tasks, null, continuationAction, m_defaultContinuationOptions, cancellationToken, DefaultScheduler); } /// @@ -3071,15 +2956,13 @@ public Task ContinueWhenAny(Task[] tasks, /// which constrain for which TaskStatus states a continuation /// will be executed, are illegal with ContinueWhenAny. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAny(Task[] tasks, Action> continuationAction, TaskContinuationOptions continuationOptions) { if (continuationAction == null) throw new ArgumentNullException(nameof(continuationAction)); Contract.EndContractBlock(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return TaskFactory.ContinueWhenAnyImpl(tasks, null, continuationAction, continuationOptions, m_defaultCancellationToken, DefaultScheduler, ref stackMark); + return TaskFactory.ContinueWhenAnyImpl(tasks, null, continuationAction, continuationOptions, m_defaultCancellationToken, DefaultScheduler); } /// @@ -3120,15 +3003,13 @@ public Task ContinueWhenAny(Task[] tasks, /// which constrain for which TaskStatus states a continuation /// will be executed, are illegal with ContinueWhenAny. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAny(Task[] tasks, Action> continuationAction, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler) { if (continuationAction == null) throw new ArgumentNullException(nameof(continuationAction)); Contract.EndContractBlock(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return TaskFactory.ContinueWhenAnyImpl(tasks, null, continuationAction, continuationOptions, cancellationToken, scheduler, ref stackMark); + return TaskFactory.ContinueWhenAnyImpl(tasks, null, continuationAction, continuationOptions, cancellationToken, scheduler); } // Check task array and return a defensive copy. diff --git a/src/mscorlib/src/System/Threading/Tasks/future.cs b/src/mscorlib/src/System/Threading/Tasks/future.cs index 18e3f92ba7be..94a980b86a7f 100644 --- a/src/mscorlib/src/System/Threading/Tasks/future.cs +++ b/src/mscorlib/src/System/Threading/Tasks/future.cs @@ -128,13 +128,10 @@ internal Task(bool canceled, TResult result, TaskCreationOptions creationOptions /// /// The argument is null. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task(Func function) : this(function, null, default(CancellationToken), TaskCreationOptions.None, InternalTaskOptions.None, null) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - PossiblyCaptureContext(ref stackMark); } @@ -152,13 +149,10 @@ public Task(Func function) /// The provided CancellationToken /// has already been disposed. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task(Func function, CancellationToken cancellationToken) : this(function, null, cancellationToken, TaskCreationOptions.None, InternalTaskOptions.None, null) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - PossiblyCaptureContext(ref stackMark); } /// @@ -179,12 +173,9 @@ public Task(Func function, CancellationToken cancellationToken) /// The argument specifies an invalid value for . /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task(Func function, TaskCreationOptions creationOptions) : this(function, Task.InternalCurrentIfAttached(creationOptions), default(CancellationToken), creationOptions, InternalTaskOptions.None, null) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - PossiblyCaptureContext(ref stackMark); } /// @@ -209,12 +200,9 @@ public Task(Func function, TaskCreationOptions creationOptions) /// The provided CancellationToken /// has already been disposed. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task(Func function, CancellationToken cancellationToken, TaskCreationOptions creationOptions) : this(function, Task.InternalCurrentIfAttached(creationOptions), cancellationToken, creationOptions, InternalTaskOptions.None, null) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - PossiblyCaptureContext(ref stackMark); } /// @@ -228,13 +216,10 @@ public Task(Func function, CancellationToken cancellationToken, TaskCre /// /// The argument is null. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task(Func function, object state) : this(function, state, null, default(CancellationToken), TaskCreationOptions.None, InternalTaskOptions.None, null) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - PossiblyCaptureContext(ref stackMark); } /// @@ -252,13 +237,10 @@ public Task(Func function, object state) /// The provided CancellationToken /// has already been disposed. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task(Func function, object state, CancellationToken cancellationToken) : this(function, state, null, cancellationToken, TaskCreationOptions.None, InternalTaskOptions.None, null) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - PossiblyCaptureContext(ref stackMark); } /// @@ -280,13 +262,10 @@ public Task(Func function, object state, CancellationToken canc /// The argument specifies an invalid value for . /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task(Func function, object state, TaskCreationOptions creationOptions) : this(function, state, Task.InternalCurrentIfAttached(creationOptions), default(CancellationToken), creationOptions, InternalTaskOptions.None, null) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - PossiblyCaptureContext(ref stackMark); } @@ -313,23 +292,10 @@ public Task(Func function, object state, TaskCreationOptions cr /// The provided CancellationToken /// has already been disposed. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task(Func function, object state, CancellationToken cancellationToken, TaskCreationOptions creationOptions) : this(function, state, Task.InternalCurrentIfAttached(creationOptions), cancellationToken, creationOptions, InternalTaskOptions.None, null) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - PossiblyCaptureContext(ref stackMark); - } - - internal Task( - Func valueSelector, Task parent, CancellationToken cancellationToken, - TaskCreationOptions creationOptions, InternalTaskOptions internalOptions, TaskScheduler scheduler, - ref StackCrawlMark stackMark) : - this(valueSelector, parent, cancellationToken, - creationOptions, internalOptions, scheduler) - { - PossiblyCaptureContext(ref stackMark); } /// @@ -347,14 +313,6 @@ internal Task(Func valueSelector, Task parent, CancellationToken cancel { } - internal Task( - Func valueSelector, object state, Task parent, CancellationToken cancellationToken, - TaskCreationOptions creationOptions, InternalTaskOptions internalOptions, TaskScheduler scheduler, ref StackCrawlMark stackMark) : - this(valueSelector, state, parent, cancellationToken, creationOptions, internalOptions, scheduler) - { - PossiblyCaptureContext(ref stackMark); - } - /// /// Creates a new future object. /// @@ -374,7 +332,7 @@ internal Task(Delegate valueSelector, object state, Task parent, CancellationTok // Internal method used by TaskFactory.StartNew() methods internal static Task StartNew(Task parent, Func function, CancellationToken cancellationToken, - TaskCreationOptions creationOptions, InternalTaskOptions internalOptions, TaskScheduler scheduler, ref StackCrawlMark stackMark) + TaskCreationOptions creationOptions, InternalTaskOptions internalOptions, TaskScheduler scheduler) { if (function == null) { @@ -386,7 +344,7 @@ internal static Task StartNew(Task parent, Func function, Canc } // Create and schedule the future. - Task f = new Task(function, parent, cancellationToken, creationOptions, internalOptions | InternalTaskOptions.QueuedByRuntime, scheduler, ref stackMark); + Task f = new Task(function, parent, cancellationToken, creationOptions, internalOptions | InternalTaskOptions.QueuedByRuntime, scheduler); f.ScheduleAndStart(false); return f; @@ -394,7 +352,7 @@ internal static Task StartNew(Task parent, Func function, Canc // Internal method used by TaskFactory.StartNew() methods internal static Task StartNew(Task parent, Func function, object state, CancellationToken cancellationToken, - TaskCreationOptions creationOptions, InternalTaskOptions internalOptions, TaskScheduler scheduler, ref StackCrawlMark stackMark) + TaskCreationOptions creationOptions, InternalTaskOptions internalOptions, TaskScheduler scheduler) { if (function == null) { @@ -406,7 +364,7 @@ internal static Task StartNew(Task parent, Func functi } // Create and schedule the future. - Task f = new Task(function, state, parent, cancellationToken, creationOptions, internalOptions | InternalTaskOptions.QueuedByRuntime, scheduler, ref stackMark); + Task f = new Task(function, state, parent, cancellationToken, creationOptions, internalOptions | InternalTaskOptions.QueuedByRuntime, scheduler); f.ScheduleAndStart(false); return f; @@ -706,11 +664,9 @@ internal override void InnerInvoke() /// /// The argument is null. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWith(Action> continuationAction) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWith(continuationAction, TaskScheduler.Current, default(CancellationToken), TaskContinuationOptions.None, ref stackMark); + return ContinueWith(continuationAction, TaskScheduler.Current, default(CancellationToken), TaskContinuationOptions.None); } @@ -734,11 +690,9 @@ public Task ContinueWith(Action> continuationAction) /// The provided CancellationToken /// has already been disposed. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWith(Action> continuationAction, CancellationToken cancellationToken) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWith(continuationAction, TaskScheduler.Current, cancellationToken, TaskContinuationOptions.None, ref stackMark); + return ContinueWith(continuationAction, TaskScheduler.Current, cancellationToken, TaskContinuationOptions.None); } @@ -764,11 +718,9 @@ public Task ContinueWith(Action> continuationAction, CancellationT /// /// The argument is null. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWith(Action> continuationAction, TaskScheduler scheduler) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWith(continuationAction, scheduler, default(CancellationToken), TaskContinuationOptions.None, ref stackMark); + return ContinueWith(continuationAction, scheduler, default(CancellationToken), TaskContinuationOptions.None); } /// @@ -799,11 +751,9 @@ public Task ContinueWith(Action> continuationAction, TaskScheduler /// The argument specifies an invalid value for TaskContinuationOptions. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWith(Action> continuationAction, TaskContinuationOptions continuationOptions) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWith(continuationAction, TaskScheduler.Current, default(CancellationToken), continuationOptions, ref stackMark); + return ContinueWith(continuationAction, TaskScheduler.Current, default(CancellationToken), continuationOptions); } /// @@ -844,17 +794,15 @@ public Task ContinueWith(Action> continuationAction, TaskContinuat /// The provided CancellationToken /// has already been disposed. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWith(Action> continuationAction, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWith(continuationAction, scheduler, cancellationToken, continuationOptions, ref stackMark); + return ContinueWith(continuationAction, scheduler, cancellationToken, continuationOptions); } // Same as the above overload, only with a stack mark. internal Task ContinueWith(Action> continuationAction, TaskScheduler scheduler, CancellationToken cancellationToken, - TaskContinuationOptions continuationOptions, ref StackCrawlMark stackMark) + TaskContinuationOptions continuationOptions) { if (continuationAction == null) { @@ -875,8 +823,7 @@ internal Task ContinueWith(Action> continuationAction, TaskSchedul Task continuationTask = new ContinuationTaskFromResultTask( this, continuationAction, null, - creationOptions, internalOptions, - ref stackMark + creationOptions, internalOptions ); // Register the continuation. If synchronous execution is requested, this may @@ -906,11 +853,9 @@ ref stackMark /// /// The argument is null. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWith(Action, Object> continuationAction, Object state) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWith(continuationAction, state, TaskScheduler.Current, default(CancellationToken), TaskContinuationOptions.None, ref stackMark); + return ContinueWith(continuationAction, state, TaskScheduler.Current, default(CancellationToken), TaskContinuationOptions.None); } @@ -935,11 +880,9 @@ public Task ContinueWith(Action, Object> continuationAction, Objec /// The provided CancellationToken /// has already been disposed. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWith(Action, Object> continuationAction, Object state,CancellationToken cancellationToken) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWith(continuationAction, state, TaskScheduler.Current, cancellationToken, TaskContinuationOptions.None, ref stackMark); + return ContinueWith(continuationAction, state, TaskScheduler.Current, cancellationToken, TaskContinuationOptions.None); } @@ -966,11 +909,9 @@ public Task ContinueWith(Action, Object> continuationAction, Objec /// /// The argument is null. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWith(Action, Object> continuationAction, Object state, TaskScheduler scheduler) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWith(continuationAction, state, scheduler, default(CancellationToken), TaskContinuationOptions.None, ref stackMark); + return ContinueWith(continuationAction, state, scheduler, default(CancellationToken), TaskContinuationOptions.None); } /// @@ -1002,11 +943,9 @@ public Task ContinueWith(Action, Object> continuationAction, Objec /// The argument specifies an invalid value for TaskContinuationOptions. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWith(Action, Object> continuationAction, Object state,TaskContinuationOptions continuationOptions) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWith(continuationAction, state, TaskScheduler.Current, default(CancellationToken), continuationOptions, ref stackMark); + return ContinueWith(continuationAction, state, TaskScheduler.Current, default(CancellationToken), continuationOptions); } /// @@ -1048,17 +987,15 @@ public Task ContinueWith(Action, Object> continuationAction, Objec /// The provided CancellationToken /// has already been disposed. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWith(Action, Object> continuationAction, Object state, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWith(continuationAction, state, scheduler, cancellationToken, continuationOptions, ref stackMark); + return ContinueWith(continuationAction, state, scheduler, cancellationToken, continuationOptions); } // Same as the above overload, only with a stack mark. internal Task ContinueWith(Action, Object> continuationAction, Object state, TaskScheduler scheduler, CancellationToken cancellationToken, - TaskContinuationOptions continuationOptions, ref StackCrawlMark stackMark) + TaskContinuationOptions continuationOptions) { if (continuationAction == null) { @@ -1079,8 +1016,7 @@ internal Task ContinueWith(Action, Object> continuationAction, Obj Task continuationTask = new ContinuationTaskFromResultTask( this, continuationAction, state, - creationOptions, internalOptions, - ref stackMark + creationOptions, internalOptions ); // Register the continuation. If synchronous execution is requested, this may @@ -1113,11 +1049,9 @@ ref stackMark /// /// The argument is null. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWith(Func, TNewResult> continuationFunction) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWith(continuationFunction, TaskScheduler.Current, default(CancellationToken), TaskContinuationOptions.None, ref stackMark); + return ContinueWith(continuationFunction, TaskScheduler.Current, default(CancellationToken), TaskContinuationOptions.None); } @@ -1144,11 +1078,9 @@ public Task ContinueWith(Func, TNewResult> /// The provided CancellationToken /// has already been disposed. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWith(Func, TNewResult> continuationFunction, CancellationToken cancellationToken) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWith(continuationFunction, TaskScheduler.Current, cancellationToken, TaskContinuationOptions.None, ref stackMark); + return ContinueWith(continuationFunction, TaskScheduler.Current, cancellationToken, TaskContinuationOptions.None); } /// @@ -1176,11 +1108,9 @@ public Task ContinueWith(Func, TNewResult> /// /// The argument is null. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWith(Func, TNewResult> continuationFunction, TaskScheduler scheduler) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWith(continuationFunction, scheduler, default(CancellationToken), TaskContinuationOptions.None, ref stackMark); + return ContinueWith(continuationFunction, scheduler, default(CancellationToken), TaskContinuationOptions.None); } /// @@ -1220,11 +1150,9 @@ public Task ContinueWith(Func, TNewResult> /// The argument specifies an invalid value for TaskContinuationOptions. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWith(Func, TNewResult> continuationFunction, TaskContinuationOptions continuationOptions) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWith(continuationFunction, TaskScheduler.Current, default(CancellationToken), continuationOptions, ref stackMark); + return ContinueWith(continuationFunction, TaskScheduler.Current, default(CancellationToken), continuationOptions); } /// @@ -1275,17 +1203,15 @@ public Task ContinueWith(Func, TNewResult> /// The provided CancellationToken /// has already been disposed. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWith(Func, TNewResult> continuationFunction, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWith(continuationFunction, scheduler, cancellationToken, continuationOptions, ref stackMark); + return ContinueWith(continuationFunction, scheduler, cancellationToken, continuationOptions); } // Same as the above overload, just with a stack mark. internal Task ContinueWith(Func, TNewResult> continuationFunction, TaskScheduler scheduler, - CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, ref StackCrawlMark stackMark) + CancellationToken cancellationToken, TaskContinuationOptions continuationOptions) { if (continuationFunction == null) { @@ -1306,8 +1232,7 @@ internal Task ContinueWith(Func, TNewResul Task continuationFuture = new ContinuationResultTaskFromResultTask( this, continuationFunction, null, - creationOptions, internalOptions, - ref stackMark + creationOptions, internalOptions ); // Register the continuation. If synchronous execution is requested, this may @@ -1340,11 +1265,9 @@ ref stackMark /// /// The argument is null. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWith(Func, Object, TNewResult> continuationFunction, Object state) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWith(continuationFunction, state, TaskScheduler.Current, default(CancellationToken), TaskContinuationOptions.None, ref stackMark); + return ContinueWith(continuationFunction, state, TaskScheduler.Current, default(CancellationToken), TaskContinuationOptions.None); } @@ -1372,12 +1295,10 @@ public Task ContinueWith(Func, Object, TNe /// The provided CancellationToken /// has already been disposed. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWith(Func, Object, TNewResult> continuationFunction, Object state, CancellationToken cancellationToken) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWith(continuationFunction, state, TaskScheduler.Current, cancellationToken, TaskContinuationOptions.None, ref stackMark); + return ContinueWith(continuationFunction, state, TaskScheduler.Current, cancellationToken, TaskContinuationOptions.None); } /// @@ -1406,12 +1327,10 @@ public Task ContinueWith(Func, Object, TNe /// /// The argument is null. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWith(Func, Object, TNewResult> continuationFunction, Object state, TaskScheduler scheduler) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWith(continuationFunction, state, scheduler, default(CancellationToken), TaskContinuationOptions.None, ref stackMark); + return ContinueWith(continuationFunction, state, scheduler, default(CancellationToken), TaskContinuationOptions.None); } /// @@ -1452,12 +1371,10 @@ public Task ContinueWith(Func, Object, TNe /// The argument specifies an invalid value for TaskContinuationOptions. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWith(Func, Object, TNewResult> continuationFunction, Object state, TaskContinuationOptions continuationOptions) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWith(continuationFunction, state, TaskScheduler.Current, default(CancellationToken), continuationOptions, ref stackMark); + return ContinueWith(continuationFunction, state, TaskScheduler.Current, default(CancellationToken), continuationOptions); } /// @@ -1509,17 +1426,15 @@ public Task ContinueWith(Func, Object, TNe /// The provided CancellationToken /// has already been disposed. /// - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWith(Func, Object, TNewResult> continuationFunction, Object state, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return ContinueWith(continuationFunction, state, scheduler, cancellationToken, continuationOptions, ref stackMark); + return ContinueWith(continuationFunction, state, scheduler, cancellationToken, continuationOptions); } // Same as the above overload, just with a stack mark. internal Task ContinueWith(Func, Object, TNewResult> continuationFunction, Object state, - TaskScheduler scheduler, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, ref StackCrawlMark stackMark) + TaskScheduler scheduler, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions) { if (continuationFunction == null) { @@ -1540,8 +1455,7 @@ internal Task ContinueWith(Func, Object, T Task continuationFuture = new ContinuationResultTaskFromResultTask( this, continuationFunction, state, - creationOptions, internalOptions, - ref stackMark + creationOptions, internalOptions ); // Register the continuation. If synchronous execution is requested, this may From b72fc3aa651ffdeb9136f785fc7631663a92685f Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Sun, 5 Feb 2017 09:27:53 -0500 Subject: [PATCH 2/2] Address PR feedback and other cleanup Addressed PR comment about removing ExecutionContext.Capture(ref StackCrawlMark, ...), which led me to remove NoInlining/StackCrawlMarks from some other places in Timer, Thread, ThreadPool, and Overlapped. In doing so, I found several other unnecessary members on ExecutionContext that could be removed with minor tweaks elsewhere in the source, e.g. - Dispose is a nop, so we can remove explicit try/finally's to clean it up - ExecutionContext.Run(..., bool) just ignores the bool arg, so it can be removed and all call sites redirected (but I've left it in EC, as it appears it's used via internals visible from a library in corefx) - FastCapture() just calls Capture, so the call sites can be changed (but I've left it in EC for a similar reason) - PreAllocatedDefault can be removed in favor of Default; etc. - ExecutionContext.Capture itself checks whether flow is suppressed; doing a check before it adds a TLS lookup and in doing so optimizes for an uncommon case in exchange for making the common case more expensive. I've removed those checks. And in the process, I also noticed that several lazily initialized delegates that no longer need to be, and cleaned those up. These were lazy due to needing to be for security checks that aren't relevant in coreclr. --- src/mscorlib/src/System/IO/Stream.cs | 2 +- .../CompilerServices/AsyncMethodBuilder.cs | 29 ++-------- .../src/System/Threading/ExecutionContext.cs | 48 ++-------------- .../src/System/Threading/Overlapped.cs | 45 +++++++-------- .../src/System/Threading/Tasks/Task.cs | 35 ++---------- .../Threading/Tasks/TaskContinuation.cs | 16 ++---- src/mscorlib/src/System/Threading/Thread.cs | 4 +- .../src/System/Threading/ThreadPool.cs | 21 +++---- src/mscorlib/src/System/Threading/Timer.cs | 55 ++++--------------- 9 files changed, 60 insertions(+), 195 deletions(-) diff --git a/src/mscorlib/src/System/IO/Stream.cs b/src/mscorlib/src/System/IO/Stream.cs index a7dbe4811d92..371c65099959 100644 --- a/src/mscorlib/src/System/IO/Stream.cs +++ b/src/mscorlib/src/System/IO/Stream.cs @@ -679,7 +679,7 @@ void ITaskCompletionAction.Invoke(Task completingTask) var invokeAsyncCallback = s_invokeAsyncCallback; if (invokeAsyncCallback == null) s_invokeAsyncCallback = invokeAsyncCallback = InvokeAsyncCallback; // benign race condition - using(context) ExecutionContext.Run(context, invokeAsyncCallback, this, true); + ExecutionContext.Run(context, invokeAsyncCallback, this); } } diff --git a/src/mscorlib/src/System/Runtime/CompilerServices/AsyncMethodBuilder.cs b/src/mscorlib/src/System/Runtime/CompilerServices/AsyncMethodBuilder.cs index 595274064003..35ccdac2b646 100644 --- a/src/mscorlib/src/System/Runtime/CompilerServices/AsyncMethodBuilder.cs +++ b/src/mscorlib/src/System/Runtime/CompilerServices/AsyncMethodBuilder.cs @@ -876,12 +876,12 @@ internal Action GetCompletionAction(Task taskForTracing, ref MoveNextRunner runn Debugger.NotifyOfCrossThreadDependency(); // The builder needs to flow ExecutionContext, so capture it. - var capturedContext = ExecutionContext.FastCapture(); // ok to use FastCapture as we haven't made any permission demands/asserts + var capturedContext = ExecutionContext.Capture(); // If the ExecutionContext is the default context, try to use a cached delegate, creating one if necessary. Action action; MoveNextRunner runner; - if (capturedContext != null && capturedContext.IsPreAllocatedDefault) + if (capturedContext == ExecutionContext.Default) { // Get the cached delegate, and if it's non-null, return it. action = m_defaultContextAction; @@ -1016,12 +1016,8 @@ internal void RunWithCapturedContext() if (m_context != null) { - try - { - // Use the context and callback to invoke m_stateMachine.MoveNext. - ExecutionContext.Run(m_context, InvokeMoveNextCallback, m_stateMachine, preserveSyncCtx: true); - } - finally { m_context.Dispose(); } + // Use the context and callback to invoke m_stateMachine.MoveNext. + ExecutionContext.Run(m_context, InvokeMoveNextCallback, m_stateMachine); } else { @@ -1046,24 +1042,11 @@ internal MoveNextRunner(IAsyncStateMachine stateMachine) internal void RunWithDefaultContext() { Debug.Assert(m_stateMachine != null, "The state machine must have been set before calling Run."); - ExecutionContext.Run(ExecutionContext.PreAllocatedDefault, InvokeMoveNextCallback, m_stateMachine, preserveSyncCtx: true); + ExecutionContext.Run(ExecutionContext.Default, InvokeMoveNextCallback, m_stateMachine); } /// Gets a delegate to the InvokeMoveNext method. - protected static ContextCallback InvokeMoveNextCallback - { - get { return s_invokeMoveNext ?? (s_invokeMoveNext = InvokeMoveNext); } - } - - /// Cached delegate used with ExecutionContext.Run. - private static ContextCallback s_invokeMoveNext; // lazily-initialized due to SecurityCritical attribution - - /// Invokes the MoveNext method on the supplied IAsyncStateMachine. - /// The IAsyncStateMachine machine instance. - private static void InvokeMoveNext(object stateMachine) - { - ((IAsyncStateMachine)stateMachine).MoveNext(); - } + protected static readonly ContextCallback InvokeMoveNextCallback = sm => ((IAsyncStateMachine)sm).MoveNext(); } /// diff --git a/src/mscorlib/src/System/Threading/ExecutionContext.cs b/src/mscorlib/src/System/Threading/ExecutionContext.cs index 5ea9942f650e..7baddff4fb9c 100644 --- a/src/mscorlib/src/System/Threading/ExecutionContext.cs +++ b/src/mscorlib/src/System/Threading/ExecutionContext.cs @@ -55,7 +55,7 @@ internal void Undo(Thread currentThread) [Serializable] public sealed class ExecutionContext : IDisposable, ISerializable { - private static readonly ExecutionContext Default = new ExecutionContext(); + internal static readonly ExecutionContext Default = new ExecutionContext(); private readonly IAsyncLocalValueMap m_localValues; private readonly IAsyncLocal[] m_localChangeNotifications; @@ -93,16 +93,10 @@ private ExecutionContext(SerializationInfo info, StreamingContext context) public static ExecutionContext Capture() { ExecutionContext executionContext = Thread.CurrentThread.ExecutionContext; - if (executionContext == null) - { - return Default; - } - if (executionContext.m_isFlowSuppressed) - { - // Prevent ExecutionContext.Run on a suppressed-flow context for desktop framework compatibility - return null; - } - return executionContext; + return + executionContext == null ? Default : + executionContext.m_isFlowSuppressed ? null : + executionContext; } private ExecutionContext ShallowClone(bool isFlowSuppressed) @@ -301,21 +295,6 @@ internal static void SetLocalValue(IAsyncLocal local, object newValue, bool need } } - #region Wrappers for CLR compat, to avoid ifdefs all over the BCL - - [Flags] - internal enum CaptureOptions - { - None = 0x00, - IgnoreSyncCtx = 0x01, - OptimizeDefaultCase = 0x02, - } - - internal static ExecutionContext Capture(ref StackCrawlMark stackMark, CaptureOptions captureOptions) - { - return Capture(); - } - [FriendAccessAllowed] internal static ExecutionContext FastCapture() { @@ -328,11 +307,6 @@ internal static void Run(ExecutionContext executionContext, ContextCallback call Run(executionContext, callback, state); } - internal bool IsDefaultFTContext(bool ignoreSyncCtx) - { - return this == Default; - } - public ExecutionContext CreateCopy() { return this; // since CoreCLR's ExecutionContext is immutable, we don't need to create copies. @@ -342,18 +316,6 @@ public void Dispose() { // For CLR compat only } - - internal static ExecutionContext PreAllocatedDefault - { - get { return ExecutionContext.Default; } - } - - internal bool IsPreAllocatedDefault - { - get { return this == ExecutionContext.Default; } - } - - #endregion } public struct AsyncFlowControl : IDisposable diff --git a/src/mscorlib/src/System/Threading/Overlapped.cs b/src/mscorlib/src/System/Threading/Overlapped.cs index 2b192c7b3a61..129bea6e2776 100644 --- a/src/mscorlib/src/System/Threading/Overlapped.cs +++ b/src/mscorlib/src/System/Threading/Overlapped.cs @@ -71,13 +71,11 @@ static _IOCompletionCallback() { } - internal _IOCompletionCallback(IOCompletionCallback ioCompletionCallback, ref StackCrawlMark stackMark) + internal _IOCompletionCallback(IOCompletionCallback ioCompletionCallback) { _ioCompletionCallback = ioCompletionCallback; // clone the exection context - _executionContext = ExecutionContext.Capture( - ref stackMark, - ExecutionContext.CaptureOptions.IgnoreSyncCtx | ExecutionContext.CaptureOptions.OptimizeDefaultCase); + _executionContext = ExecutionContext.Capture(); } // Context callback: same sig for SendOrPostCallback and ContextCallback static internal ContextCallback _ccb = new ContextCallback(IOCompletionCallback_Context); @@ -103,26 +101,23 @@ static unsafe internal void PerformIOCompletionCallback(uint errorCode, // Error overlapped = OverlappedData.GetOverlappedFromNative(pOVERLAP).m_overlapped; helper = overlapped.iocbHelper; - if (helper == null || helper._executionContext == null || helper._executionContext.IsDefaultFTContext(true)) - { - // We got here because of UnsafePack (or) Pack with EC flow supressed - IOCompletionCallback callback = overlapped.UserCallback; - callback( errorCode, numBytes, pOVERLAP); - } - else - { - // We got here because of Pack - helper._errorCode = errorCode; - helper._numBytes = numBytes; - helper._pOVERLAP = pOVERLAP; - using (ExecutionContext executionContext = helper._executionContext.CreateCopy()) - ExecutionContext.Run(executionContext, _ccb, helper, true); - } - - //Quickly check the VM again, to see if a packet has arrived. - + if (helper == null || helper._executionContext == null || helper._executionContext == ExecutionContext.Default) + { + // We got here because of UnsafePack (or) Pack with EC flow supressed + IOCompletionCallback callback = overlapped.UserCallback; + callback( errorCode, numBytes, pOVERLAP); + } + else + { + // We got here because of Pack + helper._errorCode = errorCode; + helper._numBytes = numBytes; + helper._pOVERLAP = pOVERLAP; + ExecutionContext.Run(helper._executionContext, _ccb, helper); + } + + //Quickly check the VM again, to see if a packet has arrived. OverlappedData.CheckVMForIOPacket(out pOVERLAP, out errorCode, out numBytes); - } while (pOVERLAP != null); } @@ -174,17 +169,15 @@ internal void ReInitialize() m_nativeOverlapped.InternalHigh = (IntPtr)0; } - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable unsafe internal NativeOverlapped* Pack(IOCompletionCallback iocb, Object userData) { if (!m_pinSelf.IsNull()) { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_Overlapped_Pack")); } - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; if (iocb != null) { - m_iocbHelper = new _IOCompletionCallback(iocb, ref stackMark); + m_iocbHelper = new _IOCompletionCallback(iocb); m_iocb = iocb; } else diff --git a/src/mscorlib/src/System/Threading/Tasks/Task.cs b/src/mscorlib/src/System/Threading/Tasks/Task.cs index 1426f71da2b7..82864aa7ba20 100644 --- a/src/mscorlib/src/System/Threading/Tasks/Task.cs +++ b/src/mscorlib/src/System/Threading/Tasks/Task.cs @@ -1633,7 +1633,7 @@ internal ExecutionContext CapturedContext } else { - return m_contingentProperties?.m_capturedContext ?? ExecutionContext.PreAllocatedDefault; + return m_contingentProperties?.m_capturedContext ?? ExecutionContext.Default; } } set @@ -1643,7 +1643,7 @@ internal ExecutionContext CapturedContext { m_stateFlags |= TASK_STATE_EXECUTIONCONTEXT_IS_NULL; } - else if (!value.IsPreAllocatedDefault) // not the default context, then inflate the contingent properties and set it + else if (value != ExecutionContext.Default) // not the default context, then inflate the contingent properties and set it { EnsureContingentPropertiesInitializedUnsafe().m_capturedContext = value; } @@ -1651,21 +1651,6 @@ internal ExecutionContext CapturedContext } } - /// - /// Static helper function to copy specific ExecutionContext - /// - /// The captured context - /// The copied context, null if the capturedContext is null - private static ExecutionContext CopyExecutionContext(ExecutionContext capturedContext) - { - if (capturedContext == null) - return null; - if (capturedContext.IsPreAllocatedDefault) - return ExecutionContext.PreAllocatedDefault; - - return capturedContext.CreateCopy(); - } - ///////////// // methods @@ -2465,10 +2450,7 @@ private void ExecuteWithThreadLocal(ref Task currentTaskSlot) // Run the task. We need a simple shim that converts the // object back into a Task object, so that we can Execute it. - // Lazily initialize the callback delegate; benign race condition - var callback = s_ecCallback; - if (callback == null) s_ecCallback = callback = new ContextCallback(ExecutionContextCallback); - ExecutionContext.Run(ec, callback, this, true); + ExecutionContext.Run(ec, s_ecCallback, this); } if (AsyncCausalityTracer.LoggingOn) @@ -2495,16 +2477,7 @@ private void ExecuteWithThreadLocal(ref Task currentTaskSlot) } } - // Cached callback delegate that's lazily initialized due to ContextCallback being SecurityCritical - private static ContextCallback s_ecCallback; - - private static void ExecutionContextCallback(object obj) - { - Task task = obj as Task; - Debug.Assert(task != null, "expected a task object"); - task.Execute(); - } - + private static readonly ContextCallback s_ecCallback = obj => ((Task)obj).Execute(); /// /// The actual code which invokes the body of the task. This can be overriden in derived types. diff --git a/src/mscorlib/src/System/Threading/Tasks/TaskContinuation.cs b/src/mscorlib/src/System/Threading/Tasks/TaskContinuation.cs index 9cf0142b6510..3c6ccd8dd49f 100644 --- a/src/mscorlib/src/System/Threading/Tasks/TaskContinuation.cs +++ b/src/mscorlib/src/System/Threading/Tasks/TaskContinuation.cs @@ -543,7 +543,7 @@ internal AwaitTaskContinuation(Action action, bool flowExecutionContext) m_action = action; if (flowExecutionContext) { - m_capturedContext = ExecutionContext.FastCapture(); + m_capturedContext = ExecutionContext.Capture(); } } @@ -648,11 +648,7 @@ void ExecuteWorkItemHelper() // If there is an execution context, get the cached delegate and run the action under the context. else { - try - { - ExecutionContext.Run(m_capturedContext, GetInvokeActionCallback(), m_action, true); - } - finally { m_capturedContext.Dispose(); } + ExecutionContext.Run(m_capturedContext, GetInvokeActionCallback(), m_action); } } finally @@ -667,8 +663,7 @@ void ExecuteWorkItemHelper() void IThreadPoolWorkItem.ExecuteWorkItem() { // inline the fast path - if (m_capturedContext == null && !TplEtwProvider.Log.IsEnabled() - ) + if (m_capturedContext == null && !TplEtwProvider.Log.IsEnabled()) { m_action(); } @@ -717,7 +712,7 @@ protected void RunCallback(ContextCallback callback, object state, ref Task curr // If there's no captured context, just run the callback directly. if (m_capturedContext == null) callback(state); // Otherwise, use the captured context to do so. - else ExecutionContext.Run(m_capturedContext, callback, state, true); + else ExecutionContext.Run(m_capturedContext, callback, state); } catch (Exception exc) // we explicitly do not request handling of dangerous exceptions like AVs { @@ -727,9 +722,6 @@ protected void RunCallback(ContextCallback callback, object state, ref Task curr { // Restore the current task information if (prevCurrentTask != null) currentTask = prevCurrentTask; - - // Clean up after the execution context, which is only usable once. - if (m_capturedContext != null) m_capturedContext.Dispose(); } } diff --git a/src/mscorlib/src/System/Threading/Thread.cs b/src/mscorlib/src/System/Threading/Thread.cs index bfa47f7c27d3..f05e10472df5 100644 --- a/src/mscorlib/src/System/Threading/Thread.cs +++ b/src/mscorlib/src/System/Threading/Thread.cs @@ -280,9 +280,7 @@ private void Start(ref StackCrawlMark stackMark) // If we reach here with a null delegate, something is broken. But we'll let the StartInternal method take care of // reporting an error. Just make sure we dont try to dereference a null delegate. ThreadHelper t = (ThreadHelper)(m_Delegate.Target); - ExecutionContext ec = ExecutionContext.Capture( - ref stackMark, - ExecutionContext.CaptureOptions.IgnoreSyncCtx); + ExecutionContext ec = ExecutionContext.Capture(); t.SetExecutionContextHelper(ec); } diff --git a/src/mscorlib/src/System/Threading/ThreadPool.cs b/src/mscorlib/src/System/Threading/ThreadPool.cs index 67701ec5333f..8076a76176b6 100644 --- a/src/mscorlib/src/System/Threading/ThreadPool.cs +++ b/src/mscorlib/src/System/Threading/ThreadPool.cs @@ -951,7 +951,7 @@ void IThreadPoolWorkItem.ExecuteWorkItem() } else { - ExecutionContext.Run(context, ccb, this, preserveSyncCtx:true); + ExecutionContext.Run(context, ccb, this); } } @@ -1010,7 +1010,7 @@ void IThreadPoolWorkItem.ExecuteWorkItem() #if DEBUG MarkExecuted(aborted:false); #endif - ExecutionContext.Run(ExecutionContext.PreAllocatedDefault, ccb, this, preserveSyncCtx:true); + ExecutionContext.Run(ExecutionContext.Default, ccb, this); } void IThreadPoolWorkItem.MarkAborted(ThreadAbortException tae) @@ -1042,17 +1042,15 @@ internal class _ThreadPoolWaitOrTimerCallback private static readonly ContextCallback _ccbt = new ContextCallback(WaitOrTimerCallback_Context_t); private static readonly ContextCallback _ccbf = new ContextCallback(WaitOrTimerCallback_Context_f); - internal _ThreadPoolWaitOrTimerCallback(WaitOrTimerCallback waitOrTimerCallback, Object state, bool compressStack, ref StackCrawlMark stackMark) + internal _ThreadPoolWaitOrTimerCallback(WaitOrTimerCallback waitOrTimerCallback, Object state, bool compressStack) { _waitOrTimerCallback = waitOrTimerCallback; _state = state; - if (compressStack && !ExecutionContext.IsFlowSuppressed()) + if (compressStack) { // capture the exection context - _executionContext = ExecutionContext.Capture( - ref stackMark, - ExecutionContext.CaptureOptions.IgnoreSyncCtx | ExecutionContext.CaptureOptions.OptimizeDefaultCase); + _executionContext = ExecutionContext.Capture(); } } @@ -1081,10 +1079,7 @@ internal static void PerformWaitOrTimerCallback(Object state, bool timedOut) } else { - using (ExecutionContext executionContext = helper._executionContext.CreateCopy()) - { - ExecutionContext.Run(executionContext, timedOut ? _ccbt : _ccbf, helper, preserveSyncCtx:true); - } + ExecutionContext.Run(helper._executionContext, timedOut ? _ccbt : _ccbf, helper); } } @@ -1167,7 +1162,7 @@ bool compressStack if (callBack != null) { - _ThreadPoolWaitOrTimerCallback callBackHelper = new _ThreadPoolWaitOrTimerCallback(callBack, state, compressStack, ref stackMark); + _ThreadPoolWaitOrTimerCallback callBackHelper = new _ThreadPoolWaitOrTimerCallback(callBack, state, compressStack); state = (Object)callBackHelper; // call SetWaitObject before native call so that waitObject won't be closed before threadpoolmgr registration // this could occur if callback were to fire before SetWaitObject does its addref @@ -1303,7 +1298,7 @@ public static bool QueueUserWorkItem(WaitCallback callBack, object state) ExecutionContext context = ExecutionContext.Capture(); - IThreadPoolWorkItem tpcallBack = context == ExecutionContext.PreAllocatedDefault ? + IThreadPoolWorkItem tpcallBack = context == ExecutionContext.Default ? new QueueUserWorkItemCallbackDefaultContext(callBack, state) : (IThreadPoolWorkItem)new QueueUserWorkItemCallback(callBack, state, context); diff --git a/src/mscorlib/src/System/Threading/Timer.cs b/src/mscorlib/src/System/Threading/Timer.cs index a2b437857c14..263e47ae0f3d 100644 --- a/src/mscorlib/src/System/Threading/Timer.cs +++ b/src/mscorlib/src/System/Threading/Timer.cs @@ -435,19 +435,13 @@ sealed class TimerQueueTimer volatile WaitHandle m_notifyWhenNoCallbacksRunning; - internal TimerQueueTimer(TimerCallback timerCallback, object state, uint dueTime, uint period, ref StackCrawlMark stackMark) + internal TimerQueueTimer(TimerCallback timerCallback, object state, uint dueTime, uint period) { m_timerCallback = timerCallback; m_state = state; m_dueTime = Timeout.UnsignedInfinite; m_period = Timeout.UnsignedInfinite; - - if (!ExecutionContext.IsFlowSuppressed()) - { - m_executionContext = ExecutionContext.Capture( - ref stackMark, - ExecutionContext.CaptureOptions.IgnoreSyncCtx | ExecutionContext.CaptureOptions.OptimizeDefaultCase); - } + m_executionContext = ExecutionContext.Capture(); // // After the following statement, the timer may fire. No more manipulation of timer state outside of @@ -601,29 +595,15 @@ internal void CallCallback() } else { - using (ExecutionContext executionContext = - m_executionContext.IsPreAllocatedDefault ? m_executionContext : m_executionContext.CreateCopy()) - { - ContextCallback callback = s_callCallbackInContext; - if (callback == null) - s_callCallbackInContext = callback = new ContextCallback(CallCallbackInContext); - - ExecutionContext.Run( - executionContext, - callback, - this, // state - true); // ignoreSyncCtx - } + ExecutionContext.Run(m_executionContext, s_callCallbackInContext, this); } } - private static ContextCallback s_callCallbackInContext; - - private static void CallCallbackInContext(object state) + private static readonly ContextCallback s_callCallbackInContext = state => { TimerQueueTimer t = (TimerQueueTimer)state; t.m_timerCallback(t.m_state); - } + }; } // @@ -686,7 +666,6 @@ public sealed class Timer : MarshalByRefObject, IDisposable private TimerHolder m_timer; - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public Timer(TimerCallback callback, Object state, int dueTime, @@ -697,12 +676,10 @@ public Timer(TimerCallback callback, if (period < -1 ) throw new ArgumentOutOfRangeException(nameof(period), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); Contract.EndContractBlock(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - TimerSetup(callback,state,(UInt32)dueTime,(UInt32)period,ref stackMark); + TimerSetup(callback,state,(UInt32)dueTime,(UInt32)period); } - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public Timer(TimerCallback callback, Object state, TimeSpan dueTime, @@ -720,22 +697,18 @@ public Timer(TimerCallback callback, if (periodTm > MAX_SUPPORTED_TIMEOUT) throw new ArgumentOutOfRangeException(nameof(periodTm),Environment.GetResourceString("ArgumentOutOfRange_PeriodTooLarge")); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - TimerSetup(callback,state,(UInt32)dueTm,(UInt32)periodTm,ref stackMark); + TimerSetup(callback,state,(UInt32)dueTm,(UInt32)periodTm); } [CLSCompliant(false)] - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public Timer(TimerCallback callback, Object state, UInt32 dueTime, UInt32 period) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - TimerSetup(callback,state,dueTime,period,ref stackMark); + TimerSetup(callback,state,dueTime,period); } - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public Timer(TimerCallback callback, Object state, long dueTime, @@ -750,11 +723,9 @@ public Timer(TimerCallback callback, if (period > MAX_SUPPORTED_TIMEOUT) throw new ArgumentOutOfRangeException(nameof(period),Environment.GetResourceString("ArgumentOutOfRange_PeriodTooLarge")); Contract.EndContractBlock(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - TimerSetup(callback,state,(UInt32) dueTime, (UInt32) period,ref stackMark); + TimerSetup(callback,state,(UInt32) dueTime, (UInt32) period); } - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public Timer(TimerCallback callback) { int dueTime = -1; // we want timer to be registered, but not activated. Requires caller to call @@ -762,21 +733,19 @@ public Timer(TimerCallback callback) // for a timer to be fired before the returned value is assigned to the variable, // potentially causing the callback to reference a bogus value (if passing the timer to the callback). - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - TimerSetup(callback, this, (UInt32)dueTime, (UInt32)period, ref stackMark); + TimerSetup(callback, this, (UInt32)dueTime, (UInt32)period); } private void TimerSetup(TimerCallback callback, Object state, UInt32 dueTime, - UInt32 period, - ref StackCrawlMark stackMark) + UInt32 period) { if (callback == null) throw new ArgumentNullException(nameof(TimerCallback)); Contract.EndContractBlock(); - m_timer = new TimerHolder(new TimerQueueTimer(callback, state, dueTime, period, ref stackMark)); + m_timer = new TimerHolder(new TimerQueueTimer(callback, state, dueTime, period)); } public bool Change(int dueTime, int period)