Skip to content

Commit

Permalink
Merge branch 'main' of github.com:dotnet/runtime into optimize-byref-…
Browse files Browse the repository at this point in the history
…structs
  • Loading branch information
EgorBo committed Jun 26, 2024
2 parents 0a3eea6 + 6effb8f commit ddf00b5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 19 deletions.
18 changes: 12 additions & 6 deletions src/coreclr/jit/hwintrinsicxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,18 +267,24 @@ static CORINFO_InstructionSet lookupInstructionSet(const char* className)
{
if (strncmp(className + 6, "128", 3) == 0)
{
assert((className[9] == '\0') || (strcmp(className + 9, "`1") == 0));
return InstructionSet_Vector128;
if ((className[9] == '\0') || (strcmp(className + 9, "`1") == 0))
{
return InstructionSet_Vector128;
}
}
else if (strncmp(className + 6, "256", 3) == 0)
{
assert((className[9] == '\0') || (strcmp(className + 9, "`1") == 0));
return InstructionSet_Vector256;
if ((className[9] == '\0') || (strcmp(className + 9, "`1") == 0))
{
return InstructionSet_Vector256;
}
}
else if (strncmp(className + 6, "512", 3) == 0)
{
assert((className[9] == '\0') || (strcmp(className + 9, "`1") == 0));
return InstructionSet_Vector512;
if ((className[9] == '\0') || (strcmp(className + 9, "`1") == 0))
{
return InstructionSet_Vector512;
}
}
}
else if (strcmp(className, "VL") == 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,9 @@ private async void StartConnectionHandshake(QuicConnection connection, SslClient
// https://github.com/microsoft/msquic/discussions/2705.
// This will be assigned to before the linked CTS is cancelled
TimeSpan handshakeTimeout = QuicDefaults.HandshakeTimeout;
using CancellationTokenSource linkedCts = CancellationTokenSource.CreateLinkedTokenSource(_disposeCts.Token, connection.ConnectionShutdownToken);
try
{
using CancellationTokenSource linkedCts = CancellationTokenSource.CreateLinkedTokenSource(_disposeCts.Token, connection.ConnectionShutdownToken);
cancellationToken = linkedCts.Token;
// Initial timeout for retrieving connection options.
linkedCts.CancelAfter(handshakeTimeout);
Expand All @@ -249,7 +249,7 @@ private async void StartConnectionHandshake(QuicConnection connection, SslClient
await connection.DisposeAsync().ConfigureAwait(false);
}
}
catch (OperationCanceledException) when (connection.ConnectionShutdownToken.IsCancellationRequested)
catch (OperationCanceledException) when (connection.ConnectionShutdownToken.IsCancellationRequested && !linkedCts.IsCancellationRequested)
{
// Connection closed by peer
if (NetEventSource.Log.IsEnabled())
Expand Down
24 changes: 13 additions & 11 deletions src/libraries/System.Net.Quic/src/System/Net/Quic/QuicStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Diagnostics;
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -359,38 +360,40 @@ public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationTo
/// <param name="buffer">The region of memory to write data from.</param>
/// <param name="cancellationToken">The token to monitor for cancellation requests. The default value is <see cref="CancellationToken.None"/>.</param>
/// <param name="completeWrites">Notifies the peer about gracefully closing the write side, i.e.: sends FIN flag with the data.</param>
public async ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, bool completeWrites, CancellationToken cancellationToken = default)
public ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, bool completeWrites, CancellationToken cancellationToken = default)
{
ObjectDisposedException.ThrowIf(_disposed == 1, this);
if (_disposed == 1)
{
return ValueTask.FromException(ExceptionDispatchInfo.SetCurrentStackTrace(new ObjectDisposedException(nameof(QuicStream))));
}

if (!_canWrite)
{
throw new InvalidOperationException(SR.net_quic_writing_notallowed);
return ValueTask.FromException(ExceptionDispatchInfo.SetCurrentStackTrace(new InvalidOperationException(SR.net_quic_writing_notallowed)));
}

if (NetEventSource.Log.IsEnabled())
{
NetEventSource.Info(this, $"{this} Stream writing memory of '{buffer.Length}' bytes while {(completeWrites ? "completing" : "not completing")} writes.");
}

if (_sendTcs.IsCompleted)
if (_sendTcs.IsCompleted && cancellationToken.IsCancellationRequested)
{
// Special case exception type for pre-canceled token while we've already transitioned to a final state and don't need to abort write.
// It must happen before we try to get the value task, since the task source is versioned and each instance must be awaited.
cancellationToken.ThrowIfCancellationRequested();
return ValueTask.FromCanceled(cancellationToken);
}

// Concurrent call, this one lost the race.
if (!_sendTcs.TryGetValueTask(out ValueTask valueTask, this, cancellationToken))
{
throw new InvalidOperationException(SR.Format(SR.net_io_invalidnestedcall, "write"));
return ValueTask.FromException(ExceptionDispatchInfo.SetCurrentStackTrace(new InvalidOperationException(SR.Format(SR.net_io_invalidnestedcall, "write"))));
}

// No need to call anything since we already have a result, most likely an exception.
if (valueTask.IsCompleted)
{
await valueTask.ConfigureAwait(false);
return;
return valueTask;
}

// For an empty buffer complete immediately, close the writing side of the stream if necessary.
Expand All @@ -401,8 +404,7 @@ public async ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, bool completeWrit
{
CompleteWrites();
}
await valueTask.ConfigureAwait(false);
return;
return valueTask;
}

// We own the lock, abort might happen, but exception will get stored instead.
Expand Down Expand Up @@ -438,7 +440,7 @@ public async ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, bool completeWrit
}
}

await valueTask.ConfigureAwait(false);
return valueTask;
}

/// <summary>
Expand Down
1 change: 1 addition & 0 deletions src/native/managed/native-library.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
-->
<StripSymbols>false</StripSymbols>
<SuppressGenerateILCompilerExplicitPackageReferenceWarning>true</SuppressGenerateILCompilerExplicitPackageReferenceWarning>
<ControlFlowGuard>Guard</ControlFlowGuard>
</PropertyGroup>

<!-- set the shared library name. this helps the native linker correctly reference this shared
Expand Down

0 comments on commit ddf00b5

Please sign in to comment.