Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[browser][MT] enable MT PLINQ #94214

Merged
merged 9 commits into from
Nov 6, 2023
Merged
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
Expand Up @@ -5,7 +5,12 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<UseCompilerGeneratedDocXmlFile>false</UseCompilerGeneratedDocXmlFile>
</PropertyGroup>

<PropertyGroup>
<TargetPlatformIdentifier>$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)'))</TargetPlatformIdentifier>
<FeatureWasmThreads Condition="'$(TargetPlatformIdentifier)' == 'browser' and '$(MonoWasmBuildVariant)' == 'multithread'">true</FeatureWasmThreads>
<DefineConstants Condition="'$(FeatureWasmThreads)' == 'true'" >$(DefineConstants);FEATURE_WASM_THREADS</DefineConstants>
</PropertyGroup>
<!-- Compiled Source Files -->
<ItemGroup>
<Compile Include="System\Linq\Parallel\Channels\AsynchronousChannel.cs" />
<Compile Include="System\Linq\Parallel\Channels\SynchronousChannel.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,12 @@ public static class ParallelEnumerable

// When running in single partition mode, PLINQ operations will occur on a single partition and will not
// be executed in parallel, but will retain PLINQ semantics (exceptions wrapped as aggregates, etc).
#if !FEATURE_WASM_THREADS
[System.Runtime.Versioning.SupportedOSPlatformGuard("browser")]
internal static bool SinglePartitionMode => OperatingSystem.IsBrowser();
#else
internal static bool SinglePartitionMode => false;
#endif

//-----------------------------------------------------------------------------------
// Converts any IEnumerable<TSource> into something that can be the target of parallel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<UseCompilerGeneratedDocXmlFile>false</UseCompilerGeneratedDocXmlFile>
</PropertyGroup>

<PropertyGroup>
<TargetPlatformIdentifier>$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)'))</TargetPlatformIdentifier>
<FeatureWasmThreads Condition="'$(TargetPlatformIdentifier)' == 'browser' and '$(MonoWasmBuildVariant)' == 'multithread'">true</FeatureWasmThreads>
<DefineConstants Condition="'$(FeatureWasmThreads)' == 'true'" >$(DefineConstants);FEATURE_WASM_THREADS</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Compile Include="System\Threading\Tasks\Parallel.cs" />
<Compile Include="System\Threading\Tasks\Parallel.ForEachAsync.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,12 @@ public static void Invoke(ParallelOptions parallelOptions, params Action[] actio
{
// If we've gotten this far, it's time to process the actions.

#if !FEATURE_WASM_THREADS
// Web browsers need special treatment that is implemented in TaskReplicator
if (OperatingSystem.IsBrowser() ||
#else
if (
#endif
pavelsavara marked this conversation as resolved.
Show resolved Hide resolved
// This is more efficient for a large number of actions, or for enforcing MaxDegreeOfParallelism:
(actionsCopy.Length > SMALL_ACTIONCOUNT_LIMIT) ||
(parallelOptions.MaxDegreeOfParallelism != -1 && parallelOptions.MaxDegreeOfParallelism < actionsCopy.Length)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ public static void Run<TState>(ReplicatableUserAction<TState> action, ParallelOp
{
// Browser hosts do not support synchronous Wait so we want to run the
// replicated task directly instead of going through Task infrastructure
#if !FEATURE_WASM_THREADS
if (OperatingSystem.IsBrowser())
{
// Since we are running on a single thread, we don't want the action to time out
Expand All @@ -142,6 +143,7 @@ public static void Run<TState>(ReplicatableUserAction<TState> action, ParallelOp
throw new Exception("Replicated tasks cannot yield in this single-threaded browser environment");
}
else
#endif
{
int maxConcurrencyLevel = (options.EffectiveMaxConcurrencyLevel > 0) ? options.EffectiveMaxConcurrencyLevel : int.MaxValue;

Expand Down
Loading
Loading