Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
e25dfd0
[wasm] Enable more MT PLinq areas
radekdoulik Dec 20, 2023
662ef67
Add missing pieces
radekdoulik Dec 21, 2023
bf49396
Merge remote-tracking branch 'remotes/origin/main'
radekdoulik Jan 9, 2024
5c10ce7
Add System.Threading.WebAssembly.Threading.csproj
radekdoulik Jan 10, 2024
15cbfca
Fix System.Threading to work with the new wasm MT ref assembly
radekdoulik Jan 10, 2024
7f47026
Enable the failing test
radekdoulik Jan 10, 2024
f5972b1
Use the new ref assembly in the System.Linq.Parallel
radekdoulik Jan 10, 2024
b512789
Remove now obsolete API check supressions
radekdoulik Jan 10, 2024
d7744be
Increase the thread pool size to make the plinq tests pass
radekdoulik Jan 10, 2024
8398959
Add API check suppressions for System.Threading
radekdoulik Jan 10, 2024
abf27e0
Always use the API suppressions for System.Threading
radekdoulik Jan 10, 2024
6d85a1e
Merge branch 'main' into pr-wasm-plinq-wip
radekdoulik Jan 10, 2024
aedafd3
Remove unwanted attributes from the implementation
radekdoulik Jan 10, 2024
858597f
Add suppressions to corelib
radekdoulik Jan 10, 2024
04f1427
Revert "Remove unwanted attributes from the implementation"
radekdoulik Jan 10, 2024
b1f206f
Build fixes
radekdoulik Jan 10, 2024
39c6d05
Merge branch 'main' into pr-wasm-plinq-wip
radekdoulik Jan 10, 2024
ff19ee2
Remove unnecessary suppression
radekdoulik Jan 10, 2024
93fe04b
Merge branch 'main' into pr-wasm-plinq-wip
radekdoulik Jan 10, 2024
1d198f6
Remove unwanted source file from the list
radekdoulik Jan 10, 2024
d7e33fb
Merge branch 'main' into pr-wasm-plinq-wip
radekdoulik Jan 10, 2024
55b50b7
Merge branch 'main' into pr-wasm-plinq-wip
radekdoulik Jan 11, 2024
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
Expand Up @@ -15,7 +15,8 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="$(LibrariesProjectRoot)System.Threading.Thread.WebAssembly.Threading\ref\System.Threading.Thread.WebAssembly.Threading.csproj;
<ProjectReference Include="$(LibrariesProjectRoot)System.Threading.WebAssembly.Threading\ref\System.Threading.WebAssembly.Threading.csproj;
$(LibrariesProjectRoot)System.Threading.Thread.WebAssembly.Threading\ref\System.Threading.Thread.WebAssembly.Threading.csproj;
$(LibrariesProjectRoot)System.Threading.ThreadPool.WebAssembly.Threading\ref\System.Threading.ThreadPool.WebAssembly.Threading.csproj;
$(LibrariesProjectRoot)System.Diagnostics.Tracing.WebAssembly.PerfTracing\ref\System.Diagnostics.Tracing.WebAssembly.PerfTracing.csproj"
Pack="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>
<PropertyGroup>
<TargetPlatformIdentifier>$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)'))</TargetPlatformIdentifier>
<FeatureWasmThreads Condition="'$(TargetPlatformIdentifier)' == 'browser' and '$(MonoWasmBuildVariant)' == 'multithread'">true</FeatureWasmThreads>
<FeatureWasmThreads Condition="'$(TargetOS)' == 'browser' and '$(MonoWasmBuildVariant)' == 'multithread'">true</FeatureWasmThreads>
<DefineConstants Condition="'$(FeatureWasmThreads)' == 'true'" >$(DefineConstants);FEATURE_WASM_THREADS</DefineConstants>
</PropertyGroup>
<!-- Compiled Source Files -->
Expand Down Expand Up @@ -157,7 +157,8 @@
<Reference Include="System.Diagnostics.Tracing" />
<Reference Include="System.Linq" />
<Reference Include="System.Runtime" />
<Reference Include="System.Threading" />
<Reference Include="System.Threading" Condition="'$(MonoWasmBuildVariant)' != 'multithread'" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Threading.WebAssembly.Threading\ref\System.Threading.WebAssembly.Threading.csproj" Condition="'$(MonoWasmBuildVariant)' == 'multithread'" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ namespace System.Linq.Parallel
/// This is a bounded channel meant for single-producer/single-consumer scenarios.
/// </summary>
/// <typeparam name="T">Specifies the type of data in the channel.</typeparam>
#if !FEATURE_WASM_THREADS
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
#endif
internal sealed class AsynchronousChannel<T> : IDisposable
{
// The producer will be blocked once the channel reaches a capacity, and unblocked
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ namespace System.Linq.Parallel
///
/// </summary>
/// <typeparam name="T"></typeparam>
#if !FEATURE_WASM_THREADS
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
#endif
internal sealed class AsynchronousChannelMergeEnumerator<T> : MergeEnumerator<T>
{
private readonly AsynchronousChannel<T>[] _channels; // The channels being enumerated.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ public IEnumerator<TInputOutput> GetEnumerator()
// An array of asynchronous channels, one for each partition.
//

#if !FEATURE_WASM_THREADS
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
#endif
internal static AsynchronousChannel<TInputOutput>[] MakeAsynchronousChannels(int partitionCount, ParallelMergeOptions options, IntValueEvent? consumerEvent, CancellationToken cancellationToken)
{
AsynchronousChannel<TInputOutput>[] channels = new AsynchronousChannel<TInputOutput>[partitionCount];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ namespace System.Linq.Parallel
/// Finally, if the producer notices that its buffer has exceeded an even greater threshold, it will
/// go to sleep and wait until the consumer takes the entire buffer.
/// </summary>
#if !FEATURE_WASM_THREADS
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
#endif
internal sealed class OrderPreservingPipeliningMergeHelper<TOutput, TKey> : IMergeHelper<TOutput>
{
private readonly QueryTaskGroupState _taskGroupState; // State shared among tasks.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

namespace System.Linq.Parallel
{
#if !FEATURE_WASM_THREADS
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
#endif
internal sealed class OrderPreservingPipeliningSpoolingTask<TOutput, TKey> : SpoolingTaskBase
{
private readonly QueryTaskGroupState _taskGroupState; // State shared among tasks.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ internal static void SpoolStopAndGo<TInputOutput, TIgnoreKey>(
// taskScheduler - the task manager on which to execute
//

#if !FEATURE_WASM_THREADS
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
#endif
internal static void SpoolPipeline<TInputOutput, TIgnoreKey>(
QueryTaskGroupState groupState, PartitionedStream<TInputOutput, TIgnoreKey> partitions,
AsynchronousChannel<TInputOutput>[] channels, TaskScheduler taskScheduler)
Expand Down Expand Up @@ -262,7 +264,9 @@ protected override void SpoolingFinally()
/// </summary>
/// <typeparam name="TInputOutput"></typeparam>
/// <typeparam name="TIgnoreKey"></typeparam>
#if !FEATURE_WASM_THREADS
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
#endif
internal sealed class PipelineSpoolingTask<TInputOutput, TIgnoreKey> : SpoolingTaskBase
{
// The data source from which to pull data.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,9 @@ private void QuickSortIndicesInPlace(GrowingArray<TKey> keys, List<TInputOutput>
// negatively impact speedups.
//

#if !FEATURE_WASM_THREADS
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
#endif
private void MergeSortCooperatively()
{
CancellationToken cancelToken = _groupState.CancellationState.MergedCancellationToken;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ public static IEnumerable<object[]> AllExecutionModes_Multiple()

// Check that some queries run in parallel by default, and some require forcing.
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/91661", typeof(PlatformDetection), nameof(PlatformDetection.IsWasmThreadingSupported))]
[MemberData(nameof(WithExecutionModeQueryData), new[] { 1, 4 })] // DOP of 1 to verify sequential and 4 to verify parallel
public static void WithExecutionMode(
Labeled<ParallelQuery<int>> labeled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,9 @@ public void Reset()
/// The caller of this method blocks indefinitely until the current instance is set. The caller will
/// return immediately if the event is currently in a set state.
/// </remarks>
#if !FEATURE_WASM_THREADS
[UnsupportedOSPlatform("browser")]
#endif
public void Wait()
{
Wait(Timeout.Infinite, CancellationToken.None);
Expand All @@ -365,7 +367,9 @@ public void Wait()
/// The caller of this method blocks indefinitely until the current instance is set. The caller will
/// return immediately if the event is currently in a set state.
/// </remarks>
#if !FEATURE_WASM_THREADS
[UnsupportedOSPlatform("browser")]
#endif
public void Wait(CancellationToken cancellationToken)
{
Wait(Timeout.Infinite, cancellationToken);
Expand All @@ -386,7 +390,9 @@ public void Wait(CancellationToken cancellationToken)
/// <exception cref="InvalidOperationException">
/// The maximum number of waiters has been exceeded.
/// </exception>
#if !FEATURE_WASM_THREADS
[UnsupportedOSPlatform("browser")]
#endif
public bool Wait(TimeSpan timeout)
{
long totalMilliseconds = (long)timeout.TotalMilliseconds;
Expand Down Expand Up @@ -417,7 +423,9 @@ public bool Wait(TimeSpan timeout)
/// <exception cref="InvalidOperationException">
/// The maximum number of waiters has been exceeded.
/// </exception>
#if !FEATURE_WASM_THREADS
[UnsupportedOSPlatform("browser")]
#endif
public bool Wait(TimeSpan timeout, CancellationToken cancellationToken)
{
long totalMilliseconds = (long)timeout.TotalMilliseconds;
Expand All @@ -441,7 +449,9 @@ public bool Wait(TimeSpan timeout, CancellationToken cancellationToken)
/// <exception cref="InvalidOperationException">
/// The maximum number of waiters has been exceeded.
/// </exception>
#if !FEATURE_WASM_THREADS
[UnsupportedOSPlatform("browser")]
#endif
public bool Wait(int millisecondsTimeout)
{
return Wait(millisecondsTimeout, CancellationToken.None);
Expand All @@ -465,7 +475,9 @@ public bool Wait(int millisecondsTimeout)
/// </exception>
/// <exception cref="OperationCanceledException"><paramref
/// name="cancellationToken"/> was canceled.</exception>
#if !FEATURE_WASM_THREADS
[UnsupportedOSPlatform("browser")]
#endif
public bool Wait(int millisecondsTimeout, CancellationToken cancellationToken)
{
ObjectDisposedException.ThrowIf(IsDisposed, this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,27 @@ public static bool TryEnter(object obj, TimeSpan timeout)
public static void TryEnter(object obj, TimeSpan timeout, ref bool lockTaken)
=> TryEnter(obj, WaitHandle.ToTimeoutMilliseconds(timeout), ref lockTaken);

#if !FEATURE_WASM_THREADS
[UnsupportedOSPlatform("browser")]
#endif
public static bool Wait(object obj, TimeSpan timeout) => Wait(obj, WaitHandle.ToTimeoutMilliseconds(timeout));

#if !FEATURE_WASM_THREADS
[UnsupportedOSPlatform("browser")]
#endif
public static bool Wait(object obj) => Wait(obj, Timeout.Infinite);

// Remoting is not supported, exitContext argument is unused
#if !FEATURE_WASM_THREADS
[UnsupportedOSPlatform("browser")]
#endif
public static bool Wait(object obj, int millisecondsTimeout, bool exitContext)
=> Wait(obj, millisecondsTimeout);

// Remoting is not supported, exitContext argument is unused
#if !FEATURE_WASM_THREADS
[UnsupportedOSPlatform("browser")]
#endif
public static bool Wait(object obj, TimeSpan timeout, bool exitContext)
=> Wait(obj, WaitHandle.ToTimeoutMilliseconds(timeout));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1213,7 +1213,6 @@ public static void RunParallelLoopCancellationTests()
/// Test to ensure that the task ID can be accessed from inside the task
/// </summary>
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/91583", typeof(PlatformDetection), nameof(PlatformDetection.IsWasmThreadingSupported))]
public static void TaskIDFromExternalContextTest()
{
int? withinTaskId = int.MinValue;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>$(NetCoreAppCurrent)</TargetFramework>
<FeatureWasmThreads>true</FeatureWasmThreads>
<AssemblyName>System.Threading</AssemblyName>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<!-- tell references.targets to bump the assembly version -->
<IsExperimentalRefAssembly>true</IsExperimentalRefAssembly>
<!-- Disable all binplacing since this assembly will clash with the real ref assembly -->
<EnableBinPlacing>false</EnableBinPlacing>
<StrongNameKeyId>Microsoft</StrongNameKeyId>
<IncludePlatformAttributes>true</IncludePlatformAttributes>
<DefineConstants Condition="'$(FeatureWasmThreads)' == 'true'">$(DefineConstants);FEATURE_WASM_THREADS</DefineConstants>
</PropertyGroup>

<ItemGroup>
<Compile Include="$(LibrariesProjectRoot)System.Threading\ref\System.Threading.cs" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\System.Runtime\ref\System.Runtime.csproj" PrivateAssets="all" />
</ItemGroup>

</Project>
50 changes: 50 additions & 0 deletions src/libraries/System.Threading/ref/System.Threading.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,41 @@ public Barrier(int participantCount, System.Action<System.Threading.Barrier>? po
public long CurrentPhaseNumber { get { throw null; } }
public int ParticipantCount { get { throw null; } }
public int ParticipantsRemaining { get { throw null; } }
#if !FEATURE_WASM_THREADS
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
#endif
public long AddParticipant() { throw null; }
#if !FEATURE_WASM_THREADS
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
#endif
public long AddParticipants(int participantCount) { throw null; }
public void Dispose() { }
protected virtual void Dispose(bool disposing) { }
public void RemoveParticipant() { }
public void RemoveParticipants(int participantCount) { }
#if !FEATURE_WASM_THREADS
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
#endif
public void SignalAndWait() { }
#if !FEATURE_WASM_THREADS
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
#endif
public bool SignalAndWait(int millisecondsTimeout) { throw null; }
#if !FEATURE_WASM_THREADS
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
#endif
public bool SignalAndWait(int millisecondsTimeout, System.Threading.CancellationToken cancellationToken) { throw null; }
#if !FEATURE_WASM_THREADS
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
#endif
public void SignalAndWait(System.Threading.CancellationToken cancellationToken) { }
#if !FEATURE_WASM_THREADS
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
#endif
public bool SignalAndWait(System.TimeSpan timeout) { throw null; }
#if !FEATURE_WASM_THREADS
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
#endif
public bool SignalAndWait(System.TimeSpan timeout, System.Threading.CancellationToken cancellationToken) { throw null; }
}
public partial class BarrierPostPhaseException : System.Exception
Expand Down Expand Up @@ -62,17 +78,29 @@ public void Reset(int count) { }
public bool Signal(int signalCount) { throw null; }
public bool TryAddCount() { throw null; }
public bool TryAddCount(int signalCount) { throw null; }
#if !FEATURE_WASM_THREADS
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
#endif
public void Wait() { }
#if !FEATURE_WASM_THREADS
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
#endif
public bool Wait(int millisecondsTimeout) { throw null; }
#if !FEATURE_WASM_THREADS
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
#endif
public bool Wait(int millisecondsTimeout, System.Threading.CancellationToken cancellationToken) { throw null; }
#if !FEATURE_WASM_THREADS
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
#endif
public void Wait(System.Threading.CancellationToken cancellationToken) { }
#if !FEATURE_WASM_THREADS
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
#endif
public bool Wait(System.TimeSpan timeout) { throw null; }
#if !FEATURE_WASM_THREADS
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
#endif
public bool Wait(System.TimeSpan timeout, System.Threading.CancellationToken cancellationToken) { throw null; }
}
public partial class HostExecutionContext : System.IDisposable
Expand Down Expand Up @@ -313,17 +341,29 @@ public void Dispose() { }
protected virtual void Dispose(bool disposing) { }
public void Reset() { }
public void Set() { }
#if !FEATURE_WASM_THREADS
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
#endif
public void Wait() { }
#if !FEATURE_WASM_THREADS
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
#endif
public bool Wait(int millisecondsTimeout) { throw null; }
#if !FEATURE_WASM_THREADS
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
#endif
public bool Wait(int millisecondsTimeout, System.Threading.CancellationToken cancellationToken) { throw null; }
#if !FEATURE_WASM_THREADS
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
#endif
public void Wait(System.Threading.CancellationToken cancellationToken) { }
#if !FEATURE_WASM_THREADS
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
#endif
public bool Wait(System.TimeSpan timeout) { throw null; }
#if !FEATURE_WASM_THREADS
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
#endif
public bool Wait(System.TimeSpan timeout, System.Threading.CancellationToken cancellationToken) { throw null; }
}
public static partial class Monitor
Expand All @@ -341,15 +381,25 @@ public static void TryEnter(object obj, ref bool lockTaken) { }
public static void TryEnter(object obj, int millisecondsTimeout, ref bool lockTaken) { }
public static bool TryEnter(object obj, System.TimeSpan timeout) { throw null; }
public static void TryEnter(object obj, System.TimeSpan timeout, ref bool lockTaken) { }
#if !FEATURE_WASM_THREADS
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
#endif
public static bool Wait(object obj) { throw null; }
#if !FEATURE_WASM_THREADS
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
#endif
public static bool Wait(object obj, int millisecondsTimeout) { throw null; }
#if !FEATURE_WASM_THREADS
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
#endif
public static bool Wait(object obj, int millisecondsTimeout, bool exitContext) { throw null; }
#if !FEATURE_WASM_THREADS
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
#endif
public static bool Wait(object obj, System.TimeSpan timeout) { throw null; }
#if !FEATURE_WASM_THREADS
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
#endif
public static bool Wait(object obj, System.TimeSpan timeout, bool exitContext) { throw null; }
}
public sealed partial class Mutex : System.Threading.WaitHandle
Expand Down
2 changes: 2 additions & 0 deletions src/libraries/System.Threading/ref/System.Threading.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>$(NetCoreAppCurrent)</TargetFramework>
<FeatureWasmThreads Condition="'$(TargetPlatformIdentifier)' == 'browser' and '$(MonoWasmBuildVariant)' == 'multithread'">true</FeatureWasmThreads>
<DefineConstants Condition="'$(FeatureWasmThreads)' == 'true'">$(DefineConstants);FEATURE_WASM_THREADS</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Compile Include="System.Threading.cs" />
Expand Down
Loading