Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace System.Runtime.CompilerServices;

[AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)]
internal sealed class RuntimeAsyncMethodGenerationAttribute(bool runtimeAsync) : Attribute
{
public bool RuntimeAsync => runtimeAsync;
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ private void Reset()
/// performed by the function.
/// </remarks>
[AsyncMethodBuilder(typeof(PoolingAsyncValueTaskMethodBuilder))]
[RuntimeAsyncMethodGeneration(false)]
public static async ValueTask InvokeAsync<TState>(Action<TState> action, TState state, CancellationToken cancellationToken)
{
// Queue the work to complete asynchronously. Logically, this is just queueing a work item to the thread pool.
Expand Down Expand Up @@ -120,6 +121,7 @@ public static async ValueTask InvokeAsync<TState>(Action<TState> action, TState
/// performed by the function.
/// </remarks>
[AsyncMethodBuilder(typeof(PoolingAsyncValueTaskMethodBuilder<>))]
[RuntimeAsyncMethodGeneration(false)]
public static async ValueTask<TResult> InvokeAsync<TState, TResult>(Func<TState, TResult> func, TState state, CancellationToken cancellationToken)
{
// Queue the work to complete asynchronously. Logically, this is just queueing a work item to the thread pool.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ System.IO.Pipelines.PipeReader</PackageDescription>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'">
<Compile Include="System\IO\Pipelines\ThreadPoolScheduler.netcoreapp.cs" />
<Compile Include="$(CommonPath)System\Runtime\CompilerServices\RuntimeAsyncMethodGenerationAttribute.cs"
Link="Common\System\Runtime\CompilerServices\RuntimeAsyncMethodGenerationAttribute.cs" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ private ValueTask<ReadResult> ReadInternalAsync(int? minimumSize, CancellationTo

#if NET
[AsyncMethodBuilder(typeof(PoolingAsyncValueTaskMethodBuilder<>))]
[RuntimeAsyncMethodGeneration(false)]
#endif
static async ValueTask<ReadResult> Core(StreamPipeReader reader, int? minimumSize, CancellationTokenSource tokenSource, CancellationToken cancellationToken)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ private void Cancel()

#if NET
[AsyncMethodBuilder(typeof(PoolingAsyncValueTaskMethodBuilder<>))]
[RuntimeAsyncMethodGeneration(false)]
#endif
private async ValueTask<FlushResult> FlushAsyncInternal(bool writeToStream, ReadOnlyMemory<byte> data, CancellationToken cancellationToken = default)
{
Expand Down
2 changes: 2 additions & 0 deletions src/libraries/System.IO.Pipes/src/System.IO.Pipes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@
Link="Common\Interop\Windows\Interop.GetCurrentThreadId.cs" />
<Compile Include="$(CommonPath)System\Threading\AsyncOverSyncWithIoCancellation.cs"
Link="Common\System\Threading\AsyncOverSyncWithIoCancellation.cs" />
<Compile Include="$(CommonPath)System\Runtime\CompilerServices\RuntimeAsyncMethodGenerationAttribute.cs"
Link="Common\System\Runtime\CompilerServices\RuntimeAsyncMethodGenerationAttribute.cs" />
<Compile Include="Microsoft\Win32\SafeHandles\SafePipeHandle.Windows.cs" />
<Compile Include="System\IO\Pipes\AnonymousPipeServerStreamAcl.cs" />
<Compile Include="System\IO\Pipes\AnonymousPipeServerStream.Windows.cs" />
Expand Down
2 changes: 2 additions & 0 deletions src/libraries/System.Net.Http/src/System.Net.Http.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@
<Compile Include="System\Net\Http\SocketsHttpHandler\SocketsHttpPlaintextStreamFilterContext.cs" />
<Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
Link="Common\DisableRuntimeMarshalling.cs" />
<Compile Include="$(CommonPath)System\Runtime\CompilerServices\RuntimeAsyncMethodGenerationAttribute.cs"
Link="Common\System\Runtime\CompilerServices\RuntimeAsyncMethodGenerationAttribute.cs" />
<Compile Include="$(CommonPath)System\IO\DelegatingStream.cs"
Link="Common\System\IO\DelegatingStream.cs" />
<Compile Include="$(CommonPath)System\IO\ReadOnlyMemoryStream.cs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1836,6 +1836,7 @@ private ValueTask<int> ReadBufferedAsync(Memory<byte> destination)
}

[AsyncMethodBuilder(typeof(PoolingAsyncValueTaskMethodBuilder<>))]
[RuntimeAsyncMethodGeneration(false)]
private async ValueTask<int> ReadBufferedAsyncCore(Memory<byte> destination)
{
// This is called when reading the response body.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public override int Read(Span<byte> buffer)
}

[AsyncMethodBuilder(typeof(PoolingAsyncValueTaskMethodBuilder<>))]
[RuntimeAsyncMethodGeneration(false)]
public override async ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken)
{
CancellationHelper.ThrowIfCancellationRequested(cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
Link="Common\System\LocalAppContextSwitches.Common.cs" />
<Compile Include="$(CommonPath)System\Net\LocalAppContextSwitches.Net.cs"
Link="Common\System\Net\LocalAppContextSwitches.Net.cs" />
<Compile Include="$(CommonPath)System\Runtime\CompilerServices\RuntimeAsyncMethodGenerationAttribute.cs"
Link="Common\System\Runtime\CompilerServices\RuntimeAsyncMethodGenerationAttribute.cs" />
</ItemGroup>

<ItemGroup Condition="'$(TargetPlatformIdentifier)' != ''">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,7 @@ private bool HaveFullTlsFrame(out int frameSize)
}

[AsyncMethodBuilder(typeof(PoolingAsyncValueTaskMethodBuilder<>))]
[RuntimeAsyncMethodGeneration(false)]
private async ValueTask<int> EnsureFullTlsFrameAsync<TIOAdapter>(CancellationToken cancellationToken, int estimatedSize)
where TIOAdapter : IReadWriteAdapter
{
Expand Down Expand Up @@ -839,6 +840,7 @@ private async ValueTask<int> EnsureFullTlsFrameAsync<TIOAdapter>(CancellationTok
}

[AsyncMethodBuilder(typeof(PoolingAsyncValueTaskMethodBuilder<>))]
[RuntimeAsyncMethodGeneration(false)]
private async ValueTask<int> ReadAsyncInternal<TIOAdapter>(Memory<byte> buffer, CancellationToken cancellationToken)
where TIOAdapter : IReadWriteAdapter
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
Link="Common\System\Net\Logging\NetEventSource.Common.cs" />
<Compile Include="$(CommonPath)System\Net\Logging\NetEventSource.Common.Associate.cs"
Link="Common\System\Net\Logging\NetEventSource.Common.Associate.cs" />
<Compile Include="$(CommonPath)System\Runtime\CompilerServices\RuntimeAsyncMethodGenerationAttribute.cs"
Link="Common\System\Runtime\CompilerServices\RuntimeAsyncMethodGenerationAttribute.cs" />
</ItemGroup>

<!-- Windows specific files -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,7 @@ private static void WriteRandomMask(byte[] buffer, int offset) =>
/// <param name="cancellationToken">The CancellationToken used to cancel the websocket.</param>
/// <returns>Information about the received message.</returns>
[AsyncMethodBuilder(typeof(PoolingAsyncValueTaskMethodBuilder<>))]
[RuntimeAsyncMethodGeneration(false)]
private async ValueTask<TResult> ReceiveAsyncPrivate<TResult>(Memory<byte> payloadBuffer, CancellationToken cancellationToken)
{
// This is a long method. While splitting it up into pieces would arguably help with readability, doing so would
Expand Down Expand Up @@ -1599,6 +1600,7 @@ private void ConsumeFromBuffer(int count)
}

[AsyncMethodBuilder(typeof(PoolingAsyncValueTaskMethodBuilder))]
[RuntimeAsyncMethodGeneration(false)]
private async ValueTask EnsureBufferContainsAsync(int minimumRequiredBytes, CancellationToken cancellationToken)
{
Debug.Assert(minimumRequiredBytes <= _receiveBuffer.Length, $"Requested number of bytes {minimumRequiredBytes} must not exceed {_receiveBuffer.Length}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1560,6 +1560,9 @@
<Compile Include="$(LibrariesProjectRoot)System.Reflection.Metadata\src\System\Reflection\Metadata\TypeNameParserHelpers.cs">
<Link>Common\System\Reflection\Metadata\TypeNameParserHelpers.cs</Link>
</Compile>
<Compile Include="$(CommonPath)System\Runtime\CompilerServices\RuntimeAsyncMethodGenerationAttribute.cs">
<Link>Common\System\Runtime\CompilerServices\RuntimeAsyncMethodGenerationAttribute.cs</Link>
</Compile>
<Compile Include="$(CommonPath)System\Runtime\Versioning\NonVersionableAttribute.cs">
<Link>Common\System\Runtime\Versioning\NonVersionableAttribute.cs</Link>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ private async ValueTask<int> ReadFromNonSeekableAsync(Memory<byte> destination,
}

[AsyncMethodBuilder(typeof(PoolingAsyncValueTaskMethodBuilder<>))]
[RuntimeAsyncMethodGeneration(false)]
private async ValueTask<int> ReadAsyncSlowPath(Task semaphoreLockTask, Memory<byte> buffer, CancellationToken cancellationToken)
{
Debug.Assert(_asyncActiveSemaphore != null);
Expand Down Expand Up @@ -671,6 +672,7 @@ private async ValueTask WriteToNonSeekableAsync(ReadOnlyMemory<byte> source, Can
}

[AsyncMethodBuilder(typeof(PoolingAsyncValueTaskMethodBuilder))]
[RuntimeAsyncMethodGeneration(false)]
private async ValueTask WriteAsyncSlowPath(Task semaphoreLockTask, ReadOnlyMemory<byte> source, CancellationToken cancellationToken)
{
Debug.Assert(_asyncActiveSemaphore != null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ public ValueTask<int> ReadAtLeastAsync(Memory<byte> buffer, int minimumBytes, bo

// No argument checking is done here. It is up to the caller.
[AsyncMethodBuilder(typeof(PoolingAsyncValueTaskMethodBuilder<>))]
[RuntimeAsyncMethodGeneration(false)]
private async ValueTask<int> ReadAtLeastAsyncCore(Memory<byte> buffer, int minimumBytes, bool throwOnEndOfStream, CancellationToken cancellationToken)
{
Debug.Assert(minimumBytes <= buffer.Length);
Expand Down
Loading