Don't preserve the ExecutionContext when dispatching callbacks (#2861)

* Don't preserve the ExecutionContext when dispatching callbacks
- The layers up stack already preserve and restore the ExecutionContext, there's no need to capture and run for the scheduler callback and cancellation token callback
This commit is contained in:
David Fowler 2018-08-28 09:32:33 -07:00 committed by GitHub
parent b039fb73c4
commit 6dc55a0462
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 6 additions and 6 deletions

View File

@ -67,7 +67,7 @@ namespace Microsoft.AspNetCore.Connections
public override void Abort(ConnectionAbortedException abortReason)
{
ThreadPool.QueueUserWorkItem(cts => ((CancellationTokenSource)cts).Cancel(), _connectionClosedTokenSource);
ThreadPool.UnsafeQueueUserWorkItem(cts => ((CancellationTokenSource)cts).Cancel(), _connectionClosedTokenSource);
}
public void Dispose()

View File

@ -24,7 +24,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2
public void OnCompleted(Action continuation)
{
ThreadPool.QueueUserWorkItem(state => ((Action)state)(), continuation);
ThreadPool.UnsafeQueueUserWorkItem(state => ((Action)state)(), continuation);
}
public void UnsafeOnCompleted(Action continuation)

View File

@ -107,7 +107,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
// We're done with the socket now
_socket.Dispose();
ThreadPool.QueueUserWorkItem(state => ((LibuvConnection)state).CancelConnectionClosedToken(), this);
ThreadPool.UnsafeQueueUserWorkItem(state => ((LibuvConnection)state).CancelConnectionClosedToken(), this);
}
}
catch (Exception e)

View File

@ -30,7 +30,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal
{
if (!_doingWork)
{
System.Threading.ThreadPool.QueueUserWorkItem(_doWorkCallback, this);
System.Threading.ThreadPool.UnsafeQueueUserWorkItem(_doWorkCallback, this);
_doingWork = true;
}
}

View File

@ -84,7 +84,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal
_receiver.Dispose();
_sender.Dispose();
ThreadPool.QueueUserWorkItem(state => ((SocketConnection)state).CancelConnectionClosedToken(), this);
ThreadPool.UnsafeQueueUserWorkItem(state => ((SocketConnection)state).CancelConnectionClosedToken(), this);
}
catch (Exception ex)
{

View File

@ -45,7 +45,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests.TestTrans
_isClosed = true;
ThreadPool.QueueUserWorkItem(state =>
ThreadPool.UnsafeQueueUserWorkItem(state =>
{
var self = (InMemoryTransportConnection)state;
self._connectionClosedTokenSource.Cancel();