Use ReferenceEquals not MulticastDelegate.equals (#2330)

It never inlines because its such a chunky method
This commit is contained in:
Ben Adams 2018-02-17 16:13:15 +00:00 committed by David Fowler
parent 07026cf6db
commit 1f8591184e
2 changed files with 7 additions and 7 deletions

View File

@ -32,7 +32,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
}; };
public LibuvAwaitable<TRequest> GetAwaiter() => this; public LibuvAwaitable<TRequest> GetAwaiter() => this;
public bool IsCompleted => _callback == _callbackCompleted; public bool IsCompleted => ReferenceEquals(_callback, _callbackCompleted);
public UvWriteResult GetResult() public UvWriteResult GetResult()
{ {
@ -54,8 +54,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
// There should never be a race between IsCompleted and OnCompleted since both operations // There should never be a race between IsCompleted and OnCompleted since both operations
// should always be on the libuv thread // should always be on the libuv thread
if (_callback == _callbackCompleted || if (ReferenceEquals(_callback, _callbackCompleted) ||
Interlocked.CompareExchange(ref _callback, continuation, null) == _callbackCompleted) ReferenceEquals(Interlocked.CompareExchange(ref _callback, continuation, null), _callbackCompleted))
{ {
Debug.Fail($"{typeof(LibuvAwaitable<TRequest>)}.{nameof(OnCompleted)} raced with {nameof(IsCompleted)}, running callback inline."); Debug.Fail($"{typeof(LibuvAwaitable<TRequest>)}.{nameof(OnCompleted)} raced with {nameof(IsCompleted)}, running callback inline.");

View File

@ -18,11 +18,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal
private SocketError _error; private SocketError _error;
public SocketAwaitable GetAwaiter() => this; public SocketAwaitable GetAwaiter() => this;
public bool IsCompleted => _callback == _callbackCompleted; public bool IsCompleted => ReferenceEquals(_callback, _callbackCompleted);
public int GetResult() public int GetResult()
{ {
Debug.Assert(_callback == _callbackCompleted); Debug.Assert(ReferenceEquals(_callback, _callbackCompleted));
_callback = null; _callback = null;
@ -36,8 +36,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal
public void OnCompleted(Action continuation) public void OnCompleted(Action continuation)
{ {
if (_callback == _callbackCompleted || if (ReferenceEquals(_callback, _callbackCompleted) ||
Interlocked.CompareExchange(ref _callback, continuation, null) == _callbackCompleted) ReferenceEquals(Interlocked.CompareExchange(ref _callback, continuation, null), _callbackCompleted))
{ {
continuation(); continuation();
} }