Add stack depth check to all Task continuations (dotnet/coreclr#23152)
authorStephen Toub <stoub@microsoft.com>
Sat, 9 Mar 2019 16:41:43 +0000 (11:41 -0500)
committerJan Kotas <jkotas@microsoft.com>
Sat, 9 Mar 2019 16:41:43 +0000 (08:41 -0800)
commit1f4692da8c4e5f73666a5720b6d1d2d8f1d286dd
tree834991595beb9160262f6c2e7e965ac69f4197f2
parent234c9ec8b22719222c3be22375d3d9a111ed89a7
Add stack depth check to all Task continuations (dotnet/coreclr#23152)

Currently Task has a stack depth check that avoids stack overflows on very deep stack continuation chains, but it only applies to Task.ContinueWith, not to other kinds of continuations.  This changes that to have it apply to all.

As part of this, this also deletes the current StackGuard type used to achieve the check.  The type was meant to avoid expensive calls to check where we are on the stack, but now that we're using TryEnsureSufficientExecutionStack, it's actually faster to just call that rather than access the current StackGuard from a ThreadLocal.  This then also cleans up the call sites nicely, as they no longer need finally blocks to undo the increment performed on the StackGuard.

Commit migrated from https://github.com/dotnet/coreclr/commit/6633b51df7f91623190ba6bf04c00869cd0fc1e4
src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs
src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/TaskScheduler.cs