From 9365ea574df07ce9b2613e330a401b12cb96d5f2 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz <32700855+ilonatommy@users.noreply.github.com> Date: Fri, 26 Jan 2024 15:33:56 +0000 Subject: [PATCH 01/18] Unification --- .../runtime-extra-platforms-wasm.yml | 6 +++--- eng/pipelines/runtime-official.yml | 2 +- eng/pipelines/runtime.yml | 4 ++-- eng/testing/tests.browser.targets | 8 ++++---- eng/testing/workloads-browser.targets | 16 ++++++++-------- .../Microsoft.NETCore.App.Runtime.props | 4 ++-- .../src/System.Diagnostics.Tracing.csproj | 2 +- .../src/System.Linq.Parallel.csproj | 6 +++--- .../System.Net.Http/src/System.Net.Http.csproj | 2 +- .../src/System.Net.WebSockets.Client.csproj | 2 +- .../ref/System.Private.CoreLib.csproj | 4 ++-- ...tem.Runtime.InteropServices.JavaScript.csproj | 4 ++-- ...ntime.InteropServices.JavaScript.Tests.csproj | 2 +- .../src/System.Threading.Tasks.Parallel.csproj | 2 +- .../ref/System.Threading.Thread.csproj | 2 +- .../src/System.Threading.Thread.csproj | 2 +- .../src/System.Threading.ThreadPool.csproj | 2 +- .../System.Threading/ref/System.Threading.csproj | 2 +- .../System.Threading/src/System.Threading.csproj | 4 ++-- src/libraries/tests.proj | 8 ++++---- .../System.Private.CoreLib.csproj | 6 +++--- src/mono/browser/browser.proj | 2 +- src/mono/browser/build/BrowserWasmApp.targets | 4 ++-- .../Wasm.Debugger.Tests.csproj | 2 +- src/mono/mono.proj | 6 +++--- src/mono/sample/wasm/browser-eventpipe/README.md | 6 +++--- src/mono/sample/wasm/browser-eventpipe/main.js | 2 +- src/mono/wasm/threads.md | 2 +- src/native/libs/build-native.proj | 4 ++-- 29 files changed, 59 insertions(+), 59 deletions(-) diff --git a/eng/pipelines/extra-platforms/runtime-extra-platforms-wasm.yml b/eng/pipelines/extra-platforms/runtime-extra-platforms-wasm.yml index 5e6237c9880e59..4c3994a03be1b6 100644 --- a/eng/pipelines/extra-platforms/runtime-extra-platforms-wasm.yml +++ b/eng/pipelines/extra-platforms/runtime-extra-platforms-wasm.yml @@ -124,7 +124,7 @@ jobs: - browser_wasm #- browser_wasm_win nameSuffix: _Threading - extraBuildArgs: /p:MonoWasmBuildVariant=multithread /p:WasmEnableThreads=true /p:AotHostArchitecture=x64 /p:AotHostOS=$(_hostedOS) + extraBuildArgs: /p:WasmEnableThreads=true /p:AotHostArchitecture=x64 /p:AotHostOS=$(_hostedOS) isExtraPlatformsBuild: ${{ parameters.isExtraPlatformsBuild }} isWasmOnlyBuild: ${{ parameters.isWasmOnlyBuild }} # Always run for runtime-wasm because tests are not run in runtime @@ -255,7 +255,7 @@ jobs: - browser_wasm - browser_wasm_win nameSuffix: MultiThreaded - extraBuildArgs: /p:MonoWasmBuildVariant=multithread /p:WasmEnableThreads=true /p:AotHostArchitecture=x64 /p:AotHostOS=$(_hostedOS) + extraBuildArgs: /p:WasmEnableThreads=true /p:AotHostArchitecture=x64 /p:AotHostOS=$(_hostedOS) condition: ne(variables['wasmMultiThreadedBuildOnlyNeededOnDefaultPipeline'], true) publishArtifactsForWorkload: true publishWBT: false @@ -313,7 +313,7 @@ jobs: platforms: - Browser_wasm - Browser_wasm_win - extraBuildArgs: /p:MonoWasmBuildVariant=multithread /p:WasmEnableThreads=true /p:AotHostArchitecture=x64 /p:AotHostOS=$(_hostedOS) + extraBuildArgs: /p:WasmEnableThreads=true /p:AotHostArchitecture=x64 /p:AotHostOS=$(_hostedOS) nameSuffix: DebuggerTests_MultiThreaded alwaysRun: ${{ parameters.isWasmOnlyBuild }} isExtraPlatformsBuild: ${{ parameters.isExtraPlatformsBuild }} diff --git a/eng/pipelines/runtime-official.yml b/eng/pipelines/runtime-official.yml index 618bf2b3f99530..d8ad9c571806af 100644 --- a/eng/pipelines/runtime-official.yml +++ b/eng/pipelines/runtime-official.yml @@ -394,7 +394,7 @@ extends: platforms: - browser_wasm jobParameters: - buildArgs: -s mono+libs+host+packs -c $(_BuildConfig) /p:MonoWasmBuildVariant=multithread /p:AotHostArchitecture=x64 /p:AotHostOS=$(_hostedOS) + buildArgs: -s mono+libs+host+packs -c $(_BuildConfig) /p:WasmEnableThreads=true /p:AotHostArchitecture=x64 /p:AotHostOS=$(_hostedOS) nameSuffix: Mono_multithread isOfficialBuild: ${{ variables.isOfficialBuild }} runtimeVariant: multithread diff --git a/eng/pipelines/runtime.yml b/eng/pipelines/runtime.yml index 8ad2dd191483c9..58742f3e645bf2 100644 --- a/eng/pipelines/runtime.yml +++ b/eng/pipelines/runtime.yml @@ -565,7 +565,7 @@ extends: - browser_wasm_win condition: or(eq(variables.isRollingBuild, true), eq(variables.wasmSingleThreadedBuildOnlyNeededOnDefaultPipeline, true)) nameSuffix: MultiThreaded - extraBuildArgs: /p:MonoWasmBuildVariant=multithread /p:WasmEnableThreads=true /p:AotHostArchitecture=x64 /p:AotHostOS=$(_hostedOS) + extraBuildArgs: /p:WasmEnableThreads=true /p:AotHostArchitecture=x64 /p:AotHostOS=$(_hostedOS) publishArtifactsForWorkload: true publishWBT: false @@ -601,7 +601,7 @@ extends: platforms: - browser_wasm nameSuffix: _Threading_Smoke - extraBuildArgs: /p:MonoWasmBuildVariant=multithread /p:AotHostArchitecture=x64 /p:AotHostOS=$(_hostedOS) + extraBuildArgs: /p:AotHostArchitecture=x64 /p:AotHostOS=$(_hostedOS) shouldRunSmokeOnly: true alwaysRun: ${{ variables.isRollingBuild }} scenarios: diff --git a/eng/testing/tests.browser.targets b/eng/testing/tests.browser.targets index d856a41784e679..6a1a2e29d52864 100644 --- a/eng/testing/tests.browser.targets +++ b/eng/testing/tests.browser.targets @@ -87,15 +87,15 @@ <_AppArgs Condition="'$(IsFunctionalTest)' != 'true' and '$(WasmMainAssemblyFileName)' != ''">--run $(WasmMainAssemblyFileName) <_AppArgs Condition="'$(IsFunctionalTest)' == 'true'">--run $(AssemblyName).dll - <_XUnitBackgroundExec Condition="'$(_XUnitBackgroundExec)' == '' and '$(MonoWasmBuildVariant)' == 'multithread'">true + <_XUnitBackgroundExec Condition="'$(_XUnitBackgroundExec)' == '' and '$(WasmEnableThreads)' == 'true'">true $(WasmTestAppArgs) -backgroundExec <_AppArgs Condition="'$(WasmTestAppArgs)' != ''">$(_AppArgs) $(WasmTestAppArgs) $(WasmXHarnessMonoArgs) --setenv=XHARNESS_LOG_TEST_START=1 - $(WasmXHarnessMonoArgs) --no-memory-snapshot + $(WasmXHarnessMonoArgs) --no-memory-snapshot - $(WasmXHarnessMonoArgs) --setenv=IsBrowserThreadingSupported=true + $(WasmXHarnessMonoArgs) --setenv=IsBrowserThreadingSupported=true @@ -104,7 +104,7 @@ <_XHarnessArgs Condition="'$(IsFunctionalTest)' == 'true'" >$(_XHarnessArgs) --expected-exit-code=$(ExpectedExitCode) <_XHarnessArgs Condition="'$(WasmXHarnessArgs)' != ''" >$(_XHarnessArgs) $(WasmXHarnessArgs) - <_XHarnessArgs Condition="'$(MonoWasmBuildVariant)' == 'multithread' and '$(_XHarnessArs.Contains("--web-server-use-cop")' != 'true'">$(_XHarnessArgs) --web-server-use-cop + <_XHarnessArgs Condition="'$(WasmEnableThreads)' == 'true' and '$(_XHarnessArs.Contains("--web-server-use-cop")' != 'true'">$(_XHarnessArgs) --web-server-use-cop <_XHarnessArgs >$(_XHarnessArgs) -s dotnet.native.js.symbols <_XHarnessArgs Condition="'$(_UseWasmSymbolicator)' == 'true'" >$(_XHarnessArgs) --symbol-patterns wasm-symbol-patterns.txt <_XHarnessArgs Condition="'$(_UseWasmSymbolicator)' == 'true'" >$(_XHarnessArgs) --symbolicator WasmSymbolicator.dll,Microsoft.WebAssembly.Internal.SymbolicatorWrapperForXHarness diff --git a/eng/testing/workloads-browser.targets b/eng/testing/workloads-browser.targets index 270267385bab11..3bfffc17a790da 100644 --- a/eng/testing/workloads-browser.targets +++ b/eng/testing/workloads-browser.targets @@ -47,7 +47,8 @@ - <_DefaultBuildVariant Condition="'$(MonoWasmBuildVariant)' == 'multithread'">.multithread. + <_BuildVariant Condition="'$(WasmEnableThreads)' == 'true'">multithread" + <_DefaultBuildVariant Condition="'$(WasmEnableThreads)' == 'true'">.multithread. <_DefaultBuildVariant Condition="'$(_DefaultBuildVariant)' == ''">. <_DefaultRuntimePackNuGetPath>$(LibrariesShippingPackagesDir)Microsoft.NETCore.App.Runtime.Mono$(_DefaultBuildVariant)$(RIDForWorkload).$(PackageVersionForWorkloadManifests).nupkg @@ -63,22 +64,21 @@ Text="Expected to find either one or two in $(LibrariesShippingPackagesDir): @(_RuntimePackNugetAvailable->'%(FileName)%(Extension)')" /> - <_BuildVariants Include="multithread" Condition="'$(_DefaultBuildVariant)' != '.multithread.'" /> - <_NuGetsToBuild Include="$(LibrariesShippingPackagesDir)Microsoft.NETCore.App.Runtime.Mono.%(_BuildVariants.Identity).$(RIDForWorkload).$(PackageVersionForWorkloadManifests).nupkg" + <_NuGetsToBuild Include="$(LibrariesShippingPackagesDir)Microsoft.NETCore.App.Runtime.Mono.$(_BuildVariant).$(RIDForWorkload).$(PackageVersionForWorkloadManifests).nupkg" Project="$(InstallerProjectRoot)pkg/sfx/Microsoft.NETCore.App/Microsoft.NETCore.App.Runtime.sfxproj" Dependencies="$(_DefaultRuntimePackNuGetPath)" - Properties="@(_DefaultPropsForNuGetBuild, ';');MonoWasmBuildVariant=%(_BuildVariants.Identity)" - Descriptor="runtime pack for %(_BuildVariants.Identity)" - Condition="'%(_BuildVariants.Identity)' != ''"/> + Properties="@(_DefaultPropsForNuGetBuild, ';');WasmEnableThreads=$(WasmEnableThreads)" + Descriptor="runtime pack for $(_BuildVariant)" + Condition="'$(WasmEnableThreads)' == 'true'"/> <_NuGetsToBuild Include="$(LibrariesShippingPackagesDir)Microsoft.NETCore.App.Runtime.Mono.$(RIDForWorkload).$(PackageVersionForWorkloadManifests).nupkg" Project="$(InstallerProjectRoot)pkg/sfx/Microsoft.NETCore.App/Microsoft.NETCore.App.Runtime.sfxproj" - Properties="@(_DefaultPropsForNuGetBuild, ';');MonoWasmBuildVariant=" + Properties="@(_DefaultPropsForNuGetBuild, ';');" Dependencies="$(_DefaultRuntimePackNuGetPath)" Descriptor="single threaded runtime pack" - Condition="'$(_DefaultBuildVariant)' != '.'" /> + Condition='$(WasmEnableThreads)' != 'true' /> Mono.LLVM.AOT - - Mono.$(MonoWasmBuildVariant) + + Mono.multithread $(SharedFrameworkName).Runtime.$(RuntimeSpecificFrameworkSuffix).$(RuntimeIdentifier) diff --git a/src/libraries/System.Diagnostics.Tracing/src/System.Diagnostics.Tracing.csproj b/src/libraries/System.Diagnostics.Tracing/src/System.Diagnostics.Tracing.csproj index 6af0cb0108f3c4..8a0c4aad6f08e2 100644 --- a/src/libraries/System.Diagnostics.Tracing/src/System.Diagnostics.Tracing.csproj +++ b/src/libraries/System.Diagnostics.Tracing/src/System.Diagnostics.Tracing.csproj @@ -6,7 +6,7 @@ false - + diff --git a/src/libraries/System.Linq.Parallel/src/System.Linq.Parallel.csproj b/src/libraries/System.Linq.Parallel/src/System.Linq.Parallel.csproj index 1c349dd76cadb9..2e4c8ccb5a0cee 100644 --- a/src/libraries/System.Linq.Parallel/src/System.Linq.Parallel.csproj +++ b/src/libraries/System.Linq.Parallel/src/System.Linq.Parallel.csproj @@ -7,7 +7,7 @@ $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) - true + true $(DefineConstants);FEATURE_WASM_THREADS @@ -157,8 +157,8 @@ - - + + diff --git a/src/libraries/System.Net.Http/src/System.Net.Http.csproj b/src/libraries/System.Net.Http/src/System.Net.Http.csproj index 54991bd5a4d331..8096caadb6f75e 100644 --- a/src/libraries/System.Net.Http/src/System.Net.Http.csproj +++ b/src/libraries/System.Net.Http/src/System.Net.Http.csproj @@ -11,7 +11,7 @@ $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) SR.PlatformNotSupported_NetHttp - true + true $(DefineConstants);SYSNETHTTP_NO_OPENSSL $(DefineConstants);TARGET_MOBILE $(DefineConstants);TARGET_ANDROID diff --git a/src/libraries/System.Net.WebSockets.Client/src/System.Net.WebSockets.Client.csproj b/src/libraries/System.Net.WebSockets.Client/src/System.Net.WebSockets.Client.csproj index 294a9bceb4f12e..a595540c1eddbb 100644 --- a/src/libraries/System.Net.WebSockets.Client/src/System.Net.WebSockets.Client.csproj +++ b/src/libraries/System.Net.WebSockets.Client/src/System.Net.WebSockets.Client.csproj @@ -9,7 +9,7 @@ $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) - true + true $(DefineConstants);TARGET_BROWSER $(DefineConstants);FEATURE_WASM_THREADS true diff --git a/src/libraries/System.Private.CoreLib/ref/System.Private.CoreLib.csproj b/src/libraries/System.Private.CoreLib/ref/System.Private.CoreLib.csproj index 7e0202c10b9d73..c8ebd686e4e39b 100644 --- a/src/libraries/System.Private.CoreLib/ref/System.Private.CoreLib.csproj +++ b/src/libraries/System.Private.CoreLib/ref/System.Private.CoreLib.csproj @@ -10,8 +10,8 @@ $(NoWarn);0809;0618;CS8614;CS3015 SilverlightPlatform true - true - true + true + true $(DefineConstants);FEATURE_WASM_PERFTRACING $(DefineConstants);FEATURE_WASM_THREADS $(DefineConstants);BUILDING_CORELIB_REFERENCE diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System.Runtime.InteropServices.JavaScript.csproj b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System.Runtime.InteropServices.JavaScript.csproj index 4a7f303685ba59..9173921e3607e1 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System.Runtime.InteropServices.JavaScript.csproj +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System.Runtime.InteropServices.JavaScript.csproj @@ -11,7 +11,7 @@ $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) SR.SystemRuntimeInteropServicesJavaScript_PlatformNotSupported - true + true true false $(DefineConstants);FEATURE_WASM_THREADS @@ -69,7 +69,7 @@ - + diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System.Runtime.InteropServices.JavaScript.Tests.csproj b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System.Runtime.InteropServices.JavaScript.Tests.csproj index 90b2454d6e375f..e4234ce46187a2 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System.Runtime.InteropServices.JavaScript.Tests.csproj +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System.Runtime.InteropServices.JavaScript.Tests.csproj @@ -8,7 +8,7 @@ $(WasmXHarnessArgs) --engine-arg=--expose-gc --web-server-use-cop true true - true + true $(DefineConstants);FEATURE_WASM_THREADS true diff --git a/src/libraries/System.Threading.Tasks.Parallel/src/System.Threading.Tasks.Parallel.csproj b/src/libraries/System.Threading.Tasks.Parallel/src/System.Threading.Tasks.Parallel.csproj index ed9222b0224fb1..69087539429674 100644 --- a/src/libraries/System.Threading.Tasks.Parallel/src/System.Threading.Tasks.Parallel.csproj +++ b/src/libraries/System.Threading.Tasks.Parallel/src/System.Threading.Tasks.Parallel.csproj @@ -7,7 +7,7 @@ $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) - true + true $(DefineConstants);FEATURE_WASM_THREADS diff --git a/src/libraries/System.Threading.Thread/ref/System.Threading.Thread.csproj b/src/libraries/System.Threading.Thread/ref/System.Threading.Thread.csproj index d5723a09d9b9f1..7062d967dc466a 100644 --- a/src/libraries/System.Threading.Thread/ref/System.Threading.Thread.csproj +++ b/src/libraries/System.Threading.Thread/ref/System.Threading.Thread.csproj @@ -1,7 +1,7 @@ $(NetCoreAppCurrent) - true + true $(DefineConstants);FEATURE_WASM_THREADS diff --git a/src/libraries/System.Threading.Thread/src/System.Threading.Thread.csproj b/src/libraries/System.Threading.Thread/src/System.Threading.Thread.csproj index 5c984561dcba96..49050cfbf62e80 100644 --- a/src/libraries/System.Threading.Thread/src/System.Threading.Thread.csproj +++ b/src/libraries/System.Threading.Thread/src/System.Threading.Thread.csproj @@ -6,7 +6,7 @@ false - + diff --git a/src/libraries/System.Threading.ThreadPool/src/System.Threading.ThreadPool.csproj b/src/libraries/System.Threading.ThreadPool/src/System.Threading.ThreadPool.csproj index f169f57631d941..d2b6942f141a9e 100644 --- a/src/libraries/System.Threading.ThreadPool/src/System.Threading.ThreadPool.csproj +++ b/src/libraries/System.Threading.ThreadPool/src/System.Threading.ThreadPool.csproj @@ -6,7 +6,7 @@ false - + diff --git a/src/libraries/System.Threading/ref/System.Threading.csproj b/src/libraries/System.Threading/ref/System.Threading.csproj index 7a2cbac20a48ef..78865c1b511663 100644 --- a/src/libraries/System.Threading/ref/System.Threading.csproj +++ b/src/libraries/System.Threading/ref/System.Threading.csproj @@ -1,7 +1,7 @@ $(NetCoreAppCurrent) - true + true $(DefineConstants);FEATURE_WASM_THREADS diff --git a/src/libraries/System.Threading/src/System.Threading.csproj b/src/libraries/System.Threading/src/System.Threading.csproj index 9dd69f0835fb4d..16c23cee899d4a 100644 --- a/src/libraries/System.Threading/src/System.Threading.csproj +++ b/src/libraries/System.Threading/src/System.Threading.csproj @@ -6,7 +6,7 @@ true true false - true + true $(DefineConstants);FEATURE_WASM_THREADS @@ -25,7 +25,7 @@ - + diff --git a/src/libraries/tests.proj b/src/libraries/tests.proj index ec3fc45ea75028..dec0e95d098e40 100644 --- a/src/libraries/tests.proj +++ b/src/libraries/tests.proj @@ -57,12 +57,12 @@ - + - + @@ -398,7 +398,7 @@ - + @@ -603,7 +603,7 @@ - + diff --git a/src/mono/System.Private.CoreLib/System.Private.CoreLib.csproj b/src/mono/System.Private.CoreLib/System.Private.CoreLib.csproj index 4a76a29fce6323..2a59776edc57e2 100644 --- a/src/mono/System.Private.CoreLib/System.Private.CoreLib.csproj +++ b/src/mono/System.Private.CoreLib/System.Private.CoreLib.csproj @@ -13,7 +13,7 @@ x64;x86;arm;armv6;arm64;riscv64;s390x;wasm;ppc64le true - true + true $(DefineConstants);FEATURE_WASM_THREADS @@ -122,8 +122,8 @@ $(DefineConstants);MONO_FEATURE_SRE true - true - true + true + true true true true diff --git a/src/mono/browser/browser.proj b/src/mono/browser/browser.proj index 3d8cc6b3306c98..d9055543a2344f 100644 --- a/src/mono/browser/browser.proj +++ b/src/mono/browser/browser.proj @@ -16,7 +16,7 @@ - true + true false true diff --git a/src/mono/browser/build/BrowserWasmApp.targets b/src/mono/browser/build/BrowserWasmApp.targets index 7655c5baa55d61..c3ebddf5619d6b 100644 --- a/src/mono/browser/build/BrowserWasmApp.targets +++ b/src/mono/browser/build/BrowserWasmApp.targets @@ -28,7 +28,7 @@ _WasmGenerateRunV8Script; - true + true false @@ -120,7 +120,7 @@ Condition="'$(WasmGenerateAppBundle)' == 'true'"> - <_WasmAppIncludeThreadsWorker Condition="'$(WasmEnableThreads)' == 'true' or '$(MonoWasmBuildVariant)' == 'multithread'">true + <_WasmAppIncludeThreadsWorker Condition="'$(WasmEnableThreads)' == 'true' or '$(WasmEnableThreads)' == 'true'">true <_WasmPThreadPoolSize Condition="'$(_WasmPThreadPoolSize)' == ''">-1 diff --git a/src/mono/browser/debugger/Wasm.Debugger.Tests/Wasm.Debugger.Tests.csproj b/src/mono/browser/debugger/Wasm.Debugger.Tests/Wasm.Debugger.Tests.csproj index 6c2ce61fee7c0a..a06a731fc7be9d 100644 --- a/src/mono/browser/debugger/Wasm.Debugger.Tests/Wasm.Debugger.Tests.csproj +++ b/src/mono/browser/debugger/Wasm.Debugger.Tests/Wasm.Debugger.Tests.csproj @@ -70,7 +70,7 @@ <_DotnetCommand Condition="'$(OS)' == 'Windows_NT'">dotnet.exe $(_DotnetCommand) test DebuggerTestSuite/DebuggerTestSuite.dll - $(RunScriptCommand) /e:WASM_TESTS_USING_VARIANT=multithreaded + $(RunScriptCommand) /e:WASM_TESTS_USING_VARIANT=multithreaded $(RunScriptCommand) "-l:trx%3BLogFileName=testResults.trx" $(RunScriptCommand) "-l:console%3BVerbosity=normal" diff --git a/src/mono/mono.proj b/src/mono/mono.proj index 022da2f21f010c..86e9c2d168468d 100644 --- a/src/mono/mono.proj +++ b/src/mono/mono.proj @@ -51,8 +51,8 @@ <_CompilerTargetArch Condition="'$(AotHostArchitecture)' != ''">$(AotHostArchitecture) $([MSBuild]::NormalizeDirectory('$(RepositoryEngineeringDir)', 'common')) $([MSBuild]::NormalizePath('$(RepositoryEngineeringCommonDir)', 'cross', 'toolchain.cmake')) - false - true + false + true $(runtimelinuxx64MicrosoftNETCoreRuntimeMonoLLVMSdkVersion.Substring(0, $(runtimelinuxx64MicrosoftNETCoreRuntimeMonoLLVMSdkVersion.IndexOf('.')))) true @@ -60,7 +60,7 @@ coop - coop + coop preemptive diff --git a/src/mono/sample/wasm/browser-eventpipe/README.md b/src/mono/sample/wasm/browser-eventpipe/README.md index bbbf5d872a8344..37e906ce9e3cda 100644 --- a/src/mono/sample/wasm/browser-eventpipe/README.md +++ b/src/mono/sample/wasm/browser-eventpipe/README.md @@ -1,10 +1,10 @@ [see also](../../../wasm/runtime/diagnostics/README.md) -To be able to run this sample you need to build the runtime with `/p:MonoWasmBuildVariant=multithread` and use Chrome browser +To be able to run this sample you need to build the runtime with `/p:WasmEnableThreads=true` and use Chrome browser # Testing with mock -Build the runtime with `/p:MonoWasmBuildVariant=multithread /p:MonoDiagnosticsMock=true` +Build the runtime with `/p:WasmEnableThreads=true /p:MonoDiagnosticsMock=true` Run this test with `/p:MonoDiagnosticsMock=true` It will inject file [mock.js](./mock.js) into the worker thread, which is mocking the `dotnet trace` tool. @@ -17,7 +17,7 @@ dotnet trace convert --format Speedscope c:\Downloads\trace.1665653486202.nettra # Testing with dotnet trace tool -Build the runtime with `/p:MonoWasmBuildVariant=multithread` +Build the runtime with `/p:WasmEnableThreads=true` Build a version of dsrouter with WebSockets support (versions from upstream that target net6.0 or later have the requisite support, see https://github.com/dotnet/diagnostics/blob/main/src/Tools/dotnet-dsrouter/dotnet-dsrouter.csproj) In console #1 start dsrouter diff --git a/src/mono/sample/wasm/browser-eventpipe/main.js b/src/mono/sample/wasm/browser-eventpipe/main.js index e4f4c949b09c45..c12072d7248751 100644 --- a/src/mono/sample/wasm/browser-eventpipe/main.js +++ b/src/mono/sample/wasm/browser-eventpipe/main.js @@ -67,7 +67,7 @@ async function main() { btn.onclick = () => doWork(exports.Sample.Test.StartAsyncWork, exports.Sample.Test.StopWork, exports.Sample.Test.GetIterationsDone); if (INTERNAL.diagnosticServerThread === undefined) { - console.warn("please recompile runtime with /p:MonoWasmBuildVariant=multithread /p:MonoDiagnosticsMock=true" + event.type) + console.warn("please recompile runtime with /p:WasmEnableThreads=true /p:MonoDiagnosticsMock=true" + event.type) return; } diff --git a/src/mono/wasm/threads.md b/src/mono/wasm/threads.md index d5fc9e5e63f4af..ebf1fe68c0b341 100644 --- a/src/mono/wasm/threads.md +++ b/src/mono/wasm/threads.md @@ -2,7 +2,7 @@ ## Building the runtime ## -Build the runtime with `/p:MonoWasmBuildVariant=multithread` to enable support for multi-threading. +Build the runtime with `/p:WasmEnableThreads=true` to enable support for multi-threading. ## Building sample apps ## diff --git a/src/native/libs/build-native.proj b/src/native/libs/build-native.proj index bbf272365a8993..aec082e1c0a534 100644 --- a/src/native/libs/build-native.proj +++ b/src/native/libs/build-native.proj @@ -12,9 +12,9 @@ <_BuildNativeArgs Condition="'$(OfficialBuildId)' != ''">$(_BuildNativeArgs) /p:OfficialBuildId="$(OfficialBuildId)" <_RuntimeVariant /> - <_RuntimeVariant Condition="'$(MonoWasmBuildVariant)' == 'multithread'">-threads + <_RuntimeVariant Condition="'$(WasmEnableThreads)' == 'true'">-threads <_UsePThreads /> - <_UsePThreads Condition="'$(MonoWasmBuildVariant)' == 'multithread'"> usepthreads + <_UsePThreads Condition="'$(WasmEnableThreads)' == 'true'"> usepthreads <_IcuDir Condition="'$(TargetsAppleMobile)' != 'true' and '$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)' != ''">$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)/runtimes/$(TargetOS)-$(TargetArchitecture)$(_RuntimeVariant)/native <_IcuDirArg Condition="'$(_IcuDir)' != ''"> icudir "$(_IcuDir)" From d721d58cf7d3d04d65c866097ff4778108860f1e Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz <32700855+ilonatommy@users.noreply.github.com> Date: Fri, 26 Jan 2024 16:01:03 +0000 Subject: [PATCH 02/18] Typo: remove quotation. --- eng/testing/workloads-browser.targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/testing/workloads-browser.targets b/eng/testing/workloads-browser.targets index 3bfffc17a790da..885caade0728e9 100644 --- a/eng/testing/workloads-browser.targets +++ b/eng/testing/workloads-browser.targets @@ -47,7 +47,7 @@ - <_BuildVariant Condition="'$(WasmEnableThreads)' == 'true'">multithread" + <_BuildVariant Condition="'$(WasmEnableThreads)' == 'true'">multithread <_DefaultBuildVariant Condition="'$(WasmEnableThreads)' == 'true'">.multithread. <_DefaultBuildVariant Condition="'$(_DefaultBuildVariant)' == ''">. From 526601a5b6ecf45fbb6030ccfda89710d6c76e56 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz <32700855+ilonatommy@users.noreply.github.com> Date: Fri, 26 Jan 2024 16:15:12 +0000 Subject: [PATCH 03/18] Simplify more using the fact that `RIDForWorkload` cannot be empty. --- eng/testing/workloads-browser.targets | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/eng/testing/workloads-browser.targets b/eng/testing/workloads-browser.targets index 885caade0728e9..0f256f994a7ec4 100644 --- a/eng/testing/workloads-browser.targets +++ b/eng/testing/workloads-browser.targets @@ -47,11 +47,8 @@ - <_BuildVariant Condition="'$(WasmEnableThreads)' == 'true'">multithread - <_DefaultBuildVariant Condition="'$(WasmEnableThreads)' == 'true'">.multithread. - <_DefaultBuildVariant Condition="'$(_DefaultBuildVariant)' == ''">. - - <_DefaultRuntimePackNuGetPath>$(LibrariesShippingPackagesDir)Microsoft.NETCore.App.Runtime.Mono$(_DefaultBuildVariant)$(RIDForWorkload).$(PackageVersionForWorkloadManifests).nupkg + <_BuildVariant Condition="'$(WasmEnableThreads)' == 'true'">multithread. + <_DefaultRuntimePackNuGetPath>$(LibrariesShippingPackagesDir)Microsoft.NETCore.App.Runtime.Mono.$(_BuildVariant)$(RIDForWorkload).$(PackageVersionForWorkloadManifests).nupkg @@ -64,8 +61,7 @@ Text="Expected to find either one or two in $(LibrariesShippingPackagesDir): @(_RuntimePackNugetAvailable->'%(FileName)%(Extension)')" /> - - <_NuGetsToBuild Include="$(LibrariesShippingPackagesDir)Microsoft.NETCore.App.Runtime.Mono.$(_BuildVariant).$(RIDForWorkload).$(PackageVersionForWorkloadManifests).nupkg" + <_NuGetsToBuild Include="$(LibrariesShippingPackagesDir)Microsoft.NETCore.App.Runtime.Mono.$(_BuildVariant)$(RIDForWorkload).$(PackageVersionForWorkloadManifests).nupkg" Project="$(InstallerProjectRoot)pkg/sfx/Microsoft.NETCore.App/Microsoft.NETCore.App.Runtime.sfxproj" Dependencies="$(_DefaultRuntimePackNuGetPath)" Properties="@(_DefaultPropsForNuGetBuild, ';');WasmEnableThreads=$(WasmEnableThreads)" From 2effef78e478b3b4ceed56b79d71b4dcde90e920 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz <32700855+ilonatommy@users.noreply.github.com> Date: Fri, 26 Jan 2024 17:31:11 +0000 Subject: [PATCH 04/18] Quotation typo --- eng/testing/workloads-browser.targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/testing/workloads-browser.targets b/eng/testing/workloads-browser.targets index 0f256f994a7ec4..6eec652e3a9949 100644 --- a/eng/testing/workloads-browser.targets +++ b/eng/testing/workloads-browser.targets @@ -74,7 +74,7 @@ Properties="@(_DefaultPropsForNuGetBuild, ';');" Dependencies="$(_DefaultRuntimePackNuGetPath)" Descriptor="single threaded runtime pack" - Condition='$(WasmEnableThreads)' != 'true' /> + Condition="'$(WasmEnableThreads)' != 'true'" /> Date: Wed, 31 Jan 2024 07:43:51 +0000 Subject: [PATCH 05/18] Feedback --- eng/pipelines/runtime.yml | 2 +- eng/testing/workloads-browser.targets | 22 +++++++++---------- src/mono/browser/build/BrowserWasmApp.targets | 3 +-- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/eng/pipelines/runtime.yml b/eng/pipelines/runtime.yml index 58742f3e645bf2..edc433eacc9464 100644 --- a/eng/pipelines/runtime.yml +++ b/eng/pipelines/runtime.yml @@ -601,7 +601,7 @@ extends: platforms: - browser_wasm nameSuffix: _Threading_Smoke - extraBuildArgs: /p:AotHostArchitecture=x64 /p:AotHostOS=$(_hostedOS) + extraBuildArgs: /p:WasmEnableThreads=true /p:AotHostArchitecture=x64 /p:AotHostOS=$(_hostedOS) shouldRunSmokeOnly: true alwaysRun: ${{ variables.isRollingBuild }} scenarios: diff --git a/eng/testing/workloads-browser.targets b/eng/testing/workloads-browser.targets index 6eec652e3a9949..e8298cad72b413 100644 --- a/eng/testing/workloads-browser.targets +++ b/eng/testing/workloads-browser.targets @@ -47,8 +47,14 @@ - <_BuildVariant Condition="'$(WasmEnableThreads)' == 'true'">multithread. - <_DefaultRuntimePackNuGetPath>$(LibrariesShippingPackagesDir)Microsoft.NETCore.App.Runtime.Mono.$(_BuildVariant)$(RIDForWorkload).$(PackageVersionForWorkloadManifests).nupkg + <_BuildVariant Condition="'$(WasmEnableThreads)' == 'true'">multithread + <_Descriptor Condition="'$(WasmEnableThreads)' == 'true'">runtime pack for $(_BuildVariant) + <_Descriptor Condition="'$(WasmEnableThreads)' != 'true'">single threaded runtime pack + <_DefaultRuntimePackNuGetPath>$([System.String]::Join('.', + $(LibrariesShippingPackagesDir)Microsoft.NETCore.App.Runtime.Mono, + $(_BuildVariant), + $(RIDForWorkload).$(PackageVersionForWorkloadManifests).nupkg)) + @@ -61,20 +67,12 @@ Text="Expected to find either one or two in $(LibrariesShippingPackagesDir): @(_RuntimePackNugetAvailable->'%(FileName)%(Extension)')" /> - <_NuGetsToBuild Include="$(LibrariesShippingPackagesDir)Microsoft.NETCore.App.Runtime.Mono.$(_BuildVariant)$(RIDForWorkload).$(PackageVersionForWorkloadManifests).nupkg" + <_NuGetsToBuild Include="$(_DefaultRuntimePackNuGetPath)" Project="$(InstallerProjectRoot)pkg/sfx/Microsoft.NETCore.App/Microsoft.NETCore.App.Runtime.sfxproj" Dependencies="$(_DefaultRuntimePackNuGetPath)" Properties="@(_DefaultPropsForNuGetBuild, ';');WasmEnableThreads=$(WasmEnableThreads)" - Descriptor="runtime pack for $(_BuildVariant)" + Descriptor="$(_Descriptor)" Condition="'$(WasmEnableThreads)' == 'true'"/> - - - <_NuGetsToBuild Include="$(LibrariesShippingPackagesDir)Microsoft.NETCore.App.Runtime.Mono.$(RIDForWorkload).$(PackageVersionForWorkloadManifests).nupkg" - Project="$(InstallerProjectRoot)pkg/sfx/Microsoft.NETCore.App/Microsoft.NETCore.App.Runtime.sfxproj" - Properties="@(_DefaultPropsForNuGetBuild, ';');" - Dependencies="$(_DefaultRuntimePackNuGetPath)" - Descriptor="single threaded runtime pack" - Condition="'$(WasmEnableThreads)' != 'true'" /> - <_WasmAppIncludeThreadsWorker Condition="'$(WasmEnableThreads)' == 'true' or '$(WasmEnableThreads)' == 'true'">true <_WasmPThreadPoolSize Condition="'$(_WasmPThreadPoolSize)' == ''">-1 @@ -148,7 +147,7 @@ ExtraConfig="@(WasmExtraConfig)" NativeAssets="@(WasmNativeAsset)" DebugLevel="$(WasmDebugLevel)" - IncludeThreadsWorker="$(_WasmAppIncludeThreadsWorker)" + IncludeThreadsWorker="$(WasmEnableThreads)" PThreadPoolSize="$(_WasmPThreadPoolSize)" UseWebcil="$(WasmEnableWebcil)" WasmIncludeFullIcuData="$(WasmIncludeFullIcuData)" From cf669a13ba7f63aceee407a93d31a802db53818c Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz <32700855+ilonatommy@users.noreply.github.com> Date: Wed, 31 Jan 2024 12:38:12 +0000 Subject: [PATCH 06/18] Replace `MonoWasmThreads` with `WasmEnableThreads` --- src/mono/browser/browser.proj | 29 ++++++++------- src/mono/browser/runtime/cwraps.ts | 4 +-- .../runtime/diagnostics/browser/controller.ts | 4 +-- src/mono/browser/runtime/diagnostics/index.ts | 8 ++--- .../diagnostics/server_pthread/index.ts | 4 +-- .../server_pthread/streaming-session.ts | 4 +-- src/mono/browser/runtime/exports-binding.ts | 4 +-- src/mono/browser/runtime/gc-handles.ts | 4 +-- src/mono/browser/runtime/gc-lock.ts | 6 ++-- src/mono/browser/runtime/invoke-cs.ts | 32 ++++++++--------- src/mono/browser/runtime/invoke-js.ts | 36 +++++++++---------- .../browser/runtime/jiterpreter-support.ts | 8 ++--- src/mono/browser/runtime/loader/assets.ts | 6 ++-- src/mono/browser/runtime/loader/config.ts | 4 +-- src/mono/browser/runtime/loader/logging.ts | 6 ++-- src/mono/browser/runtime/loader/polyfills.ts | 4 +-- src/mono/browser/runtime/managed-exports.ts | 8 ++--- src/mono/browser/runtime/marshal-to-cs.ts | 12 +++---- src/mono/browser/runtime/marshal-to-js.ts | 8 ++--- src/mono/browser/runtime/marshal.ts | 8 ++--- src/mono/browser/runtime/memory.ts | 10 +++--- src/mono/browser/runtime/polyfills.ts | 8 ++--- .../browser/runtime/pthreads/browser/index.ts | 20 +++++------ .../pthreads/shared/emscripten-internals.ts | 4 +-- .../shared/emscripten-replacements.ts | 8 ++--- .../browser/runtime/pthreads/shared/index.ts | 12 +++---- .../browser/runtime/pthreads/worker/events.ts | 4 +-- .../browser/runtime/pthreads/worker/index.ts | 12 +++---- src/mono/browser/runtime/rollup.config.js | 4 +-- src/mono/browser/runtime/scheduling.ts | 6 ++-- src/mono/browser/runtime/snapshot.ts | 4 +-- src/mono/browser/runtime/startup.ts | 14 ++++---- src/mono/browser/runtime/web-socket.ts | 6 ++-- src/mono/mono.proj | 22 ++++++------ 34 files changed, 165 insertions(+), 168 deletions(-) diff --git a/src/mono/browser/browser.proj b/src/mono/browser/browser.proj index d9055543a2344f..3dbbe29d085bed 100644 --- a/src/mono/browser/browser.proj +++ b/src/mono/browser/browser.proj @@ -16,17 +16,16 @@ - true false true - $([MSBuild]::NormalizeDirectory('$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)', 'runtimes', 'browser-wasm', 'native', 'lib')) - $([MSBuild]::NormalizeDirectory('$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)', 'runtimes', 'browser-wasm-threads', 'native', 'lib')) + $([MSBuild]::NormalizeDirectory('$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)', 'runtimes', 'browser-wasm', 'native', 'lib')) + $([MSBuild]::NormalizeDirectory('$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)', 'runtimes', 'browser-wasm-threads', 'native', 'lib')) true true - true + true false false emcc @@ -255,10 +254,10 @@ - + - + @@ -271,10 +270,10 @@ <_EmccLinkFlags Include="-s INITIAL_MEMORY=$(EmccInitialHeapSize)" /> <_EmccLinkFlags Include="-s STACK_SIZE=$(EmccStackSize)" /> - <_EmccCommonFlags Condition="'$(MonoWasmThreads)' == 'true'" Include="-s USE_PTHREADS=1" /> - <_EmccLinkFlags Condition="'$(MonoWasmThreads)' == 'true'" Include="-Wno-pthreads-mem-growth" /> - <_EmccLinkFlags Condition="'$(MonoWasmThreads)' == 'true'" Include="-s PTHREAD_POOL_SIZE=0" /> - <_EmccLinkFlags Condition="'$(MonoWasmThreads)' == 'true'" Include="-s PTHREAD_POOL_SIZE_STRICT=0" /> + <_EmccCommonFlags Condition="'$(WasmEnableThreads)' == 'true'" Include="-s USE_PTHREADS=1" /> + <_EmccLinkFlags Condition="'$(WasmEnableThreads)' == 'true'" Include="-Wno-pthreads-mem-growth" /> + <_EmccLinkFlags Condition="'$(WasmEnableThreads)' == 'true'" Include="-s PTHREAD_POOL_SIZE=0" /> + <_EmccLinkFlags Condition="'$(WasmEnableThreads)' == 'true'" Include="-s PTHREAD_POOL_SIZE_STRICT=0" /> <_EmccLinkFlags Include="-s ALLOW_MEMORY_GROWTH=1" /> <_EmccLinkFlags Include="-s ALLOW_TABLE_GROWTH=1" /> @@ -294,7 +293,7 @@ <_EmccLinkFlags Include="-Wno-limited-postlink-optimizations"/> - + @@ -373,7 +372,7 @@ $(CMakeConfigurationLinkFlags) -s EXPORT_ES6=1 -lexports.js $(CMakeConfigurationLinkFlags) -msimd128 - $(CMakeConfigurationLinkFlags) -Wno-pthreads-mem-growth + $(CMakeConfigurationLinkFlags) -Wno-pthreads-mem-growth $(CMakeConfigurationLinkFlags) --emit-symbol-map -DEMSDK_PATH="$(EMSDK_PATH.TrimEnd('\/').Replace('\','/'))" @@ -390,7 +389,7 @@ $(CMakeBuildRuntimeConfigureCmd) -DNATIVE_BIN_DIR="$(NativeBinDir.TrimEnd('\/').Replace('\','/'))" $(CMakeBuildRuntimeConfigureCmd) -DCONFIGURATION_COMPILE_OPTIONS="-msimd128" -DCONFIGURATION_INTERPSIMDTABLES_LIB="simd" $(CMakeBuildRuntimeConfigureCmd) -DCONFIGURATION_INTERPSIMDTABLES_LIB="nosimd" - $(CMakeBuildRuntimeConfigureCmd) -DDISABLE_THREADS=0 + $(CMakeBuildRuntimeConfigureCmd) -DDISABLE_THREADS=0 $(CMakeBuildRuntimeConfigureCmd) -DENABLE_JS_INTEROP_BY_VALUE=1 $(CMakeBuildRuntimeConfigureCmd) $(CMakeConfigurationEmsdkPath) @@ -539,7 +538,7 @@ <_MonoRollupEnvironmentVariable Include="NativeBinDir:$(NativeBinDir)" /> <_MonoRollupEnvironmentVariable Include="WasmObjDir:$(WasmObjDir)" /> <_MonoRollupEnvironmentVariable Include="ProductVersion:$(ProductVersion)" /> - <_MonoRollupEnvironmentVariable Include="MonoWasmThreads:$(MonoWasmThreads)" /> + <_MonoRollupEnvironmentVariable Include="WasmEnableThreads:$(WasmEnableThreads)" /> <_MonoRollupEnvironmentVariable Include="WASM_ENABLE_SIMD:1" Condition="'$(WasmEnableSIMD)' != 'false'" /> <_MonoRollupEnvironmentVariable Include="WASM_ENABLE_SIMD:0" Condition="'$(WasmEnableSIMD)' == 'false'" /> <_MonoRollupEnvironmentVariable Include="WASM_ENABLE_EH:1" Condition="'$(WasmEnableExceptionHandling)' != 'false'" /> @@ -562,7 +561,7 @@ + `WasmEnableThreads` property is changed between builds by a developer. --> boolean), name: string, returnType: string | null, argTypes?: string[], opts?: any]; -const threading_cwraps: SigLine[] = MonoWasmThreads ? [ +const threading_cwraps: SigLine[] = WasmEnableThreads ? [ // MONO.diagnostics [true, "mono_wasm_event_pipe_enable", "bool", ["string", "number", "number", "string", "bool", "number"]], [true, "mono_wasm_event_pipe_session_start_streaming", "bool", ["number"]], diff --git a/src/mono/browser/runtime/diagnostics/browser/controller.ts b/src/mono/browser/runtime/diagnostics/browser/controller.ts index 6286da2b50539f..8cc60f7742c4cf 100644 --- a/src/mono/browser/runtime/diagnostics/browser/controller.ts +++ b/src/mono/browser/runtime/diagnostics/browser/controller.ts @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import MonoWasmThreads from "consts:monoWasmThreads"; +import WasmEnableThreads from "consts:wasmEnableThreads"; import { threads_c_functions as cwraps } from "../../cwraps"; import { INTERNAL, mono_assert } from "../../globals"; @@ -54,7 +54,7 @@ export function getController(): ServerController { } export async function startDiagnosticServer(websocket_url: string): Promise { - mono_assert(MonoWasmThreads, "The diagnostic server requires threads to be enabled during build time."); + mono_assert(WasmEnableThreads, "The diagnostic server requires threads to be enabled during build time."); const sizeOfPthreadT = 4; mono_log_info(`starting the diagnostic server url: ${websocket_url}`); const result: number | undefined = withStackAlloc(sizeOfPthreadT, (pthreadIdPtr) => { diff --git a/src/mono/browser/runtime/diagnostics/index.ts b/src/mono/browser/runtime/diagnostics/index.ts index 1d93725a640b8a..474fd8a824fd56 100644 --- a/src/mono/browser/runtime/diagnostics/index.ts +++ b/src/mono/browser/runtime/diagnostics/index.ts @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import MonoWasmThreads from "consts:monoWasmThreads"; +import WasmEnableThreads from "consts:wasmEnableThreads"; import type { DiagnosticOptions, @@ -16,7 +16,7 @@ import { mono_assert, runtimeHelpers } from "../globals"; // called from C on the main thread export function mono_wasm_event_pipe_early_startup_callback(): void { - if (MonoWasmThreads) { + if (WasmEnableThreads) { return; } } @@ -39,7 +39,7 @@ let diagnosticsInitialized = false; export async function mono_wasm_init_diagnostics(): Promise { if (diagnosticsInitialized) return; - if (!MonoWasmThreads) { + if (!WasmEnableThreads) { mono_log_warn("ignoring diagnostics options because this runtime does not support diagnostics"); return; } @@ -144,7 +144,7 @@ function diagnostic_options_from_ports_spec(val: string): DiagnosticOptions | nu } export function mono_wasm_diagnostic_server_on_runtime_server_init(out_options: VoidPtr): void { - mono_assert(MonoWasmThreads, "The diagnostic server requires threads to be enabled during build time."); + mono_assert(WasmEnableThreads, "The diagnostic server requires threads to be enabled during build time."); if (diagnosticsServerEnabled) { /* called on the main thread when the runtime is sufficiently initialized */ const controller = getController(); diff --git a/src/mono/browser/runtime/diagnostics/server_pthread/index.ts b/src/mono/browser/runtime/diagnostics/server_pthread/index.ts index 1bec0f6b3efd98..1fbca276f3c897 100644 --- a/src/mono/browser/runtime/diagnostics/server_pthread/index.ts +++ b/src/mono/browser/runtime/diagnostics/server_pthread/index.ts @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. /// -import MonoWasmThreads from "consts:monoWasmThreads"; +import WasmEnableThreads from "consts:wasmEnableThreads"; import monoDiagnosticsMock from "consts:monoDiagnosticsMock"; import { PromiseAndController, assertNever } from "../../types/internal"; @@ -285,7 +285,7 @@ function parseProtocolCommand(data: ArrayBuffer | BinaryProtocolCommand): ParseC /// Called by the runtime to initialize the diagnostic server workers export function mono_wasm_diagnostic_server_on_server_thread_created(websocketUrlPtr: CharPtr): void { - mono_assert(MonoWasmThreads, "The diagnostic server requires threads to be enabled during build time."); + mono_assert(WasmEnableThreads, "The diagnostic server requires threads to be enabled during build time."); const websocketUrl = utf8ToString(websocketUrlPtr); mono_log_debug(`mono_wasm_diagnostic_server_on_server_thread_created, url ${websocketUrl}`); let mock: PromiseAndController | undefined = undefined; diff --git a/src/mono/browser/runtime/diagnostics/server_pthread/streaming-session.ts b/src/mono/browser/runtime/diagnostics/server_pthread/streaming-session.ts index aa60222ed657d5..6854261e4d00ed 100644 --- a/src/mono/browser/runtime/diagnostics/server_pthread/streaming-session.ts +++ b/src/mono/browser/runtime/diagnostics/server_pthread/streaming-session.ts @@ -1,6 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import MonoWasmThreads from "consts:monoWasmThreads"; +import WasmEnableThreads from "consts:wasmEnableThreads"; import { EventPipeSessionIDImpl } from "../shared/types"; import { EventPipeSocketConnection, takeOverSocket } from "./socket-connection"; @@ -25,7 +25,7 @@ export class EventPipeStreamingSession { } export async function makeEventPipeStreamingSession(ws: WebSocket | MockRemoteSocket, cmd: EventPipeCommandCollectTracing2): Promise { - mono_assert(MonoWasmThreads, "The diagnostic server requires threads to be enabled during build time."); + mono_assert(WasmEnableThreads, "The diagnostic server requires threads to be enabled during build time."); // First, create the native IPC stream and get its queue. const ipcStreamAddr = cwraps.mono_wasm_diagnostic_server_create_stream(); // FIXME: this should be a wrapped in a JS object so we can free it when we're done. const queueAddr = getQueueAddrFromStreamAddr(ipcStreamAddr); diff --git a/src/mono/browser/runtime/exports-binding.ts b/src/mono/browser/runtime/exports-binding.ts index 2f69b78b95fecf..98752f2bcb9aa4 100644 --- a/src/mono/browser/runtime/exports-binding.ts +++ b/src/mono/browser/runtime/exports-binding.ts @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import MonoWasmThreads from "consts:monoWasmThreads"; +import WasmEnableThreads from "consts:wasmEnableThreads"; import { mono_wasm_debugger_log, mono_wasm_add_dbg_command_received, mono_wasm_set_entrypoint_breakpoint, mono_wasm_fire_debugger_agent_message_with_data, mono_wasm_fire_debugger_agent_message_with_data_to_pause } from "./debug"; import { mono_wasm_release_cs_owned_object } from "./gc-handles"; @@ -31,7 +31,7 @@ import { mono_wasm_browser_entropy } from "./crypto"; // the JS methods would be visible to EMCC linker and become imports of the WASM module -export const mono_wasm_threads_imports = !MonoWasmThreads ? [] : [ +export const mono_wasm_threads_imports = !WasmEnableThreads ? [] : [ // mono-threads-wasm.c mono_wasm_pthread_on_pthread_attached, mono_wasm_pthread_on_pthread_detached, diff --git a/src/mono/browser/runtime/gc-handles.ts b/src/mono/browser/runtime/gc-handles.ts index d0c8c6094cba17..554387d4c64c17 100644 --- a/src/mono/browser/runtime/gc-handles.ts +++ b/src/mono/browser/runtime/gc-handles.ts @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import MonoWasmThreads from "consts:monoWasmThreads"; +import WasmEnableThreads from "consts:wasmEnableThreads"; import BuildConfiguration from "consts:configuration"; import { loaderHelpers, mono_assert, runtimeHelpers } from "./globals"; @@ -185,7 +185,7 @@ export function _lookup_js_owned_object(gc_handle: GCHandle): any { } export function assertNoProxies(): void { - if (!MonoWasmThreads) return; + if (!WasmEnableThreads) return; mono_assert(_js_owned_object_table.size === 0, "There should be no proxies on this thread."); mono_assert(_cs_owned_objects_by_js_handle.length === 1, "There should be no proxies on this thread."); mono_assert(_cs_owned_objects_by_jsv_handle.length === 1, "There should be no proxies on this thread."); diff --git a/src/mono/browser/runtime/gc-lock.ts b/src/mono/browser/runtime/gc-lock.ts index 31b2db200c5b39..876e6a2eb58693 100644 --- a/src/mono/browser/runtime/gc-lock.ts +++ b/src/mono/browser/runtime/gc-lock.ts @@ -1,4 +1,4 @@ -import MonoWasmThreads from "consts:monoWasmThreads"; +import WasmEnableThreads from "consts:wasmEnableThreads"; import { ENVIRONMENT_IS_PTHREAD } from "./globals"; import cwraps from "./cwraps"; @@ -8,7 +8,7 @@ export function mono_wasm_gc_lock(): void { if (locked) { throw new Error("GC is already locked"); } - if (MonoWasmThreads) { + if (WasmEnableThreads) { if (ENVIRONMENT_IS_PTHREAD) { throw new Error("GC lock only supported in main thread"); } @@ -21,7 +21,7 @@ export function mono_wasm_gc_unlock(): void { if (!locked) { throw new Error("GC is not locked"); } - if (MonoWasmThreads) { + if (WasmEnableThreads) { if (ENVIRONMENT_IS_PTHREAD) { throw new Error("GC lock only supported in main thread"); } diff --git a/src/mono/browser/runtime/invoke-cs.ts b/src/mono/browser/runtime/invoke-cs.ts index dccdbe5be31317..fdcc2fd82330bb 100644 --- a/src/mono/browser/runtime/invoke-cs.ts +++ b/src/mono/browser/runtime/invoke-cs.ts @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. import BuildConfiguration from "consts:configuration"; -import MonoWasmThreads from "consts:monoWasmThreads"; +import WasmEnableThreads from "consts:wasmEnableThreads"; import { Module, loaderHelpers, mono_assert, runtimeHelpers } from "./globals"; import { bind_arg_marshal_to_cs } from "./marshal-to-cs"; @@ -131,11 +131,11 @@ export function mono_wasm_bind_cs_function(fully_qualified_name: MonoStringRef, function bind_fn_0V(closure: BindingClosure) { const method = closure.method; const fqn = closure.fqn; - if (!MonoWasmThreads) (closure) = null; + if (!WasmEnableThreads) (closure) = null; return function bound_fn_0V() { const mark = startMeasure(); loaderHelpers.assert_runtime_running(); - mono_assert(!MonoWasmThreads || !closure.isDisposed, "The function was already disposed"); + mono_assert(!WasmEnableThreads || !closure.isDisposed, "The function was already disposed"); const sp = Module.stackSave(); try { const args = alloc_stack_frame(2); @@ -152,11 +152,11 @@ function bind_fn_1V(closure: BindingClosure) { const method = closure.method; const marshaler1 = closure.arg_marshalers[0]!; const fqn = closure.fqn; - if (!MonoWasmThreads) (closure) = null; + if (!WasmEnableThreads) (closure) = null; return function bound_fn_1V(arg1: any) { const mark = startMeasure(); loaderHelpers.assert_runtime_running(); - mono_assert(!MonoWasmThreads || !closure.isDisposed, "The function was already disposed"); + mono_assert(!WasmEnableThreads || !closure.isDisposed, "The function was already disposed"); const sp = Module.stackSave(); try { const args = alloc_stack_frame(3); @@ -176,11 +176,11 @@ function bind_fn_1R(closure: BindingClosure) { const marshaler1 = closure.arg_marshalers[0]!; const res_converter = closure.res_converter!; const fqn = closure.fqn; - if (!MonoWasmThreads) (closure) = null; + if (!WasmEnableThreads) (closure) = null; return function bound_fn_1R(arg1: any) { const mark = startMeasure(); loaderHelpers.assert_runtime_running(); - mono_assert(!MonoWasmThreads || !closure.isDisposed, "The function was already disposed"); + mono_assert(!WasmEnableThreads || !closure.isDisposed, "The function was already disposed"); const sp = Module.stackSave(); try { const args = alloc_stack_frame(3); @@ -203,11 +203,11 @@ function bind_fn_1RA(closure: BindingClosure) { const marshaler1 = closure.arg_marshalers[0]!; const res_converter = closure.res_converter!; const fqn = closure.fqn; - if (!MonoWasmThreads) (closure) = null; + if (!WasmEnableThreads) (closure) = null; return function bound_fn_1R(arg1: any) { const mark = startMeasure(); loaderHelpers.assert_runtime_running(); - mono_assert(!MonoWasmThreads || !closure.isDisposed, "The function was already disposed"); + mono_assert(!WasmEnableThreads || !closure.isDisposed, "The function was already disposed"); const sp = Module.stackSave(); try { const args = alloc_stack_frame(3); @@ -236,11 +236,11 @@ function bind_fn_2R(closure: BindingClosure) { const marshaler2 = closure.arg_marshalers[1]!; const res_converter = closure.res_converter!; const fqn = closure.fqn; - if (!MonoWasmThreads) (closure) = null; + if (!WasmEnableThreads) (closure) = null; return function bound_fn_2R(arg1: any, arg2: any) { const mark = startMeasure(); loaderHelpers.assert_runtime_running(); - mono_assert(!MonoWasmThreads || !closure.isDisposed, "The function was already disposed"); + mono_assert(!WasmEnableThreads || !closure.isDisposed, "The function was already disposed"); const sp = Module.stackSave(); try { const args = alloc_stack_frame(4); @@ -265,11 +265,11 @@ function bind_fn_2RA(closure: BindingClosure) { const marshaler2 = closure.arg_marshalers[1]!; const res_converter = closure.res_converter!; const fqn = closure.fqn; - if (!MonoWasmThreads) (closure) = null; + if (!WasmEnableThreads) (closure) = null; return function bound_fn_2R(arg1: any, arg2: any) { const mark = startMeasure(); loaderHelpers.assert_runtime_running(); - mono_assert(!MonoWasmThreads || !closure.isDisposed, "The function was already disposed"); + mono_assert(!WasmEnableThreads || !closure.isDisposed, "The function was already disposed"); const sp = Module.stackSave(); try { const args = alloc_stack_frame(4); @@ -300,11 +300,11 @@ function bind_fn(closure: BindingClosure) { const method = closure.method; const fqn = closure.fqn; const is_async = closure.is_async; - if (!MonoWasmThreads) (closure) = null; + if (!WasmEnableThreads) (closure) = null; return function bound_fn(...js_args: any[]) { const mark = startMeasure(); loaderHelpers.assert_runtime_running(); - mono_assert(!MonoWasmThreads || !closure.isDisposed, "The function was already disposed"); + mono_assert(!WasmEnableThreads || !closure.isDisposed, "The function was already disposed"); const sp = Module.stackSave(); try { const args = alloc_stack_frame(2 + args_count); @@ -435,7 +435,7 @@ export async function mono_wasm_get_assembly_exports(assembly: string): Promise< } } } else { - mono_assert(!MonoWasmThreads, () => `JSExport with multi-threading enabled is not supported with assembly ${assembly} as it was generated with the .NET 7 SDK`); + mono_assert(!WasmEnableThreads, () => `JSExport with multi-threading enabled is not supported with assembly ${assembly} as it was generated with the .NET 7 SDK`); // this needs to stay here for compatibility with assemblies generated in Net7 // it doesn't have the __GeneratedInitializer class cwraps.mono_wasm_runtime_run_module_cctor(asm); diff --git a/src/mono/browser/runtime/invoke-js.ts b/src/mono/browser/runtime/invoke-js.ts index f36d2ee1aa02b7..79f676ee08b437 100644 --- a/src/mono/browser/runtime/invoke-js.ts +++ b/src/mono/browser/runtime/invoke-js.ts @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import MonoWasmThreads from "consts:monoWasmThreads"; +import WasmEnableThreads from "consts:wasmEnableThreads"; import BuildConfiguration from "consts:configuration"; import { marshal_exception_to_cs, bind_arg_marshal_to_cs } from "./marshal-to-cs"; @@ -22,7 +22,7 @@ import { is_thread_available } from "./pthreads/shared/emscripten-replacements"; export const js_import_wrapper_by_fn_handle: Function[] = [null];// 0th slot is dummy, main thread we free them on shutdown. On web worker thread we free them when worker is detached. export function mono_wasm_bind_js_import(signature: JSFunctionSignature, is_exception: Int32Ptr, result_address: MonoObjectRef): void { - if (MonoWasmThreads) return; + if (WasmEnableThreads) return; assert_js_interop(); const resultRoot = mono_wasm_new_external_root(result_address); try { @@ -37,7 +37,7 @@ export function mono_wasm_bind_js_import(signature: JSFunctionSignature, is_exce } export function mono_wasm_invoke_import_async(args: JSMarshalerArguments, signature: JSFunctionSignature) { - if (!MonoWasmThreads) return; + if (!WasmEnableThreads) return; assert_js_interop(); const function_handle = get_signature_handle(signature); @@ -60,7 +60,7 @@ export function mono_wasm_invoke_import_async(args: JSMarshalerArguments, signat } } - if (MonoWasmThreads && !ENVIRONMENT_IS_WORKER) { + if (WasmEnableThreads && !ENVIRONMENT_IS_WORKER) { // give thread chance to load before we run more synchronous code on UI thread postpone_invoke_import_async(); } @@ -72,7 +72,7 @@ export function mono_wasm_invoke_import_async(args: JSMarshalerArguments, signat } export function mono_wasm_invoke_import_sync(args: JSMarshalerArguments, signature: JSFunctionSignature) { - if (!MonoWasmThreads) return; + if (!WasmEnableThreads) return; assert_js_interop(); const function_handle = get_signature_handle(signature); @@ -176,11 +176,11 @@ function bind_js_import(signature: JSFunctionSignature): Function { function bind_fn_0V(closure: BindingClosure) { const fn = closure.fn; const fqn = closure.fqn; - if (!MonoWasmThreads) (closure) = null; + if (!WasmEnableThreads) (closure) = null; return function bound_fn_0V(args: JSMarshalerArguments) { const mark = startMeasure(); try { - mono_assert(!MonoWasmThreads || !closure.isDisposed, "The function was already disposed"); + mono_assert(!WasmEnableThreads || !closure.isDisposed, "The function was already disposed"); // call user function fn(); } catch (ex) { @@ -196,11 +196,11 @@ function bind_fn_1V(closure: BindingClosure) { const fn = closure.fn; const marshaler1 = closure.arg_marshalers[0]!; const fqn = closure.fqn; - if (!MonoWasmThreads) (closure) = null; + if (!WasmEnableThreads) (closure) = null; return function bound_fn_1V(args: JSMarshalerArguments) { const mark = startMeasure(); try { - mono_assert(!MonoWasmThreads || !closure.isDisposed, "The function was already disposed"); + mono_assert(!WasmEnableThreads || !closure.isDisposed, "The function was already disposed"); const arg1 = marshaler1(args); // call user function fn(arg1); @@ -218,11 +218,11 @@ function bind_fn_1R(closure: BindingClosure) { const marshaler1 = closure.arg_marshalers[0]!; const res_converter = closure.res_converter!; const fqn = closure.fqn; - if (!MonoWasmThreads) (closure) = null; + if (!WasmEnableThreads) (closure) = null; return function bound_fn_1R(args: JSMarshalerArguments) { const mark = startMeasure(); try { - mono_assert(!MonoWasmThreads || !closure.isDisposed, "The function was already disposed"); + mono_assert(!WasmEnableThreads || !closure.isDisposed, "The function was already disposed"); const arg1 = marshaler1(args); // call user function const js_result = fn(arg1); @@ -242,11 +242,11 @@ function bind_fn_2R(closure: BindingClosure) { const marshaler2 = closure.arg_marshalers[1]!; const res_converter = closure.res_converter!; const fqn = closure.fqn; - if (!MonoWasmThreads) (closure) = null; + if (!WasmEnableThreads) (closure) = null; return function bound_fn_2R(args: JSMarshalerArguments) { const mark = startMeasure(); try { - mono_assert(!MonoWasmThreads || !closure.isDisposed, "The function was already disposed"); + mono_assert(!WasmEnableThreads || !closure.isDisposed, "The function was already disposed"); const arg1 = marshaler1(args); const arg2 = marshaler2(args); // call user function @@ -269,11 +269,11 @@ function bind_fn(closure: BindingClosure) { const has_cleanup = closure.has_cleanup; const fn = closure.fn; const fqn = closure.fqn; - if (!MonoWasmThreads) (closure) = null; + if (!WasmEnableThreads) (closure) = null; return function bound_fn(args: JSMarshalerArguments) { const mark = startMeasure(); try { - mono_assert(!MonoWasmThreads || !closure.isDisposed, "The function was already disposed"); + mono_assert(!WasmEnableThreads || !closure.isDisposed, "The function was already disposed"); const js_args = new Array(args_count); for (let index = 0; index < args_count; index++) { const marshaler = arg_marshalers[index]!; @@ -340,7 +340,7 @@ function mono_wasm_lookup_js_import(function_name: string, js_module_name: strin const parts = function_name.split("."); if (js_module_name) { scope = importedModules.get(js_module_name); - if (MonoWasmThreads) { + if (WasmEnableThreads) { mono_assert(scope, () => `ES6 module ${js_module_name} was not imported yet, please call JSHost.ImportAsync() on the UI or JSWebWorker thread first.`); } else { mono_assert(scope, () => `ES6 module ${js_module_name} was not imported yet, please call JSHost.ImportAsync() first.`); @@ -461,7 +461,7 @@ export function wrap_no_error_root(is_exception: Int32Ptr | null, result?: WasmR export function assert_js_interop(): void { loaderHelpers.assert_runtime_running(); - if (MonoWasmThreads) { + if (WasmEnableThreads) { mono_assert(runtimeHelpers.mono_wasm_bindings_is_ready && runtimeHelpers.proxy_context_gc_handle, "Please use dedicated worker for working with JavaScript interop. See https://github.com/dotnet/runtime/blob/main/src/mono/wasm/threads.md#JS-interop-on-dedicated-threads"); } else { mono_assert(runtimeHelpers.mono_wasm_bindings_is_ready, "The runtime must be initialized."); @@ -470,7 +470,7 @@ export function assert_js_interop(): void { export function assert_c_interop(): void { loaderHelpers.assert_runtime_running(); - if (MonoWasmThreads) { + if (WasmEnableThreads) { mono_assert(runtimeHelpers.mono_wasm_bindings_is_ready, "Please use dedicated worker for working with JavaScript interop. See https://github.com/dotnet/runtime/blob/main/src/mono/wasm/threads.md#JS-interop-on-dedicated-threads"); } else { mono_assert(runtimeHelpers.mono_wasm_bindings_is_ready, "The runtime must be initialized."); diff --git a/src/mono/browser/runtime/jiterpreter-support.ts b/src/mono/browser/runtime/jiterpreter-support.ts index d406fd68b94ce8..cacd4d306695ae 100644 --- a/src/mono/browser/runtime/jiterpreter-support.ts +++ b/src/mono/browser/runtime/jiterpreter-support.ts @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import MonoWasmThreads from "consts:monoWasmThreads"; +import WasmEnableThreads from "consts:wasmEnableThreads"; import { NativePointer, ManagedPointer, VoidPtr } from "./types/emscripten"; import { Module, mono_assert, runtimeHelpers, linkerRunAOTCompilation } from "./globals"; import { WasmOpcode, WasmSimdOpcode, WasmValtype } from "./jiterpreter-opcodes"; @@ -513,7 +513,7 @@ export class WasmBuilder { // import the native heap this.appendName("m"); this.appendName("h"); - if (MonoWasmThreads) { + if (WasmEnableThreads) { // memtype (limits = 0x03 n:u32 m:u32 => {min n, max m, shared}) this.appendU8(0x02); this.appendU8(0x03); @@ -1821,7 +1821,7 @@ let observedTaintedZeroPage: boolean | undefined; export function isZeroPageReserved(): boolean { // FIXME: This check will always return true on worker threads. // Right now the jiterpreter is disabled when threading is active, so that's not an issue. - if (MonoWasmThreads) + if (WasmEnableThreads) return false; if (!cwraps.mono_wasm_is_zero_page_reserved()) @@ -1991,7 +1991,7 @@ function jiterpreter_allocate_table(type: JiterpreterTable, base: number, size: // In threaded builds we need to populate all the reserved slots with safe placeholder functions // This operation is expensive in v8, so avoid doing it in single-threaded builds (which SHOULD // be safe, since it was previously not necessary) - if (MonoWasmThreads) { + if (WasmEnableThreads) { // HACK: If possible, we want to copy any backing state associated with the first placeholder item, // so that additional work doesn't have to be done by the runtime for the following table sets const preparedValue = wasmTable.get(firstIndex); diff --git a/src/mono/browser/runtime/loader/assets.ts b/src/mono/browser/runtime/loader/assets.ts index d4a6653ca9b821..3cbfd663caa947 100644 --- a/src/mono/browser/runtime/loader/assets.ts +++ b/src/mono/browser/runtime/loader/assets.ts @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import MonoWasmThreads from "consts:monoWasmThreads"; +import WasmEnableThreads from "consts:wasmEnableThreads"; import type { AssetEntryInternal, PromiseAndController } from "../types/internal"; import type { AssetBehaviors, AssetEntry, LoadingResource, ResourceList, SingleAssetBehaviors as SingleAssetBehaviors, WebAssemblyBootResourceType } from "../types"; @@ -284,11 +284,11 @@ export function prepareAssets() { mono_assert(resources.wasmNative, "resources.wasmNative must be defined"); mono_assert(resources.jsModuleNative, "resources.jsModuleNative must be defined"); mono_assert(resources.jsModuleRuntime, "resources.jsModuleRuntime must be defined"); - mono_assert(!MonoWasmThreads || resources.jsModuleWorker, "resources.jsModuleWorker must be defined"); + mono_assert(!WasmEnableThreads || resources.jsModuleWorker, "resources.jsModuleWorker must be defined"); convert_single_asset(alwaysLoadedAssets, resources.wasmNative, "dotnetwasm"); convert_single_asset(modulesAssets, resources.jsModuleNative, "js-module-native"); convert_single_asset(modulesAssets, resources.jsModuleRuntime, "js-module-runtime"); - if (MonoWasmThreads) { + if (WasmEnableThreads) { convert_single_asset(modulesAssets, resources.jsModuleWorker, "js-module-threads"); } diff --git a/src/mono/browser/runtime/loader/config.ts b/src/mono/browser/runtime/loader/config.ts index a42db2dcb0e9d6..7adb0af155747f 100644 --- a/src/mono/browser/runtime/loader/config.ts +++ b/src/mono/browser/runtime/loader/config.ts @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. import BuildConfiguration from "consts:configuration"; -import MonoWasmThreads from "consts:monoWasmThreads"; +import WasmEnableThreads from "consts:wasmEnableThreads"; import type { DotnetModuleInternal, MonoConfigInternal } from "../types/internal"; import type { DotnetModuleConfig, MonoConfig, ResourceGroups, ResourceList } from "../types"; @@ -188,7 +188,7 @@ export function normalizeConfig() { config.cachedResourcesPurgeDelay = 10000; } - if (MonoWasmThreads && !Number.isInteger(config.pthreadPoolSize)) { + if (WasmEnableThreads && !Number.isInteger(config.pthreadPoolSize)) { // ActiveIssue https://github.com/dotnet/runtime/issues/91538 config.pthreadPoolSize = 7; } diff --git a/src/mono/browser/runtime/loader/logging.ts b/src/mono/browser/runtime/loader/logging.ts index e8fba663b78109..2e3f76822ce4ad 100644 --- a/src/mono/browser/runtime/loader/logging.ts +++ b/src/mono/browser/runtime/loader/logging.ts @@ -3,7 +3,7 @@ /* eslint-disable no-console */ -import MonoWasmThreads from "consts:monoWasmThreads"; +import WasmEnableThreads from "consts:wasmEnableThreads"; import { ENVIRONMENT_IS_WORKER, loaderHelpers } from "./globals"; @@ -62,12 +62,12 @@ function proxyConsoleMethod(prefix: string, func: any, asJson: boolean) { if (typeof payload === "string") { if (payload[0] == "[") { const now = new Date().toISOString(); - if (MonoWasmThreads && ENVIRONMENT_IS_WORKER) { + if (WasmEnableThreads && ENVIRONMENT_IS_WORKER) { payload = `[${threadNamePrefix}][${now}] ${payload}`; } else { payload = `[${now}] ${payload}`; } - } else if (MonoWasmThreads && ENVIRONMENT_IS_WORKER) { + } else if (WasmEnableThreads && ENVIRONMENT_IS_WORKER) { if (payload.indexOf("keeping the worker alive for asynchronous operation") !== -1) { // muting emscripten noise return; diff --git a/src/mono/browser/runtime/loader/polyfills.ts b/src/mono/browser/runtime/loader/polyfills.ts index b688e5a90eaaf3..e60fb2111b8f5f 100644 --- a/src/mono/browser/runtime/loader/polyfills.ts +++ b/src/mono/browser/runtime/loader/polyfills.ts @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import MonoWasmThreads from "consts:monoWasmThreads"; +import WasmEnableThreads from "consts:wasmEnableThreads"; import type { DotnetModuleInternal } from "../types/internal"; import { INTERNAL, ENVIRONMENT_IS_NODE, ENVIRONMENT_IS_SHELL, loaderHelpers, ENVIRONMENT_IS_WEB, mono_assert } from "./globals"; @@ -21,7 +21,7 @@ const URLPolyfill = class URL { export function verifyEnvironment() { mono_assert(ENVIRONMENT_IS_SHELL || typeof globalThis.URL === "function", "This browser/engine doesn't support URL API. Please use a modern version. See also https://aka.ms/dotnet-wasm-features"); mono_assert(typeof globalThis.BigInt64Array === "function", "This browser/engine doesn't support BigInt64Array API. Please use a modern version. See also https://aka.ms/dotnet-wasm-features"); - if (MonoWasmThreads) { + if (WasmEnableThreads) { mono_assert(!ENVIRONMENT_IS_SHELL && !ENVIRONMENT_IS_NODE, "This build of dotnet is multi-threaded, it doesn't support shell environments like V8 or NodeJS. See also https://aka.ms/dotnet-wasm-features"); mono_assert(globalThis.SharedArrayBuffer !== undefined, "SharedArrayBuffer is not enabled on this page. Please use a modern browser and set Cross-Origin-Opener-Policy and Cross-Origin-Embedder-Policy http headers. See also https://aka.ms/dotnet-wasm-features"); mono_assert(typeof globalThis.EventTarget === "function", "This browser/engine doesn't support EventTarget API. Please use a modern version. See also https://aka.ms/dotnet-wasm-features"); diff --git a/src/mono/browser/runtime/managed-exports.ts b/src/mono/browser/runtime/managed-exports.ts index 6d2e54a551f6e2..64db9fd82eb49c 100644 --- a/src/mono/browser/runtime/managed-exports.ts +++ b/src/mono/browser/runtime/managed-exports.ts @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import MonoWasmThreads from "consts:monoWasmThreads"; +import WasmEnableThreads from "consts:wasmEnableThreads"; import { GCHandle, MarshalerToCs, MarshalerToJs, MarshalerType, MonoMethod } from "./types/internal"; import cwraps from "./cwraps"; @@ -24,8 +24,8 @@ export function init_managed_exports(): void { if (!runtimeHelpers.runtime_interop_exports_class) throw "Can't find " + runtimeHelpers.runtime_interop_namespace + "." + runtimeHelpers.runtime_interop_exports_classname + " class"; - const install_main_synchronization_context = MonoWasmThreads ? get_method("InstallMainSynchronizationContext") : undefined; - mono_assert(!MonoWasmThreads || install_main_synchronization_context, "Can't find InstallMainSynchronizationContext method"); + const install_main_synchronization_context = WasmEnableThreads ? get_method("InstallMainSynchronizationContext") : undefined; + mono_assert(!WasmEnableThreads || install_main_synchronization_context, "Can't find InstallMainSynchronizationContext method"); const call_entry_point = get_method("CallEntrypoint"); mono_assert(call_entry_point, "Can't find CallEntrypoint method"); const release_js_owned_object_by_gc_handle_method = get_method("ReleaseJSOwnedObjectByGCHandle"); @@ -189,7 +189,7 @@ export function init_managed_exports(): void { Module.stackRestore(sp); } }; - if (MonoWasmThreads && install_main_synchronization_context) { + if (WasmEnableThreads && install_main_synchronization_context) { runtimeHelpers.javaScriptExports.install_main_synchronization_context = () => invoke_method_raw(install_main_synchronization_context); } } diff --git a/src/mono/browser/runtime/marshal-to-cs.ts b/src/mono/browser/runtime/marshal-to-cs.ts index defc56cb0417a9..cd40c514d48ce7 100644 --- a/src/mono/browser/runtime/marshal-to-cs.ts +++ b/src/mono/browser/runtime/marshal-to-cs.ts @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import MonoWasmThreads from "consts:monoWasmThreads"; +import WasmEnableThreads from "consts:wasmEnableThreads"; import BuildConfiguration from "consts:configuration"; import WasmEnableJsInteropByValue from "consts:wasmEnableJsInteropByValue"; @@ -267,7 +267,7 @@ function _marshal_function_to_cs(arg: JSMarshalerArgument, value: Function, _?: const arg3 = get_arg(args, 4); try { - mono_assert(!MonoWasmThreads || !wrapper.isDisposed, "Function is disposed and should not be invoked anymore."); + mono_assert(!WasmEnableThreads || !wrapper.isDisposed, "Function is disposed and should not be invoked anymore."); let arg1_js: any = undefined; let arg2_js: any = undefined; @@ -311,7 +311,7 @@ export class PromiseHolder extends ManagedObject { function _marshal_task_to_cs(arg: JSMarshalerArgument, value: Promise, _?: MarshalerType, res_converter?: MarshalerToCs) { const handleIsPreallocated = get_arg_type(arg) == MarshalerType.TaskPreCreated; if (value === null || value === undefined) { - if (MonoWasmThreads && handleIsPreallocated) { + if (WasmEnableThreads && handleIsPreallocated) { // This is multi-threading return from JSImport with Task result and we can't return synchronously, // because C# caller could be on different thread and sent us an async message. // It already returned pending Task to it's own caller. @@ -336,7 +336,7 @@ function _marshal_task_to_cs(arg: JSMarshalerArgument, value: Promise, _?: (holder as any)[proxy_debug_symbol] = `PromiseHolder with GCHandle ${gc_handle}`; } - if (MonoWasmThreads) + if (WasmEnableThreads) addUnsettledPromise(); function resolve(data: any) { @@ -346,7 +346,7 @@ function _marshal_task_to_cs(arg: JSMarshalerArgument, value: Promise, _?: } try { mono_assert(!holder.isDisposed, "This promise can't be propagated to managed code, because the Task was already freed."); - if (MonoWasmThreads) { + if (WasmEnableThreads) { settleUnsettledPromise(); } // we can unregister the GC handle on JS side @@ -367,7 +367,7 @@ function _marshal_task_to_cs(arg: JSMarshalerArgument, value: Promise, _?: } try { mono_assert(!holder.isDisposed, "This promise can't be propagated to managed code, because the Task was already freed."); - if (MonoWasmThreads) { + if (WasmEnableThreads) { settleUnsettledPromise(); } // we can unregister the GC handle on JS side diff --git a/src/mono/browser/runtime/marshal-to-js.ts b/src/mono/browser/runtime/marshal-to-js.ts index 4eb46d211e1050..327ac664c2a58f 100644 --- a/src/mono/browser/runtime/marshal-to-js.ts +++ b/src/mono/browser/runtime/marshal-to-js.ts @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import MonoWasmThreads from "consts:monoWasmThreads"; +import WasmEnableThreads from "consts:wasmEnableThreads"; import BuildConfiguration from "consts:configuration"; import WasmEnableJsInteropByValue from "consts:wasmEnableJsInteropByValue"; @@ -197,7 +197,7 @@ function _marshal_delegate_to_js(arg: JSMarshalerArgument, _?: MarshalerType, re if (result === null || result === undefined) { // this will create new Function for the C# delegate result = (arg1_js: any, arg2_js: any, arg3_js: any): any => { - mono_assert(!MonoWasmThreads || !result.isDisposed, "Delegate is disposed and should not be invoked anymore."); + mono_assert(!WasmEnableThreads || !result.isDisposed, "Delegate is disposed and should not be invoked anymore."); // arg numbers are shifted by one, the real first is a gc handle of the callback return runtimeHelpers.javaScriptExports.call_delegate(gc_handle, arg1_js, arg2_js, arg3_js, res_converter, arg1_converter, arg2_converter, arg3_converter); }; @@ -349,7 +349,7 @@ export function mono_wasm_resolve_or_reject_promise(args: JSMarshalerArguments): mono_assert(holder, () => `Cannot find Promise for JSHandle ${js_handle}`); holder.resolve_or_reject(type, js_handle, arg_value); - if (MonoWasmThreads) { + if (WasmEnableThreads) { // this works together with AllocHGlobal in JSFunctionBinding.ResolveOrRejectPromise Module._free(args as any); return; @@ -358,7 +358,7 @@ export function mono_wasm_resolve_or_reject_promise(args: JSMarshalerArguments): set_arg_type(exc, MarshalerType.None); } catch (ex: any) { - if (MonoWasmThreads) { + if (WasmEnableThreads) { mono_assert(false, () => `Failed to resolve or reject promise ${ex}`); } marshal_exception_to_cs(exc, ex); diff --git a/src/mono/browser/runtime/marshal.ts b/src/mono/browser/runtime/marshal.ts index bf4c5145badd47..bfb02fb9bacc6e 100644 --- a/src/mono/browser/runtime/marshal.ts +++ b/src/mono/browser/runtime/marshal.ts @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import MonoWasmThreads from "consts:monoWasmThreads"; +import WasmEnableThreads from "consts:wasmEnableThreads"; import { js_owned_gc_handle_symbol, teardown_managed_proxy } from "./gc-handles"; import { Module, loaderHelpers, mono_assert, runtimeHelpers } from "./globals"; @@ -42,7 +42,7 @@ export function is_args_exception(args: JSMarshalerArguments): boolean { } export function set_args_context(args: JSMarshalerArguments): void { - if (!MonoWasmThreads) return; + if (!WasmEnableThreads) return; mono_assert(args, "Null args"); const exc = get_arg(args, 0); const res = get_arg(args, 1); @@ -263,7 +263,7 @@ export function get_arg_js_handle(arg: JSMarshalerArgument): JSHandle { } export function set_arg_proxy_context(arg: JSMarshalerArgument): void { - if (!MonoWasmThreads) return; + if (!WasmEnableThreads) return; mono_assert(arg, "Null arg"); setI32(arg + 16, runtimeHelpers.proxy_context_gc_handle); } @@ -349,7 +349,7 @@ export class ManagedError extends Error implements IDisposable { if (this.managed_stack) { return this.managed_stack; } - if (loaderHelpers.is_runtime_running() && (!MonoWasmThreads || runtimeHelpers.proxy_context_gc_handle)) { + if (loaderHelpers.is_runtime_running() && (!WasmEnableThreads || runtimeHelpers.proxy_context_gc_handle)) { const gc_handle = (this)[js_owned_gc_handle_symbol]; if (gc_handle !== GCHandleNull) { const managed_stack = runtimeHelpers.javaScriptExports.get_managed_stack_trace(gc_handle); diff --git a/src/mono/browser/runtime/memory.ts b/src/mono/browser/runtime/memory.ts index 5f3314ad510ebf..0ae04672797cf2 100644 --- a/src/mono/browser/runtime/memory.ts +++ b/src/mono/browser/runtime/memory.ts @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import MonoWasmThreads from "consts:monoWasmThreads"; +import WasmEnableThreads from "consts:wasmEnableThreads"; import { MemOffset, NumberOrPointer } from "./types/internal"; import { VoidPtr, CharPtr } from "./types/emscripten"; @@ -324,7 +324,7 @@ export function getEnv(name: string): string | null { const BuiltinAtomics = globalThis.Atomics; -export const Atomics = MonoWasmThreads ? { +export const Atomics = WasmEnableThreads ? { storeI32(offset: MemOffset, value: number): void { BuiltinAtomics.store(localHeapViewI32(), offset >>> 2, value); }, @@ -393,7 +393,7 @@ export function localHeapViewF64(): Float64Array { // when we run with multithreading enabled, we need to make sure that the memory views are updated on each worker // on non-MT build, this will be a no-op trimmed by rollup export function receiveWorkerHeapViews() { - if (!MonoWasmThreads) return; + if (!WasmEnableThreads) return; const memory = runtimeHelpers.getMemory(); if (memory.buffer !== Module.HEAPU8.buffer) { runtimeHelpers.updateMemoryViews(); @@ -403,7 +403,7 @@ export function receiveWorkerHeapViews() { const sharedArrayBufferDefined = typeof SharedArrayBuffer !== "undefined"; export function isSharedArrayBuffer(buffer: any): buffer is SharedArrayBuffer { // this condition should be eliminated by rollup on non-threading builds - if (!MonoWasmThreads) return false; + if (!WasmEnableThreads) return false; // BEWARE: In some cases, `instanceof SharedArrayBuffer` returns false even though buffer is an SAB. // Patch adapted from https://github.com/emscripten-core/emscripten/pull/16994 // See also https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag @@ -417,7 +417,7 @@ This is likely V8 bug. We don't have direct evidence, just failed debugger unit */ export function forceThreadMemoryViewRefresh() { // this condition should be eliminated by rollup on non-threading builds and it would become empty method. - if (!MonoWasmThreads) return; + if (!WasmEnableThreads) return; const wasmMemory = runtimeHelpers.getMemory(); diff --git a/src/mono/browser/runtime/polyfills.ts b/src/mono/browser/runtime/polyfills.ts index 0a2a075cd7bc6d..7aae92566b34a0 100644 --- a/src/mono/browser/runtime/polyfills.ts +++ b/src/mono/browser/runtime/polyfills.ts @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import MonoWasmThreads from "consts:monoWasmThreads"; +import WasmEnableThreads from "consts:wasmEnableThreads"; import type { EmscriptenReplacements } from "./types/internal"; import type { TypedArray } from "./types/emscripten"; import { ENVIRONMENT_IS_NODE, ENVIRONMENT_IS_WORKER, INTERNAL, Module, loaderHelpers, runtimeHelpers } from "./globals"; @@ -33,14 +33,14 @@ export function initializeReplacements(replacements: EmscriptenReplacements): vo replacements.ENVIRONMENT_IS_WORKER = ENVIRONMENT_IS_WORKER; // threads - if (MonoWasmThreads && replacements.modulePThread) { + if (WasmEnableThreads && replacements.modulePThread) { replaceEmscriptenPThreadLibrary(replacements.modulePThread); } } export async function init_polyfills_async(): Promise { // v8 shell doesn't have Event and EventTarget - if (MonoWasmThreads && typeof globalThis.Event === "undefined") { + if (WasmEnableThreads && typeof globalThis.Event === "undefined") { globalThis.Event = class Event { readonly type: string; constructor(type: string) { @@ -48,7 +48,7 @@ export async function init_polyfills_async(): Promise { } } as any; } - if (MonoWasmThreads && typeof globalThis.EventTarget === "undefined") { + if (WasmEnableThreads && typeof globalThis.EventTarget === "undefined") { globalThis.EventTarget = class EventTarget { private subscribers = new Map>(); addEventListener(type: string, listener: EventListenerOrEventListenerObject | null, options?: boolean | AddEventListenerOptions) { diff --git a/src/mono/browser/runtime/pthreads/browser/index.ts b/src/mono/browser/runtime/pthreads/browser/index.ts index 2ff00afe4eda9f..dc719948666aa4 100644 --- a/src/mono/browser/runtime/pthreads/browser/index.ts +++ b/src/mono/browser/runtime/pthreads/browser/index.ts @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import MonoWasmThreads from "consts:monoWasmThreads"; +import WasmEnableThreads from "consts:wasmEnableThreads"; import { monoSymbol, makeMonoThreadMessageApplyMonoConfig, isMonoWorkerMessagePreload, MonoWorkerMessage, isMonoWorkerMessageEnabledInterop, isMonoWorkerMessageChannelCreated } from "../shared"; import { pthreadPtr } from "../shared/types"; @@ -31,7 +31,7 @@ const threadPromises: Map[]> = new Map(); /// wait until the thread with the given id has set up a message port to the runtime export function waitForThread(pthreadPtr: pthreadPtr): Promise { - if (!MonoWasmThreads) return null as any; + if (!WasmEnableThreads) return null as any; if (threads.has(pthreadPtr)) { return Promise.resolve(threads.get(pthreadPtr)!); @@ -47,7 +47,7 @@ export function waitForThread(pthreadPtr: pthreadPtr): Promise { } function resolvePromises(pthreadPtr: pthreadPtr, thread: Thread): void { - if (!MonoWasmThreads) return; + if (!WasmEnableThreads) return; const arr = threadPromises.get(pthreadPtr); if (arr !== undefined) { arr.forEach((controller) => controller.resolve(thread)); @@ -56,7 +56,7 @@ function resolvePromises(pthreadPtr: pthreadPtr, thread: Thread): void { } function addThread(pthreadPtr: pthreadPtr, worker: Worker, port: MessagePort): Thread { - if (!MonoWasmThreads) return null as any; + if (!WasmEnableThreads) return null as any; const thread = new ThreadImpl(pthreadPtr, worker, port); threads.set(pthreadPtr, thread); return thread; @@ -68,7 +68,7 @@ function removeThread(pthreadPtr: pthreadPtr): void { /// Given a thread id, return the thread object with the worker where the thread is running, and a message port. export function getThread(pthreadPtr: pthreadPtr): Thread | undefined { - if (!MonoWasmThreads) return null as any; + if (!WasmEnableThreads) return null as any; const thread = threads.get(pthreadPtr); if (thread === undefined) { return undefined; @@ -93,7 +93,7 @@ function monoDedicatedChannelMessageFromWorkerToMain(event: MessageEvent): void { - if (!MonoWasmThreads) return; + if (!WasmEnableThreads) return; /// N.B. important to ignore messages we don't recognize - Emscripten uses the message event to send internal messages const data = ev.data; if (isMonoWorkerMessagePreload(data)) { @@ -120,7 +120,7 @@ let pendingWorkerLoad: PromiseAndController | undefined; /// Called by Emscripten internals on the browser thread when a new pthread worker is created and added to the pthread worker pool. /// At this point the worker doesn't have any pthread assigned to it, yet. export function onWorkerLoadInitiated(worker: Worker, loaded: Promise): void { - if (!MonoWasmThreads) return; + if (!WasmEnableThreads) return; worker.addEventListener("message", (ev) => monoWorkerMessageHandler(worker, ev)); if (pendingWorkerLoad == undefined) { pendingWorkerLoad = createPromiseController(); @@ -134,7 +134,7 @@ export function onWorkerLoadInitiated(worker: Worker, loaded: Promise): } export function thread_available(): Promise { - if (!MonoWasmThreads) return null as any; + if (!WasmEnableThreads) return null as any; if (pendingWorkerLoad == undefined) { return Promise.resolve(); } @@ -145,7 +145,7 @@ export function thread_available(): Promise { /// At this point asset resolution needs to be working (ie we loaded MonoConfig). /// This is used instead of the Emscripten PThread.initMainThread because we call it later. export function preAllocatePThreadWorkerPool(pthreadPoolSize: number): void { - if (!MonoWasmThreads) return; + if (!WasmEnableThreads) return; for (let i = 0; i < pthreadPoolSize; i++) { Internals.allocateUnusedWorker(); } @@ -157,7 +157,7 @@ export function preAllocatePThreadWorkerPool(pthreadPoolSize: number): void { /// This is used instead of the Emscripten "receiveInstance" in "createWasm" because that code is /// conditioned on a non-zero PTHREAD_POOL_SIZE (but we set it to 0 to avoid early worker allocation). export async function instantiateWasmPThreadWorkerPool(): Promise { - if (!MonoWasmThreads) return null as any; + if (!WasmEnableThreads) return null as any; // this is largely copied from emscripten's "receiveInstance" in "createWasm" in "src/preamble.js" const workers = Internals.getUnusedWorkerPool(); if (workers.length > 0) { diff --git a/src/mono/browser/runtime/pthreads/shared/emscripten-internals.ts b/src/mono/browser/runtime/pthreads/shared/emscripten-internals.ts index 0341a16ffc0c67..ddd9b9c2cba473 100644 --- a/src/mono/browser/runtime/pthreads/shared/emscripten-internals.ts +++ b/src/mono/browser/runtime/pthreads/shared/emscripten-internals.ts @@ -3,7 +3,7 @@ import { Module } from "../../globals"; import { pthreadPtr } from "./types"; -import MonoWasmThreads from "consts:monoWasmThreads"; +import WasmEnableThreads from "consts:wasmEnableThreads"; /** @module emscripten-internals accessors to the functions in the emscripten PThreads library, including * the low-level representations of {@linkcode pthreadPtr} thread info structs, etc. @@ -45,7 +45,7 @@ function isRunningPThreadWorker(w: Worker): w is PThreadWorker { } /// These utility functions dig into Emscripten internals -export const Internals = !MonoWasmThreads ? null as any : { +export const Internals = !WasmEnableThreads ? null as any : { get modulePThread(): PThreadLibrary { return (Module).PThread as PThreadLibrary; }, diff --git a/src/mono/browser/runtime/pthreads/shared/emscripten-replacements.ts b/src/mono/browser/runtime/pthreads/shared/emscripten-replacements.ts index 30e150df221339..362d9055a841e7 100644 --- a/src/mono/browser/runtime/pthreads/shared/emscripten-replacements.ts +++ b/src/mono/browser/runtime/pthreads/shared/emscripten-replacements.ts @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import MonoWasmThreads from "consts:monoWasmThreads"; +import WasmEnableThreads from "consts:wasmEnableThreads"; import { onWorkerLoadInitiated } from "../browser"; import { afterThreadInitTLS } from "../worker"; @@ -15,7 +15,7 @@ import { mono_log_warn } from "../../logging"; */ export function replaceEmscriptenPThreadLibrary(modulePThread: PThreadLibrary): void { - if (!MonoWasmThreads) return; + if (!WasmEnableThreads) return; const originalLoadWasmModuleToWorker = modulePThread.loadWasmModuleToWorker; const originalThreadInitTLS = modulePThread.threadInitTLS; @@ -59,7 +59,7 @@ export function is_thread_available() { } function getNewWorker(modulePThread: PThreadLibrary): PThreadWorker { - if (!MonoWasmThreads) return null as any; + if (!WasmEnableThreads) return null as any; if (modulePThread.unusedWorkers.length == 0) { mono_log_warn("Failed to find unused WebWorker, this may deadlock. Please increase the pthreadPoolSize."); @@ -90,7 +90,7 @@ function getNewWorker(modulePThread: PThreadLibrary): PThreadWorker { /// We replace Module["PThreads"].allocateUnusedWorker with this version that knows about assets function allocateUnusedWorker(): PThreadWorker { - if (!MonoWasmThreads) return null as any; + if (!WasmEnableThreads) return null as any; const asset = loaderHelpers.resolve_single_asset_path("js-module-threads"); const uri = asset.resolvedUrl; diff --git a/src/mono/browser/runtime/pthreads/shared/index.ts b/src/mono/browser/runtime/pthreads/shared/index.ts index 0024e09f1e4c89..7796eece2d6b0f 100644 --- a/src/mono/browser/runtime/pthreads/shared/index.ts +++ b/src/mono/browser/runtime/pthreads/shared/index.ts @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import MonoWasmThreads from "consts:monoWasmThreads"; +import WasmEnableThreads from "consts:wasmEnableThreads"; import BuildConfiguration from "consts:configuration"; import { ENVIRONMENT_IS_PTHREAD, Module, mono_assert, runtimeHelpers } from "../../globals"; @@ -160,7 +160,7 @@ export function isMonoWorkerMessagePreload(message: MonoWorkerMessage): message } export function mono_wasm_install_js_worker_interop(context_gc_handle: GCHandle): void { - if (!MonoWasmThreads) return; + if (!WasmEnableThreads) return; bindings_init(); if (!runtimeHelpers.proxy_context_gc_handle) { runtimeHelpers.proxy_context_gc_handle = context_gc_handle; @@ -175,7 +175,7 @@ export function mono_wasm_install_js_worker_interop(context_gc_handle: GCHandle) } export function mono_wasm_uninstall_js_worker_interop(): void { - if (!MonoWasmThreads) return; + if (!WasmEnableThreads) return; mono_assert(runtimeHelpers.mono_wasm_bindings_is_ready, "JS interop is not installed on this worker."); mono_assert(runtimeHelpers.proxy_context_gc_handle, "JSSynchronizationContext is not installed on this worker."); @@ -189,7 +189,7 @@ export function mono_wasm_uninstall_js_worker_interop(): void { // this is just for Debug build of the runtime, making it easier to debug worker threads export function set_thread_info(pthread_ptr: number, isAttached: boolean, hasInterop: boolean, hasSynchronization: boolean): void { - if (MonoWasmThreads && BuildConfiguration === "Debug" && !runtimeHelpers.cspPolicy) { + if (WasmEnableThreads && BuildConfiguration === "Debug" && !runtimeHelpers.cspPolicy) { try { (globalThis as any).monoThreadInfo = new Function(`//# sourceURL=https://WorkerInfo/\r\nconsole.log("tid:0x${pthread_ptr.toString(16)} isAttached:${isAttached} hasInterop:${!!hasInterop} hasSynchronization:${hasSynchronization}" );`); } @@ -200,11 +200,11 @@ export function set_thread_info(pthread_ptr: number, isAttached: boolean, hasInt } export function mono_wasm_pthread_ptr(): number { - if (!MonoWasmThreads) return 0; + if (!WasmEnableThreads) return 0; return (Module)["_pthread_self"](); } export function mono_wasm_main_thread_ptr(): number { - if (!MonoWasmThreads) return 0; + if (!WasmEnableThreads) return 0; return (Module)["_emscripten_main_runtime_thread_id"](); } diff --git a/src/mono/browser/runtime/pthreads/worker/events.ts b/src/mono/browser/runtime/pthreads/worker/events.ts index 692b2fd0a191ab..faff2f22c0ae0a 100644 --- a/src/mono/browser/runtime/pthreads/worker/events.ts +++ b/src/mono/browser/runtime/pthreads/worker/events.ts @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import MonoWasmThreads from "consts:monoWasmThreads"; +import WasmEnableThreads from "consts:wasmEnableThreads"; import type { pthreadPtr } from "../shared/types"; import type { PThreadInfo, MonoThreadMessage } from "../shared"; @@ -39,7 +39,7 @@ export interface WorkerThreadEventTarget extends EventTarget { } let WorkerThreadEventClassConstructor: new (type: keyof WorkerThreadEventMap, pthread_self: PThreadSelf) => WorkerThreadEvent; -export const makeWorkerThreadEvent: (type: keyof WorkerThreadEventMap, pthread_self: PThreadSelf) => WorkerThreadEvent = !MonoWasmThreads +export const makeWorkerThreadEvent: (type: keyof WorkerThreadEventMap, pthread_self: PThreadSelf) => WorkerThreadEvent = !WasmEnableThreads ? (() => { throw new Error("threads support disabled"); }) : ((type: keyof WorkerThreadEventMap, pthread_self: PThreadSelf) => { if (!WorkerThreadEventClassConstructor) WorkerThreadEventClassConstructor = class WorkerThreadEventImpl extends Event implements WorkerThreadEvent { diff --git a/src/mono/browser/runtime/pthreads/worker/index.ts b/src/mono/browser/runtime/pthreads/worker/index.ts index 468c703bf65e95..58ae1a6027f09a 100644 --- a/src/mono/browser/runtime/pthreads/worker/index.ts +++ b/src/mono/browser/runtime/pthreads/worker/index.ts @@ -3,7 +3,7 @@ /// -import MonoWasmThreads from "consts:monoWasmThreads"; +import WasmEnableThreads from "consts:wasmEnableThreads"; import { ENVIRONMENT_IS_PTHREAD, mono_assert, loaderHelpers } from "../../globals"; import { makeChannelCreatedMonoMessage, mono_wasm_pthread_ptr, set_thread_info } from "../shared"; @@ -59,7 +59,7 @@ export let currentWorkerThreadEvents: WorkerThreadEventTarget = undefined as any export function initWorkerThreadEvents() { // treeshake if threads are disabled - currentWorkerThreadEvents = MonoWasmThreads ? new globalThis.EventTarget() : null as any as WorkerThreadEventTarget; + currentWorkerThreadEvents = WasmEnableThreads ? new globalThis.EventTarget() : null as any as WorkerThreadEventTarget; } // this is the message handler for the worker that receives messages from the main thread @@ -70,7 +70,7 @@ function monoDedicatedChannelMessageFromMainToWorker(event: MessageEvent function setupChannelToMainThread(pthread_ptr: pthreadPtr): PThreadSelf { - if (!MonoWasmThreads) return null as any; + if (!WasmEnableThreads) return null as any; const channel = new MessageChannel(); const workerPort = channel.port1; const mainPort = channel.port2; @@ -85,7 +85,7 @@ function setupChannelToMainThread(pthread_ptr: pthreadPtr): PThreadSelf { /// This is an implementation detail function. /// Called in the worker thread (not main thread) from mono when a pthread becomes attached to the mono runtime. export function mono_wasm_pthread_on_pthread_attached(pthread_id: number): void { - if (!MonoWasmThreads) return; + if (!WasmEnableThreads) return; mono_assert(pthread_self !== null && pthread_self.pthreadId == pthread_id, "expected pthread_self to be set already when attaching"); const threadName = `0x${pthread_id.toString(16)}-worker`; mono_set_thread_name(threadName); @@ -98,7 +98,7 @@ export function mono_wasm_pthread_on_pthread_attached(pthread_id: number): void /// Called in the worker thread (not main thread) from mono when a pthread becomes detached from the mono runtime. export function mono_wasm_pthread_on_pthread_detached(pthread_id: number): void { - if (!MonoWasmThreads) return; + if (!WasmEnableThreads) return; postRunWorker(); set_thread_info(pthread_id, false, false, false); const threadName = `0x${pthread_id.toString(16)}-worker-detached`; @@ -110,7 +110,7 @@ export function mono_wasm_pthread_on_pthread_detached(pthread_id: number): void /// Called by emscripten when a pthread is setup to run on a worker. Can be called multiple times /// for the same worker, since emscripten can reuse workers. This is an implementation detail, that shouldn't be used directly. export function afterThreadInitTLS(): void { - if (!MonoWasmThreads) return; + if (!WasmEnableThreads) return; // don't do this callback for the main thread if (ENVIRONMENT_IS_PTHREAD) { const pthread_ptr = mono_wasm_pthread_ptr(); diff --git a/src/mono/browser/runtime/rollup.config.js b/src/mono/browser/runtime/rollup.config.js index 769d6a01518ae2..111b07fd55846b 100644 --- a/src/mono/browser/runtime/rollup.config.js +++ b/src/mono/browser/runtime/rollup.config.js @@ -19,7 +19,7 @@ const isContinuousIntegrationBuild = process.env.ContinuousIntegrationBuild === const productVersion = process.env.ProductVersion || "8.0.0-dev"; const nativeBinDir = process.env.NativeBinDir ? process.env.NativeBinDir.replace(/"/g, "") : "bin"; const wasmObjDir = process.env.WasmObjDir ? process.env.WasmObjDir.replace(/"/g, "") : "obj"; -const monoWasmThreads = process.env.MonoWasmThreads === "true" ? true : false; +const wasmEnableThreads = process.env.WasmEnableThreads === "true" ? true : false; const wasmEnableSIMD = process.env.WASM_ENABLE_SIMD === "1" ? true : false; const wasmEnableExceptionHandling = process.env.WASM_ENABLE_EH === "1" ? true : false; const wasmEnableJsInteropByValue = process.env.ENABLE_JS_INTEROP_BY_VALUE == "1" ? true : false; @@ -97,7 +97,7 @@ try { const envConstants = { productVersion, configuration, - monoWasmThreads, + wasmEnableThreads, wasmEnableSIMD, wasmEnableExceptionHandling, monoDiagnosticsMock, diff --git a/src/mono/browser/runtime/scheduling.ts b/src/mono/browser/runtime/scheduling.ts index 5b598861e4938f..69412b79473291 100644 --- a/src/mono/browser/runtime/scheduling.ts +++ b/src/mono/browser/runtime/scheduling.ts @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import MonoWasmThreads from "consts:monoWasmThreads"; +import WasmEnableThreads from "consts:wasmEnableThreads"; import cwraps from "./cwraps"; import { ENVIRONMENT_IS_WORKER, Module, loaderHelpers } from "./globals"; @@ -61,7 +61,7 @@ export function schedule_background_exec(): void { } } - if (MonoWasmThreads && !ENVIRONMENT_IS_WORKER) { + if (WasmEnableThreads && !ENVIRONMENT_IS_WORKER) { // give threads chance to load before we run more synchronous code on UI thread postpone_schedule_background(); } @@ -78,7 +78,7 @@ export function mono_wasm_schedule_timer(shortestDueTimeMs: number): void { // NOTE: Multi-threaded Module.safeSetTimeout() does the runtimeKeepalivePush() // and non-Multi-threaded Module.safeSetTimeout does not runtimeKeepalivePush() // but clearTimeout does not runtimeKeepalivePop() so we need to do it here in MT only. - if (MonoWasmThreads) Module.runtimeKeepalivePop(); + if (WasmEnableThreads) Module.runtimeKeepalivePop(); } lastScheduledTimeoutId = Module.safeSetTimeout(mono_wasm_schedule_timer_tick, shortestDueTimeMs); } diff --git a/src/mono/browser/runtime/snapshot.ts b/src/mono/browser/runtime/snapshot.ts index 7375c3399352f4..abc8ee756674c1 100644 --- a/src/mono/browser/runtime/snapshot.ts +++ b/src/mono/browser/runtime/snapshot.ts @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. import ProductVersion from "consts:productVersion"; -import MonoWasmThreads from "consts:monoWasmThreads"; +import WasmEnableThreads from "consts:wasmEnableThreads"; import { ENVIRONMENT_IS_WEB, loaderHelpers, runtimeHelpers } from "./globals"; import { mono_log_warn } from "./logging"; @@ -116,7 +116,7 @@ export async function storeCacheEntry(cacheKey: string, memory: ArrayBuffer, mim if (!cache) { return; } - const copy = MonoWasmThreads + const copy = WasmEnableThreads // storing SHaredArrayBuffer in the cache is not working ? (new Uint8Array(memory)).slice(0) : memory; diff --git a/src/mono/browser/runtime/startup.ts b/src/mono/browser/runtime/startup.ts index 55088f67fe72a0..3d666656cafac2 100644 --- a/src/mono/browser/runtime/startup.ts +++ b/src/mono/browser/runtime/startup.ts @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import MonoWasmThreads from "consts:monoWasmThreads"; +import WasmEnableThreads from "consts:wasmEnableThreads"; import { DotnetModuleInternal, CharPtrNull } from "./types/internal"; import { ENVIRONMENT_IS_NODE, exportedRuntimeAPI, INTERNAL, loaderHelpers, Module, runtimeHelpers, createPromiseController, mono_assert, linkerWasmEnableSIMD, linkerWasmEnableEH, ENVIRONMENT_IS_WORKER } from "./globals"; @@ -233,7 +233,7 @@ async function onRuntimeInitializedAsync(userOnRuntimeInitialized: () => void) { // Threads early are not supported with memory snapshot. See below how we enable them later. // Please disable startupMemoryCache in order to be able to diagnose or pause runtime startup. - if (MonoWasmThreads && !runtimeHelpers.config.startupMemoryCache) { + if (WasmEnableThreads && !runtimeHelpers.config.startupMemoryCache) { await mono_wasm_init_threads(); } @@ -270,7 +270,7 @@ async function onRuntimeInitializedAsync(userOnRuntimeInitialized: () => void) { FS.chdir(cwd); } - if (MonoWasmThreads && runtimeHelpers.config.startupMemoryCache) { + if (WasmEnableThreads && runtimeHelpers.config.startupMemoryCache) { await mono_wasm_init_threads(); } @@ -282,7 +282,7 @@ async function onRuntimeInitializedAsync(userOnRuntimeInitialized: () => void) { Module.runtimeKeepalivePush(); } - if (MonoWasmThreads) { + if (WasmEnableThreads) { runtimeHelpers.javaScriptExports.install_main_synchronization_context(); } @@ -327,7 +327,7 @@ async function postRunAsync(userpostRun: (() => void)[]) { Module["FS_createPath"]("/", "usr", true, true); Module["FS_createPath"]("/", "usr/share", true, true); - if (MonoWasmThreads) { + if (WasmEnableThreads) { tcwraps.mono_wasm_init_finalizer_thread(); } @@ -351,7 +351,7 @@ export function postRunWorker() { } async function mono_wasm_init_threads() { - if (!MonoWasmThreads) { + if (!WasmEnableThreads) { return; } const threadName = `0x${mono_wasm_main_thread_ptr().toString(16)}-main`; @@ -389,7 +389,7 @@ async function mono_wasm_pre_init_essential_async(): Promise { mono_log_debug("mono_wasm_pre_init_essential_async"); Module.addRunDependency("mono_wasm_pre_init_essential_async"); - if (MonoWasmThreads) { + if (WasmEnableThreads) { preAllocatePThreadWorkerPool(runtimeHelpers.config.pthreadPoolSize!); } diff --git a/src/mono/browser/runtime/web-socket.ts b/src/mono/browser/runtime/web-socket.ts index 8f95dee771311f..f8399891a53422 100644 --- a/src/mono/browser/runtime/web-socket.ts +++ b/src/mono/browser/runtime/web-socket.ts @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import MonoWasmThreads from "consts:monoWasmThreads"; +import WasmEnableThreads from "consts:wasmEnableThreads"; import { prevent_timer_throttling } from "./scheduling"; import { Queue } from "./queue"; @@ -398,7 +398,7 @@ function _mono_wasm_web_socket_send_buffering(ws: WebSocketExtension, buffer_vie else { if (length !== 0) { // we could use the un-pinned view, because it will be immediately used in ws.send() - if (MonoWasmThreads) { + if (WasmEnableThreads) { buffer = buffer_view.slice(); // copy, because the provided ArrayBufferView value must not be shared. } else { buffer = buffer_view; @@ -456,7 +456,7 @@ type Message = { } function resolvedPromise(): Promise | null { - if (!MonoWasmThreads) { + if (!WasmEnableThreads) { // signal that we are finished synchronously // this is optimization, which doesn't allocate and doesn't require to marshal resolve() call to C# side. return null; diff --git a/src/mono/mono.proj b/src/mono/mono.proj index 86e9c2d168468d..3b0ade6bd89ccb 100644 --- a/src/mono/mono.proj +++ b/src/mono/mono.proj @@ -8,7 +8,7 @@ - MonoAOTEnableLLVM - enable LLVM for an AOT-only Mono - MonoVerboseBuild - enable verbose build - MonoThreadSuspend - coop,hybrid,preemptive - default thread suspend mode - - MonoWasmThreads - build runtime with threading support for wasm + - WasmEnableThreads - build runtime with threading support for wasm --> @@ -51,8 +51,6 @@ <_CompilerTargetArch Condition="'$(AotHostArchitecture)' != ''">$(AotHostArchitecture) $([MSBuild]::NormalizeDirectory('$(RepositoryEngineeringDir)', 'common')) $([MSBuild]::NormalizePath('$(RepositoryEngineeringCommonDir)', 'cross', 'toolchain.cmake')) - false - true $(runtimelinuxx64MicrosoftNETCoreRuntimeMonoLLVMSdkVersion.Substring(0, $(runtimelinuxx64MicrosoftNETCoreRuntimeMonoLLVMSdkVersion.IndexOf('.')))) true @@ -428,7 +426,7 @@ <_MonoMinimal Condition="'$(Configuration)' == 'Release'">,debugger_agent,log_dest <_MonoMinimal Condition="'$(Configuration)' == 'Release' and '$(MonoEnableAssertMessages)' != 'true'">$(_MonoMinimal),assert_messages - <_MonoMinimal Condition="'$(MonoWasmThreads)' != 'true'">$(_MonoMinimal),threads + <_MonoMinimal Condition="'$(WasmEnableThreads)' != 'true'">$(_MonoMinimal),threads <_MonoCMakeArgs Include="-DENABLE_MINIMAL=jit,sgen_major_marksweep_conc,sgen_split_nursery,sgen_gc_bridge,sgen_toggleref,sgen_debug_helpers,sgen_binary_protocol,logging,interpreter,qcalls$(_MonoMinimal)"/> @@ -437,18 +435,18 @@ <_MonoCMakeArgs Include="-DENABLE_ICALL_EXPORT=1"/> <_MonoCMakeArgs Include="-DENABLE_LAZY_GC_THREAD_CREATION=1"/> <_MonoCMakeArgs Include="-DENABLE_WEBCIL=1"/> - <_MonoCFLAGS Condition="'$(MonoWasmThreads)' == 'true'" Include="-pthread"/> - <_MonoCFLAGS Condition="'$(MonoWasmThreads)' == 'true'" Include="-D_GNU_SOURCE=1" /> - <_MonoCXXFLAGS Condition="'$(MonoWasmThreads)' == 'true'" Include="-pthread"/> - <_MonoCXXFLAGS Condition="'$(MonoWasmThreads)' == 'true'" Include="-D_GNU_SOURCE=1" /> + <_MonoCFLAGS Condition="'$(WasmEnableThreads)' == 'true'" Include="-pthread"/> + <_MonoCFLAGS Condition="'$(WasmEnableThreads)' == 'true'" Include="-D_GNU_SOURCE=1" /> + <_MonoCXXFLAGS Condition="'$(WasmEnableThreads)' == 'true'" Include="-pthread"/> + <_MonoCXXFLAGS Condition="'$(WasmEnableThreads)' == 'true'" Include="-D_GNU_SOURCE=1" /> <_MonoCMakeArgs Include="-DENABLE_LLVM_RUNTIME=1"/> <_MonoCMakeArgs Include="-DEMSCRIPTEN_SYSTEM_PROCESSOR=wasm"/> - <_MonoCFLAGS Condition="'$(MonoWasmThreads)' == 'true'" Include="$(EscapedQuoteW)-I$([MSBuild]::NormalizePath('$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)', 'runtimes', 'browser-wasm-threads', 'native', 'include'))$(EscapedQuoteW)"/> + <_MonoCFLAGS Condition="'$(WasmEnableThreads)' == 'true'" Include="$(EscapedQuoteW)-I$([MSBuild]::NormalizePath('$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)', 'runtimes', 'browser-wasm-threads', 'native', 'include'))$(EscapedQuoteW)"/> - <_MonoCFLAGS Condition="'$(MonoWasmThreads)' != 'true'" Include="$(EscapedQuoteW)-I$([MSBuild]::NormalizePath('$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)', 'runtimes', 'browser-wasm', 'native', 'include'))$(EscapedQuoteW)"/> + <_MonoCFLAGS Condition="'$(WasmEnableThreads)' != 'true'" Include="$(EscapedQuoteW)-I$([MSBuild]::NormalizePath('$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)', 'runtimes', 'browser-wasm', 'native', 'include'))$(EscapedQuoteW)"/> @@ -463,8 +461,8 @@ <_MonoCFLAGS Include="-D_WASI_EMULATED_PROCESS_CLOCKS"/> <_MonoCFLAGS Include="-D_WASI_EMULATED_SIGNAL"/> <_MonoCFLAGS Include="-D_WASI_EMULATED_MMAN"/> - <_MonoCFLAGS Condition="'$(MonoWasmThreads)' == 'true'" Include="$(EscapedQuoteW)-I$([MSBuild]::NormalizePath('$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)', 'runtimes', 'wasi-wasm-threads', 'native', 'include').Replace('\','/'))$(EscapedQuoteW)"/> - <_MonoCFLAGS Condition="'$(MonoWasmThreads)' != 'true'" Include="$(EscapedQuoteW)-I$([MSBuild]::NormalizePath('$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)', 'runtimes', 'wasi-wasm', 'native', 'include').Replace('\','/'))$(EscapedQuoteW)"/> + <_MonoCFLAGS Condition="'$(WasmEnableThreads)' == 'true'" Include="$(EscapedQuoteW)-I$([MSBuild]::NormalizePath('$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)', 'runtimes', 'wasi-wasm-threads', 'native', 'include').Replace('\','/'))$(EscapedQuoteW)"/> + <_MonoCFLAGS Condition="'$(WasmEnableThreads)' != 'true'" Include="$(EscapedQuoteW)-I$([MSBuild]::NormalizePath('$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)', 'runtimes', 'wasi-wasm', 'native', 'include').Replace('\','/'))$(EscapedQuoteW)"/> From 788264068986e3fdf977a727731b1a671ec866da Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz <32700855+ilonatommy@users.noreply.github.com> Date: Wed, 31 Jan 2024 13:30:56 +0000 Subject: [PATCH 07/18] Rename --- .../src/System.Linq.Parallel.csproj | 4 ++-- .../System.Net.Http/src/System.Net.Http.csproj | 4 ++-- .../src/System.Net.WebSockets.Client.csproj | 4 ++-- .../ref/System.Private.CoreLib.csproj | 4 ++-- .../src/System.Private.CoreLib.Shared.projitems | 4 ++-- ...tem.Runtime.InteropServices.JavaScript.csproj | 10 +++++----- ...ntime.InteropServices.JavaScript.Tests.csproj | 8 ++++---- .../src/System.Threading.Tasks.Parallel.csproj | 4 ++-- ...Threading.Thread.WebAssembly.Threading.csproj | 4 ++-- ...ading.ThreadPool.WebAssembly.Threading.csproj | 4 ++-- .../ref/System.Threading.ThreadPool.csproj | 2 +- ...System.Threading.WebAssembly.Threading.csproj | 4 ++-- .../System.Threading/src/System.Threading.csproj | 4 ++-- .../System.Private.CoreLib.csproj | 16 ++++++++-------- src/mono/browser/build/WasmApp.InTree.props | 2 +- src/mono/wasi/build/WasiApp.InTree.props | 2 +- src/mono/wasm/threads.md | 2 +- 17 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/libraries/System.Linq.Parallel/src/System.Linq.Parallel.csproj b/src/libraries/System.Linq.Parallel/src/System.Linq.Parallel.csproj index b5195b98476fe1..d4f6341422a0f7 100644 --- a/src/libraries/System.Linq.Parallel/src/System.Linq.Parallel.csproj +++ b/src/libraries/System.Linq.Parallel/src/System.Linq.Parallel.csproj @@ -8,8 +8,8 @@ $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) - true - $(DefineConstants);FEATURE_WASM_THREADS + true + $(DefineConstants);FEATURE_WASM_THREADS diff --git a/src/libraries/System.Net.Http/src/System.Net.Http.csproj b/src/libraries/System.Net.Http/src/System.Net.Http.csproj index 8096caadb6f75e..73474880af3d21 100644 --- a/src/libraries/System.Net.Http/src/System.Net.Http.csproj +++ b/src/libraries/System.Net.Http/src/System.Net.Http.csproj @@ -11,7 +11,7 @@ $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) SR.PlatformNotSupported_NetHttp - true + true $(DefineConstants);SYSNETHTTP_NO_OPENSSL $(DefineConstants);TARGET_MOBILE $(DefineConstants);TARGET_ANDROID @@ -20,7 +20,7 @@ $(DefineConstants);TARGET_TVOS $(DefineConstants);TARGET_BROWSER $(DefineConstants);TARGET_WASI - $(DefineConstants);FEATURE_WASM_THREADS + $(DefineConstants);FEATURE_WASM_THREADS true diff --git a/src/libraries/System.Net.WebSockets.Client/src/System.Net.WebSockets.Client.csproj b/src/libraries/System.Net.WebSockets.Client/src/System.Net.WebSockets.Client.csproj index a595540c1eddbb..c8ba9fee2b1061 100644 --- a/src/libraries/System.Net.WebSockets.Client/src/System.Net.WebSockets.Client.csproj +++ b/src/libraries/System.Net.WebSockets.Client/src/System.Net.WebSockets.Client.csproj @@ -9,9 +9,9 @@ $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) - true + true $(DefineConstants);TARGET_BROWSER - $(DefineConstants);FEATURE_WASM_THREADS + $(DefineConstants);FEATURE_WASM_THREADS true diff --git a/src/libraries/System.Private.CoreLib/ref/System.Private.CoreLib.csproj b/src/libraries/System.Private.CoreLib/ref/System.Private.CoreLib.csproj index c8ebd686e4e39b..4a63af867c5ca9 100644 --- a/src/libraries/System.Private.CoreLib/ref/System.Private.CoreLib.csproj +++ b/src/libraries/System.Private.CoreLib/ref/System.Private.CoreLib.csproj @@ -11,9 +11,9 @@ SilverlightPlatform true true - true + true $(DefineConstants);FEATURE_WASM_PERFTRACING - $(DefineConstants);FEATURE_WASM_THREADS + $(DefineConstants);FEATURE_WASM_THREADS $(DefineConstants);BUILDING_CORELIB_REFERENCE false diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems index e46bd04f7d6958..9fc91793b70654 100644 --- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems +++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems @@ -2666,13 +2666,13 @@ - + - + diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System.Runtime.InteropServices.JavaScript.csproj b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System.Runtime.InteropServices.JavaScript.csproj index 9173921e3607e1..1e68bcebbb8c80 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System.Runtime.InteropServices.JavaScript.csproj +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System.Runtime.InteropServices.JavaScript.csproj @@ -11,10 +11,10 @@ $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) SR.SystemRuntimeInteropServicesJavaScript_PlatformNotSupported - true - true + true + true false - $(DefineConstants);FEATURE_WASM_THREADS + $(DefineConstants);FEATURE_WASM_THREADS $(DefineConstants);ENABLE_JS_INTEROP_BY_VALUE true @@ -64,8 +64,8 @@ - - + + diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System.Runtime.InteropServices.JavaScript.Tests.csproj b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System.Runtime.InteropServices.JavaScript.Tests.csproj index 5c1cc3aa3b18c0..a92784e30e2086 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System.Runtime.InteropServices.JavaScript.Tests.csproj +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System.Runtime.InteropServices.JavaScript.Tests.csproj @@ -8,8 +8,8 @@ $(WasmXHarnessArgs) --engine-arg=--expose-gc --web-server-use-cop true true - true - $(DefineConstants);FEATURE_WASM_THREADS + true + $(DefineConstants);FEATURE_WASM_THREADS true @@ -31,12 +31,12 @@ - + - + diff --git a/src/libraries/System.Threading.Tasks.Parallel/src/System.Threading.Tasks.Parallel.csproj b/src/libraries/System.Threading.Tasks.Parallel/src/System.Threading.Tasks.Parallel.csproj index f03190f3aa87c5..03b1f303bed216 100644 --- a/src/libraries/System.Threading.Tasks.Parallel/src/System.Threading.Tasks.Parallel.csproj +++ b/src/libraries/System.Threading.Tasks.Parallel/src/System.Threading.Tasks.Parallel.csproj @@ -8,8 +8,8 @@ $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) - true - $(DefineConstants);FEATURE_WASM_THREADS + true + $(DefineConstants);FEATURE_WASM_THREADS diff --git a/src/libraries/System.Threading.Thread.WebAssembly.Threading/ref/System.Threading.Thread.WebAssembly.Threading.csproj b/src/libraries/System.Threading.Thread.WebAssembly.Threading/ref/System.Threading.Thread.WebAssembly.Threading.csproj index ef7dc37aac2bba..a5805dc57bad7c 100644 --- a/src/libraries/System.Threading.Thread.WebAssembly.Threading/ref/System.Threading.Thread.WebAssembly.Threading.csproj +++ b/src/libraries/System.Threading.Thread.WebAssembly.Threading/ref/System.Threading.Thread.WebAssembly.Threading.csproj @@ -2,7 +2,7 @@ $(NetCoreAppCurrent) - true + true System.Threading.Thread true @@ -11,7 +11,7 @@ false Microsoft true - $(DefineConstants);FEATURE_WASM_THREADS + $(DefineConstants);FEATURE_WASM_THREADS diff --git a/src/libraries/System.Threading.ThreadPool.WebAssembly.Threading/ref/System.Threading.ThreadPool.WebAssembly.Threading.csproj b/src/libraries/System.Threading.ThreadPool.WebAssembly.Threading/ref/System.Threading.ThreadPool.WebAssembly.Threading.csproj index b7721040498a28..370e00b99272cc 100644 --- a/src/libraries/System.Threading.ThreadPool.WebAssembly.Threading/ref/System.Threading.ThreadPool.WebAssembly.Threading.csproj +++ b/src/libraries/System.Threading.ThreadPool.WebAssembly.Threading/ref/System.Threading.ThreadPool.WebAssembly.Threading.csproj @@ -3,14 +3,14 @@ System.Threading.ThreadPool true $(NetCoreAppCurrent) - true + true true false Microsoft true - $(DefineConstants);FEATURE_WASM_THREADS + $(DefineConstants);FEATURE_WASM_THREADS diff --git a/src/libraries/System.Threading.ThreadPool/ref/System.Threading.ThreadPool.csproj b/src/libraries/System.Threading.ThreadPool/ref/System.Threading.ThreadPool.csproj index 4c918c153ba698..c7c5d2c26ecfb0 100644 --- a/src/libraries/System.Threading.ThreadPool/ref/System.Threading.ThreadPool.csproj +++ b/src/libraries/System.Threading.ThreadPool/ref/System.Threading.ThreadPool.csproj @@ -2,7 +2,7 @@ $(NetCoreAppCurrent) true - $(DefineConstants);FEATURE_WASM_THREADS + $(DefineConstants);FEATURE_WASM_THREADS diff --git a/src/libraries/System.Threading.WebAssembly.Threading/ref/System.Threading.WebAssembly.Threading.csproj b/src/libraries/System.Threading.WebAssembly.Threading/ref/System.Threading.WebAssembly.Threading.csproj index b4d819a041fee6..3f0a38381ff0f6 100644 --- a/src/libraries/System.Threading.WebAssembly.Threading/ref/System.Threading.WebAssembly.Threading.csproj +++ b/src/libraries/System.Threading.WebAssembly.Threading/ref/System.Threading.WebAssembly.Threading.csproj @@ -2,7 +2,7 @@ $(NetCoreAppCurrent) - true + true System.Threading true @@ -11,7 +11,7 @@ false Microsoft true - $(DefineConstants);FEATURE_WASM_THREADS + $(DefineConstants);FEATURE_WASM_THREADS diff --git a/src/libraries/System.Threading/src/System.Threading.csproj b/src/libraries/System.Threading/src/System.Threading.csproj index 16c23cee899d4a..34e367ac90a399 100644 --- a/src/libraries/System.Threading/src/System.Threading.csproj +++ b/src/libraries/System.Threading/src/System.Threading.csproj @@ -6,8 +6,8 @@ true true false - true - $(DefineConstants);FEATURE_WASM_THREADS + true + $(DefineConstants);FEATURE_WASM_THREADS diff --git a/src/mono/System.Private.CoreLib/System.Private.CoreLib.csproj b/src/mono/System.Private.CoreLib/System.Private.CoreLib.csproj index 2a59776edc57e2..7c9012951a4f5f 100644 --- a/src/mono/System.Private.CoreLib/System.Private.CoreLib.csproj +++ b/src/mono/System.Private.CoreLib/System.Private.CoreLib.csproj @@ -13,8 +13,8 @@ x64;x86;arm;armv6;arm64;riscv64;s390x;wasm;ppc64le true - true - $(DefineConstants);FEATURE_WASM_THREADS + true + $(DefineConstants);FEATURE_WASM_THREADS @@ -122,10 +122,10 @@ $(DefineConstants);MONO_FEATURE_SRE true - true + true true - true - true + true + true true true @@ -133,7 +133,7 @@ $(DefineConstants);FEATURE_PERFTRACING $(DefineConstants);FEATURE_OBJCMARSHAL - $(DefineConstants);FEATURE_WASM_THREADS + $(DefineConstants);FEATURE_WASM_THREADS $(DefineConstants);FEATURE_WASM_PERFTRACING @@ -274,7 +274,7 @@ - + @@ -282,7 +282,7 @@ - + diff --git a/src/mono/browser/build/WasmApp.InTree.props b/src/mono/browser/build/WasmApp.InTree.props index 4e56c8fe5e5c6a..951aeca06948e3 100644 --- a/src/mono/browser/build/WasmApp.InTree.props +++ b/src/mono/browser/build/WasmApp.InTree.props @@ -29,7 +29,7 @@ <_MonoRuntimeComponentDontLink Include="libmono-component-debugger-stub-static.a" /> - <_MonoRuntimeComponentDontLink Include="libmono-component-diagnostics_tracing-static.a" Condition="'$(FeatureWasmPerfTracing)' != 'true' and $(FeatureWasmThreads) != 'true'"/> + <_MonoRuntimeComponentDontLink Include="libmono-component-diagnostics_tracing-static.a" Condition="'$(FeatureWasmPerfTracing)' != 'true' and $(FeatureWasmManagedThreads) != 'true'"/> <_MonoRuntimeComponentDontLink Include="libmono-component-hot_reload-stub-static.a" /> <_MonoRuntimeComponentDontLink Include="libmono-component-marshal-ilgen-stub-static.a" /> diff --git a/src/mono/wasi/build/WasiApp.InTree.props b/src/mono/wasi/build/WasiApp.InTree.props index 2d2124c33699a8..894b17f646e38c 100644 --- a/src/mono/wasi/build/WasiApp.InTree.props +++ b/src/mono/wasi/build/WasiApp.InTree.props @@ -15,7 +15,7 @@ <_MonoRuntimeComponentDontLink Include="libmono-component-debugger-stub-static.a" /> - <_MonoRuntimeComponentDontLink Include="libmono-component-diagnostics_tracing-static.a" Condition="'$(FeatureWasmPerfTracing)' != 'true' and $(FeatureWasmThreads) != 'true'"/> + <_MonoRuntimeComponentDontLink Include="libmono-component-diagnostics_tracing-static.a" Condition="'$(FeatureWasmPerfTracing)' != 'true' and $(FeatureWasmManagedThreads) != 'true'"/> <_MonoRuntimeComponentDontLink Include="libmono-component-hot_reload-stub-static.a" /> <_MonoRuntimeComponentDontLink Include="libmono-component-marshal-ilgen-stub-static.a" /> diff --git a/src/mono/wasm/threads.md b/src/mono/wasm/threads.md index ebf1fe68c0b341..409d8de4c972d4 100644 --- a/src/mono/wasm/threads.md +++ b/src/mono/wasm/threads.md @@ -11,7 +11,7 @@ This also works with released versions of .NET 7 or later and the `wasmbrowser` ## Libraries feature defines ## -We use the `FeatureWasmThreads` property in the libraries projects to conditionally define +We use the `FeatureWasmManagedThreads` property in the libraries projects to conditionally define `FEATURE_WASM_THREADS` which is used to affect how the libraries are built for the multi-threaded runtime. From 46528326084161d025af68a1f12045bfe711f276 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz <32700855+ilonatommy@users.noreply.github.com> Date: Wed, 31 Jan 2024 14:23:33 +0000 Subject: [PATCH 08/18] Fix merge errors (defined but not used). --- src/mono/browser/runtime/pthreads/browser/index.ts | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/mono/browser/runtime/pthreads/browser/index.ts b/src/mono/browser/runtime/pthreads/browser/index.ts index ebcf79d780e088..2d97a601ec36d6 100644 --- a/src/mono/browser/runtime/pthreads/browser/index.ts +++ b/src/mono/browser/runtime/pthreads/browser/index.ts @@ -3,11 +3,11 @@ import WasmEnableThreads from "consts:wasmEnableThreads"; -import { MonoWorkerToMainMessage, pthreadPtr } from "../shared/types"; +import { pthreadPtr } from "../shared/types"; import { MonoThreadMessage } from "../shared"; import { PThreadWorker, allocateUnusedWorker, getRunningWorkers, getUnusedWorkerPool, getWorker, loadWasmModuleToWorker } from "../shared/emscripten-internals"; -import { createPromiseController, mono_assert, runtimeHelpers } from "../../globals"; -import { MainToWorkerMessageType, PromiseAndController, PromiseController, WorkerToMainMessageType, monoMessageSymbol } from "../../types/internal"; +import { createPromiseController, runtimeHelpers } from "../../globals"; +import { PromiseAndController, PromiseController } from "../../types/internal"; const threadPromises: Map[]> = new Map(); @@ -17,14 +17,6 @@ export interface Thread { postMessageToWorker(message: T): void; } -class ThreadImpl implements Thread { - constructor(readonly pthreadPtr: pthreadPtr, readonly worker: Worker, readonly port: MessagePort) { } - postMessageToWorker(message: T): void { - this.port.postMessage(message); - } -} - - /// wait until the thread with the given id has set up a message port to the runtime export function waitForThread(pthreadPtr: pthreadPtr): Promise { if (!WasmEnableThreads) return null as any; From 51b738be38dcaefdc178ce41896c426857d81445 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz <32700855+ilonatommy@users.noreply.github.com> Date: Wed, 31 Jan 2024 15:33:44 +0000 Subject: [PATCH 09/18] More merge errors fixed. --- .../browser/runtime/pthreads/browser/index.ts | 75 ++++++++++++++----- .../shared/emscripten-replacements.ts | 2 +- src/mono/browser/runtime/run.ts | 4 +- src/mono/browser/runtime/types/consts.d.ts | 2 +- src/mono/wasi/wasi.proj | 12 +-- 5 files changed, 65 insertions(+), 30 deletions(-) diff --git a/src/mono/browser/runtime/pthreads/browser/index.ts b/src/mono/browser/runtime/pthreads/browser/index.ts index 2d97a601ec36d6..f459508a93ef02 100644 --- a/src/mono/browser/runtime/pthreads/browser/index.ts +++ b/src/mono/browser/runtime/pthreads/browser/index.ts @@ -3,11 +3,11 @@ import WasmEnableThreads from "consts:wasmEnableThreads"; -import { pthreadPtr } from "../shared/types"; +import { MonoWorkerToMainMessage, pthreadPtr } from "../shared/types"; import { MonoThreadMessage } from "../shared"; import { PThreadWorker, allocateUnusedWorker, getRunningWorkers, getUnusedWorkerPool, getWorker, loadWasmModuleToWorker } from "../shared/emscripten-internals"; -import { createPromiseController, runtimeHelpers } from "../../globals"; -import { PromiseAndController, PromiseController } from "../../types/internal"; +import { createPromiseController, mono_assert, runtimeHelpers } from "../../globals"; +import { MainToWorkerMessageType, PromiseAndController, PromiseController, WorkerToMainMessageType, monoMessageSymbol } from "../../types/internal"; const threadPromises: Map[]> = new Map(); @@ -17,6 +17,13 @@ export interface Thread { postMessageToWorker(message: T): void; } +class ThreadImpl implements Thread { + constructor(readonly pthreadPtr: pthreadPtr, readonly worker: Worker, readonly port: MessagePort) { } + postMessageToWorker(message: T): void { + this.port.postMessage(message); + } +} + /// wait until the thread with the given id has set up a message port to the runtime export function waitForThread(pthreadPtr: pthreadPtr): Promise { if (!WasmEnableThreads) return null as any; @@ -50,26 +57,54 @@ export function resolveThreadPromises(pthreadPtr: pthreadPtr, thread?: Thread): } // handler that runs in the main thread when a message is received from a pthread worker -function monoWorkerMessageHandler(worker: Worker, ev: MessageEvent): void { +function monoWorkerMessageHandler(worker: PThreadWorker, ev: MessageEvent): void { if (!WasmEnableThreads) return; - /// N.B. important to ignore messages we don't recognize - Emscripten uses the message event to send internal messages - const data = ev.data; - if (isMonoWorkerMessagePreload(data)) { - const port = data[monoSymbol].port; - port.postMessage(makeMonoThreadMessageApplyMonoConfig(runtimeHelpers.config)); + let pthreadId: pthreadPtr; + // this is emscripten message + if (ev.data.cmd === "killThread") { + pthreadId = ev.data["thread"]; + mono_assert(pthreadId == worker.info.pthreadId, "expected pthreadId to match"); + worker.info.isRunning = false; + worker.info.pthreadId = 0; + return; } - else if (isMonoWorkerMessageChannelCreated(data)) { - const port = data[monoSymbol].port; - const pthreadId = data[monoSymbol].threadId; - const thread = addThread(pthreadId, worker, port); - port.addEventListener("message", (ev) => monoDedicatedChannelMessageFromWorkerToMain(ev, thread)); - port.start(); - resolvePromises(pthreadId, thread); + + const message = ev.data[monoMessageSymbol] as MonoWorkerToMainMessage; + if (message === undefined) { + /// N.B. important to ignore messages we don't recognize - Emscripten uses the message event to send internal messages + return; } - else if (isMonoWorkerMessageEnabledInterop(data)) { - const pthreadId = data[monoSymbol].threadId; - const worker = Internals.getWorker(pthreadId) as PThreadWorker; - worker.interopInstalled = true; + + let port: MessagePort; + let thread: Thread; + pthreadId = message.info?.pthreadId ?? 0; + + switch (message.monoCmd) { + case WorkerToMainMessageType.preload: + // this one shot port from setupPreloadChannelToMainThread + port = message.port!; + port.postMessage({ + type: "pthread", + cmd: MainToWorkerMessageType.applyConfig, + config: JSON.stringify(runtimeHelpers.config) + }); + port.close(); + break; + case WorkerToMainMessageType.pthreadCreated: + port = message.port!; + thread = new ThreadImpl(pthreadId, worker, port); + worker.thread = thread; + worker.info.isRunning = true; + resolveThreadPromises(pthreadId, thread); + // fall through + case WorkerToMainMessageType.monoRegistered: + case WorkerToMainMessageType.monoAttached: + case WorkerToMainMessageType.enabledInterop: + case WorkerToMainMessageType.monoUnRegistered: + worker.info = Object.assign(worker.info!, message.info, {}); + break; + default: + throw new Error(`Unhandled message from worker: ${message.monoCmd}`); } } diff --git a/src/mono/browser/runtime/pthreads/shared/emscripten-replacements.ts b/src/mono/browser/runtime/pthreads/shared/emscripten-replacements.ts index 7bd136be550e4a..1f3647be4b358f 100644 --- a/src/mono/browser/runtime/pthreads/shared/emscripten-replacements.ts +++ b/src/mono/browser/runtime/pthreads/shared/emscripten-replacements.ts @@ -121,7 +121,7 @@ function allocateUnusedWorker(): PThreadWorker { export function dumpThreads(): void { - if (!MonoWasmThreads) return; + if (!WasmEnableThreads) return; // eslint-disable-next-line no-console console.log("Running workers:"); getRunningWorkers().forEach((worker) => { diff --git a/src/mono/browser/runtime/run.ts b/src/mono/browser/runtime/run.ts index 6ba5076e53e219..0b8ab30725e25e 100644 --- a/src/mono/browser/runtime/run.ts +++ b/src/mono/browser/runtime/run.ts @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import MonoWasmThreads from "consts:monoWasmThreads"; +import WasmEnableThreads from "consts:wasmEnableThreads"; import { ENVIRONMENT_IS_NODE, loaderHelpers, mono_assert, runtimeHelpers } from "./globals"; import { mono_wasm_wait_for_debugger } from "./debug"; @@ -89,7 +89,7 @@ export function find_entry_point(assembly: string) { } export function nativeExit(code: number) { - if (MonoWasmThreads) { + if (WasmEnableThreads) { cancelThreads(); } cwraps.mono_wasm_exit(code); diff --git a/src/mono/browser/runtime/types/consts.d.ts b/src/mono/browser/runtime/types/consts.d.ts index 3ada8dc3dcaaeb..7400c15b8bbc04 100644 --- a/src/mono/browser/runtime/types/consts.d.ts +++ b/src/mono/browser/runtime/types/consts.d.ts @@ -7,7 +7,7 @@ declare module "consts:*" { export default constant; } -declare module "consts:monoWasmThreads" { +declare module "consts:wasmEnableThreads" { const constant: boolean; export default constant; } diff --git a/src/mono/wasi/wasi.proj b/src/mono/wasi/wasi.proj index 7b8772070596f3..bd03a1a0e79b44 100644 --- a/src/mono/wasi/wasi.proj +++ b/src/mono/wasi/wasi.proj @@ -6,8 +6,8 @@ - $([MSBuild]::NormalizeDirectory('$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)', 'runtimes', 'wasi-wasm', 'native', 'lib')) - $([MSBuild]::NormalizeDirectory('$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)', 'runtimes', 'wasi-wasm-threads', 'native', 'lib')) + $([MSBuild]::NormalizeDirectory('$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)', 'runtimes', 'wasi-wasm', 'native', 'lib')) + $([MSBuild]::NormalizeDirectory('$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)', 'runtimes', 'wasi-wasm-threads', 'native', 'lib')) false false $(ArtifactsObjDir)wasi @@ -124,15 +124,15 @@ --> - + <_WasiFlags Include="@(_WasiCommonFlags)" /> - <_WasiCompileFlags Condition="'$(MonoWasmThreads)' == 'true'" Include="-I$([MSBuild]::NormalizePath('$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)', 'runtimes', 'wasi-wasm-threads', 'native', 'include').Replace('\','/'))"/> - <_WasiCompileFlags Condition="'$(MonoWasmThreads)' != 'true'" Include="-I$([MSBuild]::NormalizePath('$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)', 'runtimes', 'wasi-wasm', 'native', 'include').Replace('\','/'))"/> + <_WasiCompileFlags Condition="'$(WasmEnableThreads)' == 'true'" Include="-I$([MSBuild]::NormalizePath('$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)', 'runtimes', 'wasi-wasm-threads', 'native', 'include').Replace('\','/'))"/> + <_WasiCompileFlags Condition="'$(WasmEnableThreads)' != 'true'" Include="-I$([MSBuild]::NormalizePath('$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)', 'runtimes', 'wasi-wasm', 'native', 'include').Replace('\','/'))"/> <_WasiCompileFlags Include="-I$([MSBuild]::NormalizePath('$(WasiProjectRoot)', 'include').Replace('\','/'))"/> <_WasiCompileFlags Include="-I$([MSBuild]::NormalizePath('$(WasiProjectRoot)', 'mono-include').Replace('\','/'))"/> <_WasiCompileFlags Include="-I$([MSBuild]::NormalizePath('$(RepoRoot)', 'src', 'native', 'public').Replace('\','/'))"/> @@ -217,7 +217,7 @@ $(CMakeBuildRuntimeConfigureCmd) -DNATIVE_BIN_DIR="$(NativeBinDir.TrimEnd('\/'))" $(CMakeBuildRuntimeConfigureCmd) -DCONFIGURATION_COMPILE_OPTIONS="-msimd128" -DCONFIGURATION_INTERPSIMDTABLES_LIB="simd" $(CMakeBuildRuntimeConfigureCmd) -DCONFIGURATION_INTERPSIMDTABLES_LIB="nosimd" - $(CMakeBuildRuntimeConfigureCmd) -DDISABLE_THREADS=0 + $(CMakeBuildRuntimeConfigureCmd) -DDISABLE_THREADS=0 call "$(RepositoryEngineeringDir)native\init-vs-env.cmd" wasm && $(CMakeBuildRuntimeConfigureCmd) -v From 7c205db39a553c4e0544c55f288d4f3f1783ca82 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz <32700855+ilonatommy@users.noreply.github.com> Date: Thu, 1 Feb 2024 09:23:27 +0000 Subject: [PATCH 10/18] Feedback. --- .../src/Interop/Browser/Interop.Runtime.cs | 2 +- .../src/System.Linq.Parallel.csproj | 2 +- .../Parallel/Channels/AsynchronousChannel.cs | 2 +- .../AsynchronousChannelMergeEnumerator.cs | 2 +- .../Linq/Parallel/Merging/MergeExecutor.cs | 2 +- .../OrderPreservingPipeliningMergeHelper.cs | 2 +- .../OrderPreservingPipeliningSpoolingTask.cs | 2 +- .../Linq/Parallel/Scheduling/SpoolingTask.cs | 4 +- .../src/System/Linq/Parallel/Utils/Sorting.cs | 2 +- .../src/System/Linq/ParallelEnumerable.cs | 2 +- .../src/System.Net.Http.csproj | 2 +- .../src/System.Net.WebSockets.Client.csproj | 2 +- .../BrowserWebSockets/BrowserWebSocket.cs | 2 +- .../ref/System.Private.CoreLib.csproj | 2 +- .../System/Threading/ManualResetEventSlim.cs | 12 ++--- .../src/System/Threading/Monitor.cs | 8 +-- .../src/System/Threading/Overlapped.cs | 2 +- .../RegisteredWaitHandle.Portable.cs | 2 +- .../src/System/Threading/Thread.cs | 10 ++-- .../src/System/Threading/ThreadPool.Unix.cs | 2 +- .../System/Threading/ThreadPoolWorkQueue.cs | 16 +++--- ....Runtime.InteropServices.JavaScript.csproj | 2 +- .../JavaScript/CancelablePromise.cs | 4 +- .../JavaScript/Interop/JavaScriptExports.cs | 12 ++--- .../Interop/JavaScriptImports.Generated.cs | 2 +- .../InteropServices/JavaScript/JSException.cs | 2 +- .../JavaScript/JSFunctionBinding.cs | 16 +++--- .../JavaScript/JSHostImplementation.Types.cs | 2 +- .../JavaScript/JSHostImplementation.cs | 4 +- .../JavaScript/JSMarshalerArgument.cs | 10 ++-- .../JavaScript/JSObject.References.cs | 4 +- .../JavaScript/JSProxyContext.cs | 14 +++--- .../JavaScript/JSSynchronizationContext.cs | 2 +- .../InteropServices/JavaScript/JSWebWorker.cs | 2 +- .../JSMarshalerArgument.Exception.cs | 2 +- .../Marshaling/JSMarshalerArgument.Func.cs | 16 +++--- .../JSMarshalerArgument.JSObject.cs | 2 +- .../Marshaling/JSMarshalerArgument.Task.cs | 22 ++++---- ...me.InteropServices.JavaScript.Tests.csproj | 2 +- .../JavaScript/JSImportExportTest.cs | 8 +-- .../JavaScript/JavaScriptTestHelper.cs | 2 +- .../System.Threading.Tasks.Parallel.csproj | 2 +- .../src/System/Threading/Tasks/Parallel.cs | 2 +- .../System/Threading/Tasks/TaskReplicator.cs | 2 +- ...eading.Thread.WebAssembly.Threading.csproj | 2 +- .../ref/System.Threading.Thread.cs | 8 +-- ...ng.ThreadPool.WebAssembly.Threading.csproj | 2 +- .../ref/System.Threading.ThreadPool.cs | 18 +++---- .../ref/System.Threading.ThreadPool.csproj | 2 +- ...tem.Threading.WebAssembly.Threading.csproj | 2 +- .../System.Threading/ref/System.Threading.cs | 50 +++++++++---------- .../src/System.Threading.csproj | 2 +- .../src/System/Threading/Barrier.cs | 18 +++---- .../src/System/Threading/CountdownEvent.cs | 12 ++--- .../System.Private.CoreLib.csproj | 4 +- .../src/System/Threading/Monitor.Mono.cs | 2 +- .../Threading/ThreadPool.Browser.Mono.cs | 4 +- .../System/Threading/ThreadPool.Wasi.Mono.cs | 4 +- src/mono/browser/build/BrowserWasmApp.targets | 2 +- src/mono/wasm/threads.md | 4 +- 60 files changed, 177 insertions(+), 177 deletions(-) diff --git a/src/libraries/Common/src/Interop/Browser/Interop.Runtime.cs b/src/libraries/Common/src/Interop/Browser/Interop.Runtime.cs index 61786b5b33748b..bdfe0efa092b07 100644 --- a/src/libraries/Common/src/Interop/Browser/Interop.Runtime.cs +++ b/src/libraries/Common/src/Interop/Browser/Interop.Runtime.cs @@ -27,7 +27,7 @@ internal static unsafe partial class Runtime public static extern void DeregisterGCRoot(nint handle); #endif -#if FEATURE_WASM_THREADS +#if FEATURE_WASM_MANAGED_THREADS [MethodImpl(MethodImplOptions.InternalCall)] public static extern void InstallWebWorkerInterop(nint proxyContextGCHandle); [MethodImpl(MethodImplOptions.InternalCall)] diff --git a/src/libraries/System.Linq.Parallel/src/System.Linq.Parallel.csproj b/src/libraries/System.Linq.Parallel/src/System.Linq.Parallel.csproj index d4f6341422a0f7..3d7f38289ac0aa 100644 --- a/src/libraries/System.Linq.Parallel/src/System.Linq.Parallel.csproj +++ b/src/libraries/System.Linq.Parallel/src/System.Linq.Parallel.csproj @@ -9,7 +9,7 @@ $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) true - $(DefineConstants);FEATURE_WASM_THREADS + $(DefineConstants);FEATURE_WASM_MANAGED_THREADS diff --git a/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Channels/AsynchronousChannel.cs b/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Channels/AsynchronousChannel.cs index d00c969e0f8aa6..775228fb66c5f0 100644 --- a/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Channels/AsynchronousChannel.cs +++ b/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Channels/AsynchronousChannel.cs @@ -17,7 +17,7 @@ namespace System.Linq.Parallel /// This is a bounded channel meant for single-producer/single-consumer scenarios. /// /// Specifies the type of data in the channel. -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] #endif internal sealed class AsynchronousChannel : IDisposable diff --git a/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Merging/AsynchronousChannelMergeEnumerator.cs b/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Merging/AsynchronousChannelMergeEnumerator.cs index b6c6d837379c53..9b101fb7891327 100644 --- a/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Merging/AsynchronousChannelMergeEnumerator.cs +++ b/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Merging/AsynchronousChannelMergeEnumerator.cs @@ -26,7 +26,7 @@ namespace System.Linq.Parallel /// /// /// -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] #endif internal sealed class AsynchronousChannelMergeEnumerator : MergeEnumerator diff --git a/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Merging/MergeExecutor.cs b/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Merging/MergeExecutor.cs index d6cb9a58245d6d..11bf7fd5a233ab 100644 --- a/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Merging/MergeExecutor.cs +++ b/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Merging/MergeExecutor.cs @@ -141,7 +141,7 @@ public IEnumerator GetEnumerator() // An array of asynchronous channels, one for each partition. // -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] #endif internal static AsynchronousChannel[] MakeAsynchronousChannels(int partitionCount, ParallelMergeOptions options, IntValueEvent? consumerEvent, CancellationToken cancellationToken) diff --git a/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Merging/OrderPreservingPipeliningMergeHelper.cs b/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Merging/OrderPreservingPipeliningMergeHelper.cs index b964a36048977a..2846d016ebb4e3 100644 --- a/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Merging/OrderPreservingPipeliningMergeHelper.cs +++ b/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Merging/OrderPreservingPipeliningMergeHelper.cs @@ -36,7 +36,7 @@ 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. /// -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] #endif internal sealed class OrderPreservingPipeliningMergeHelper : IMergeHelper diff --git a/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Scheduling/OrderPreservingPipeliningSpoolingTask.cs b/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Scheduling/OrderPreservingPipeliningSpoolingTask.cs index ac5d9ea432b9f9..0e0e81ee6448a7 100644 --- a/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Scheduling/OrderPreservingPipeliningSpoolingTask.cs +++ b/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Scheduling/OrderPreservingPipeliningSpoolingTask.cs @@ -18,7 +18,7 @@ namespace System.Linq.Parallel { -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] #endif internal sealed class OrderPreservingPipeliningSpoolingTask : SpoolingTaskBase diff --git a/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Scheduling/SpoolingTask.cs b/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Scheduling/SpoolingTask.cs index 45e44d2be18eb8..2a796d57aabae1 100644 --- a/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Scheduling/SpoolingTask.cs +++ b/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Scheduling/SpoolingTask.cs @@ -82,7 +82,7 @@ internal static void SpoolStopAndGo( // taskScheduler - the task manager on which to execute // -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] #endif internal static void SpoolPipeline( @@ -264,7 +264,7 @@ protected override void SpoolingFinally() /// /// /// -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] #endif internal sealed class PipelineSpoolingTask : SpoolingTaskBase diff --git a/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Utils/Sorting.cs b/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Utils/Sorting.cs index d475e7e8f20242..33288424eff27f 100644 --- a/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Utils/Sorting.cs +++ b/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Utils/Sorting.cs @@ -351,7 +351,7 @@ private void QuickSortIndicesInPlace(GrowingArray keys, List // negatively impact speedups. // -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] #endif private void MergeSortCooperatively() diff --git a/src/libraries/System.Linq.Parallel/src/System/Linq/ParallelEnumerable.cs b/src/libraries/System.Linq.Parallel/src/System/Linq/ParallelEnumerable.cs index a3e760b465929c..55ef371ea04226 100644 --- a/src/libraries/System.Linq.Parallel/src/System/Linq/ParallelEnumerable.cs +++ b/src/libraries/System.Linq.Parallel/src/System/Linq/ParallelEnumerable.cs @@ -64,7 +64,7 @@ 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 +#if !FEATURE_WASM_MANAGED_THREADS [System.Runtime.Versioning.SupportedOSPlatformGuard("browser")] internal static bool SinglePartitionMode => OperatingSystem.IsBrowser(); #else diff --git a/src/libraries/System.Net.Http/src/System.Net.Http.csproj b/src/libraries/System.Net.Http/src/System.Net.Http.csproj index 73474880af3d21..7955744b6207e4 100644 --- a/src/libraries/System.Net.Http/src/System.Net.Http.csproj +++ b/src/libraries/System.Net.Http/src/System.Net.Http.csproj @@ -20,7 +20,7 @@ $(DefineConstants);TARGET_TVOS $(DefineConstants);TARGET_BROWSER $(DefineConstants);TARGET_WASI - $(DefineConstants);FEATURE_WASM_THREADS + $(DefineConstants);FEATURE_WASM_MANAGED_THREADS true diff --git a/src/libraries/System.Net.WebSockets.Client/src/System.Net.WebSockets.Client.csproj b/src/libraries/System.Net.WebSockets.Client/src/System.Net.WebSockets.Client.csproj index c8ba9fee2b1061..da4bb6f79b829d 100644 --- a/src/libraries/System.Net.WebSockets.Client/src/System.Net.WebSockets.Client.csproj +++ b/src/libraries/System.Net.WebSockets.Client/src/System.Net.WebSockets.Client.csproj @@ -11,7 +11,7 @@ $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) true $(DefineConstants);TARGET_BROWSER - $(DefineConstants);FEATURE_WASM_THREADS + $(DefineConstants);FEATURE_WASM_MANAGED_THREADS true diff --git a/src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/BrowserWebSockets/BrowserWebSocket.cs b/src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/BrowserWebSockets/BrowserWebSocket.cs index c635a3d48aad81..478de9846cc254 100644 --- a/src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/BrowserWebSockets/BrowserWebSocket.cs +++ b/src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/BrowserWebSockets/BrowserWebSocket.cs @@ -268,7 +268,7 @@ static void Cleanup(object? _state) self.responseStatusHandle?.Dispose(); } -#if FEATURE_WASM_THREADS +#if FEATURE_WASM_MANAGED_THREADS // if this is finalizer thread, we need to postpone the abort -> dispose _innerWebSocket?.SynchronizationContext.Post(Cleanup, this); #else diff --git a/src/libraries/System.Private.CoreLib/ref/System.Private.CoreLib.csproj b/src/libraries/System.Private.CoreLib/ref/System.Private.CoreLib.csproj index 4a63af867c5ca9..82024e3887fd18 100644 --- a/src/libraries/System.Private.CoreLib/ref/System.Private.CoreLib.csproj +++ b/src/libraries/System.Private.CoreLib/ref/System.Private.CoreLib.csproj @@ -13,7 +13,7 @@ true true $(DefineConstants);FEATURE_WASM_PERFTRACING - $(DefineConstants);FEATURE_WASM_THREADS + $(DefineConstants);FEATURE_WASM_MANAGED_THREADS $(DefineConstants);BUILDING_CORELIB_REFERENCE false diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/ManualResetEventSlim.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/ManualResetEventSlim.cs index b049a9aaeebeb4..a385543f9174ab 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/ManualResetEventSlim.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/ManualResetEventSlim.cs @@ -344,7 +344,7 @@ 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. /// -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [UnsupportedOSPlatform("browser")] #endif public void Wait() @@ -367,7 +367,7 @@ 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. /// -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [UnsupportedOSPlatform("browser")] #endif public void Wait(CancellationToken cancellationToken) @@ -390,7 +390,7 @@ public void Wait(CancellationToken cancellationToken) /// /// The maximum number of waiters has been exceeded. /// -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [UnsupportedOSPlatform("browser")] #endif public bool Wait(TimeSpan timeout) @@ -423,7 +423,7 @@ public bool Wait(TimeSpan timeout) /// /// The maximum number of waiters has been exceeded. /// -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [UnsupportedOSPlatform("browser")] #endif public bool Wait(TimeSpan timeout, CancellationToken cancellationToken) @@ -449,7 +449,7 @@ public bool Wait(TimeSpan timeout, CancellationToken cancellationToken) /// /// The maximum number of waiters has been exceeded. /// -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [UnsupportedOSPlatform("browser")] #endif public bool Wait(int millisecondsTimeout) @@ -475,7 +475,7 @@ public bool Wait(int millisecondsTimeout) /// /// was canceled. -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [UnsupportedOSPlatform("browser")] #endif public bool Wait(int millisecondsTimeout, CancellationToken cancellationToken) diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Monitor.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Monitor.cs index 8fe478a52dc9ab..c40c38dab4f0f0 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/Monitor.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Monitor.cs @@ -13,25 +13,25 @@ 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 +#if !FEATURE_WASM_MANAGED_THREADS [UnsupportedOSPlatform("browser")] #endif public static bool Wait(object obj, TimeSpan timeout) => Wait(obj, WaitHandle.ToTimeoutMilliseconds(timeout)); -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_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 +#if !FEATURE_WASM_MANAGED_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 +#if !FEATURE_WASM_MANAGED_THREADS [UnsupportedOSPlatform("browser")] #endif public static bool Wait(object obj, TimeSpan timeout, bool exitContext) diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Overlapped.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Overlapped.cs index 29446e444073c4..a4dae77a751166 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/Overlapped.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Overlapped.cs @@ -184,7 +184,7 @@ public static void Free(NativeOverlapped* nativeOverlappedPtr) _pNativeOverlapped = pNativeOverlapped; #if FEATURE_PERFTRACING -#if !((TARGET_BROWSER || TARGET_WASI) && !FEATURE_WASM_THREADS) +#if !((TARGET_BROWSER || TARGET_WASI) && !FEATURE_WASM_MANAGED_THREADS) if (NativeRuntimeEventSource.Log.IsEnabled()) NativeRuntimeEventSource.Log.ThreadPoolIOPack(pNativeOverlapped); #endif diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/RegisteredWaitHandle.Portable.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/RegisteredWaitHandle.Portable.cs index b5672e243282ea..2fb8d1fb3f63ca 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/RegisteredWaitHandle.Portable.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/RegisteredWaitHandle.Portable.cs @@ -10,7 +10,7 @@ namespace System.Threading /// /// An object representing the registration of a via . /// -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [UnsupportedOSPlatform("browser")] #endif public sealed partial class RegisteredWaitHandle : MarshalByRefObject diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Thread.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Thread.cs index aeed0604c301f0..0c1c65348fa501 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/Thread.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Thread.cs @@ -147,7 +147,7 @@ public Thread(ParameterizedThreadStart start, int maxStackSize) Initialize(); } -#if (!TARGET_BROWSER && !TARGET_WASI) || FEATURE_WASM_THREADS +#if (!TARGET_BROWSER && !TARGET_WASI) || FEATURE_WASM_MANAGED_THREADS [UnsupportedOSPlatformGuard("browser")] internal static bool IsThreadStartSupported => true; internal static bool IsInternalThreadStartSupported => true; @@ -175,7 +175,7 @@ internal static void ThrowIfNoThreadStart(bool internalThread = false) /// The thread has already been started. /// There is not enough memory available to start this thread. /// This thread was created using a delegate instead of a delegate. -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [UnsupportedOSPlatform("browser")] #endif public void Start(object? parameter) => Start(parameter, captureContext: true); @@ -189,7 +189,7 @@ internal static void ThrowIfNoThreadStart(bool internalThread = false) /// Unlike , which captures the current and uses that context to invoke the thread's delegate, /// explicitly avoids capturing the current context and flowing it to the invocation. /// -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [UnsupportedOSPlatform("browser")] #endif public void UnsafeStart(object? parameter) => Start(parameter, captureContext: false); @@ -220,7 +220,7 @@ private void Start(object? parameter, bool captureContext, bool internalThread = /// Causes the operating system to change the state of the current instance to . /// The thread has already been started. /// There is not enough memory available to start this thread. -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [UnsupportedOSPlatform("browser")] #endif public void Start() => Start(captureContext: true); @@ -232,7 +232,7 @@ private void Start(object? parameter, bool captureContext, bool internalThread = /// Unlike , which captures the current and uses that context to invoke the thread's delegate, /// explicitly avoids capturing the current context and flowing it to the invocation. /// -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [UnsupportedOSPlatform("browser")] #endif public void UnsafeStart() => Start(captureContext: false); diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPool.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPool.Unix.cs index 3c5888a6f80dbd..83faa720e3974a 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPool.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPool.Unix.cs @@ -16,7 +16,7 @@ public static partial class ThreadPool AppContextConfigHelper.GetBooleanConfig("System.Threading.ThreadPool.EnableWorkerTracking", "DOTNET_ThreadPool_EnableWorkerTracking"); #endif -#if !(TARGET_BROWSER && FEATURE_WASM_THREADS) +#if !(TARGET_BROWSER && FEATURE_WASM_MANAGED_THREADS) // Indicates whether the thread pool should yield the thread from the dispatch loop to the runtime periodically so that // the runtime may use the thread for processing other work. internal static bool YieldFromDispatchLoop => false; diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs index 9e4a2420c7edb1..cc7c76922d9964 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs @@ -1368,7 +1368,7 @@ public static partial class ThreadPool internal static bool EnableWorkerTracking => IsWorkerTrackingEnabledInConfig && EventSource.IsSupported; -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [UnsupportedOSPlatform("browser")] #endif [CLSCompliant(false)] @@ -1385,7 +1385,7 @@ public static RegisteredWaitHandle RegisterWaitForSingleObject( return RegisterWaitForSingleObject(waitObject, callBack, state, millisecondsTimeOutInterval, executeOnlyOnce, true); } -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [UnsupportedOSPlatform("browser")] #endif [CLSCompliant(false)] @@ -1402,7 +1402,7 @@ public static RegisteredWaitHandle UnsafeRegisterWaitForSingleObject( return RegisterWaitForSingleObject(waitObject, callBack, state, millisecondsTimeOutInterval, executeOnlyOnce, false); } -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [UnsupportedOSPlatform("browser")] #endif public static RegisteredWaitHandle RegisterWaitForSingleObject( @@ -1417,7 +1417,7 @@ public static RegisteredWaitHandle RegisterWaitForSingleObject( return RegisterWaitForSingleObject(waitObject, callBack, state, (uint)millisecondsTimeOutInterval, executeOnlyOnce, true); } -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [UnsupportedOSPlatform("browser")] #endif public static RegisteredWaitHandle UnsafeRegisterWaitForSingleObject( @@ -1432,7 +1432,7 @@ public static RegisteredWaitHandle UnsafeRegisterWaitForSingleObject( return RegisterWaitForSingleObject(waitObject, callBack, state, (uint)millisecondsTimeOutInterval, executeOnlyOnce, false); } -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [UnsupportedOSPlatform("browser")] #endif public static RegisteredWaitHandle RegisterWaitForSingleObject( @@ -1448,7 +1448,7 @@ public static RegisteredWaitHandle RegisterWaitForSingleObject( return RegisterWaitForSingleObject(waitObject, callBack, state, (uint)millisecondsTimeOutInterval, executeOnlyOnce, true); } -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [UnsupportedOSPlatform("browser")] #endif public static RegisteredWaitHandle UnsafeRegisterWaitForSingleObject( @@ -1464,7 +1464,7 @@ public static RegisteredWaitHandle UnsafeRegisterWaitForSingleObject( return RegisterWaitForSingleObject(waitObject, callBack, state, (uint)millisecondsTimeOutInterval, executeOnlyOnce, false); } -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [UnsupportedOSPlatform("browser")] #endif public static RegisteredWaitHandle RegisterWaitForSingleObject( @@ -1483,7 +1483,7 @@ bool executeOnlyOnce return RegisterWaitForSingleObject(waitObject, callBack, state, (uint)tm, executeOnlyOnce, true); } -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [UnsupportedOSPlatform("browser")] #endif public static RegisteredWaitHandle UnsafeRegisterWaitForSingleObject( diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System.Runtime.InteropServices.JavaScript.csproj b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System.Runtime.InteropServices.JavaScript.csproj index 1e68bcebbb8c80..2e452abeb199fa 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System.Runtime.InteropServices.JavaScript.csproj +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System.Runtime.InteropServices.JavaScript.csproj @@ -14,7 +14,7 @@ true true false - $(DefineConstants);FEATURE_WASM_THREADS + $(DefineConstants);FEATURE_WASM_MANAGED_THREADS $(DefineConstants);ENABLE_JS_INTEROP_BY_VALUE true diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/CancelablePromise.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/CancelablePromise.cs index aac90359978715..260a78f0c633cf 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/CancelablePromise.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/CancelablePromise.cs @@ -22,7 +22,7 @@ public static void CancelPromise(Task promise) JSHostImplementation.PromiseHolder? holder = promise.AsyncState as JSHostImplementation.PromiseHolder; if (holder == null) throw new InvalidOperationException("Expected Task converted from JS Promise"); -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS if (holder.IsDisposed) { return; @@ -55,7 +55,7 @@ public static void CancelPromise(Task promise, Action callback, T state) JSHostImplementation.PromiseHolder? holder = promise.AsyncState as JSHostImplementation.PromiseHolder; if (holder == null) throw new InvalidOperationException("Expected Task converted from JS Promise"); -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS if (holder.IsDisposed) { return; diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Interop/JavaScriptExports.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Interop/JavaScriptExports.cs index 870b2006fdf33b..b08f7c4da1a9ed 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Interop/JavaScriptExports.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Interop/JavaScriptExports.cs @@ -26,7 +26,7 @@ public static void CallEntrypoint(JSMarshalerArgument* arguments_buffer) ref JSMarshalerArgument arg_2 = ref arguments_buffer[3]; // initialized and set by caller try { -#if FEATURE_WASM_THREADS +#if FEATURE_WASM_MANAGED_THREADS // when we arrive here, we are on the thread which owns the proxies arg_exc.AssertCurrentThreadContext(); #endif @@ -108,7 +108,7 @@ public static void LoadLazyAssembly(JSMarshalerArgument* arguments_buffer) ref JSMarshalerArgument arg_2 = ref arguments_buffer[3]; try { -#if FEATURE_WASM_THREADS +#if FEATURE_WASM_MANAGED_THREADS // when we arrive here, we are on the thread which owns the proxies arg_exc.AssertCurrentThreadContext(); #endif @@ -130,7 +130,7 @@ public static void LoadSatelliteAssembly(JSMarshalerArgument* arguments_buffer) ref JSMarshalerArgument arg_1 = ref arguments_buffer[2]; try { -#if FEATURE_WASM_THREADS +#if FEATURE_WASM_MANAGED_THREADS // when we arrive here, we are on the thread which owns the proxies arg_exc.AssertCurrentThreadContext(); #endif @@ -178,7 +178,7 @@ public static void CallDelegate(JSMarshalerArgument* arguments_buffer) // arg_4 set by JS caller when there are arguments try { -#if FEATURE_WASM_THREADS +#if FEATURE_WASM_MANAGED_THREADS // when we arrive here, we are on the thread which owns the proxies arg_exc.AssertCurrentThreadContext(); #endif @@ -215,7 +215,7 @@ public static void CompleteTask(JSMarshalerArgument* arguments_buffer) var ctx = arg_exc.AssertCurrentThreadContext(); var holder = ctx.GetPromiseHolder(arg_1.slot.GCHandle); -#if FEATURE_WASM_THREADS +#if FEATURE_WASM_MANAGED_THREADS lock (ctx) { if (holder.Callback == null) @@ -271,7 +271,7 @@ public static void GetManagedStackTrace(JSMarshalerArgument* arguments_buffer) } } -#if FEATURE_WASM_THREADS +#if FEATURE_WASM_MANAGED_THREADS // this is here temporarily, until JSWebWorker becomes public API [DynamicDependency(DynamicallyAccessedMemberTypes.NonPublicMethods, "System.Runtime.InteropServices.JavaScript.JSWebWorker", "System.Runtime.InteropServices.JavaScript")] diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Interop/JavaScriptImports.Generated.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Interop/JavaScriptImports.Generated.cs index 77716ab72c0c81..4ab7301e22b362 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Interop/JavaScriptImports.Generated.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Interop/JavaScriptImports.Generated.cs @@ -44,7 +44,7 @@ internal static unsafe partial class JavaScriptImports public static partial JSObject GetDotnetInstance(); [JSImport("INTERNAL.dynamic_import")] public static partial Task DynamicImport(string moduleName, string moduleUrl); -#if FEATURE_WASM_THREADS +#if FEATURE_WASM_MANAGED_THREADS [JSImport("INTERNAL.thread_available")] public static partial Task ThreadAvailable(); #endif diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSException.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSException.cs index 1a9e2278d57caa..eede0b643a6580 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSException.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSException.cs @@ -46,7 +46,7 @@ public override string? StackTrace return bs; } -#if FEATURE_WASM_THREADS +#if FEATURE_WASM_MANAGED_THREADS if (!jsException.ProxyContext.IsCurrentThread()) { // if we are on another thread, it would be too expensive and risky to obtain lazy stack trace. diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSFunctionBinding.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSFunctionBinding.cs index 08619d5325df44..7c39d19df5027c 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSFunctionBinding.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSFunctionBinding.cs @@ -202,7 +202,7 @@ internal static unsafe void InvokeJSFunction(JSObject jsFunction, Span arguments) { -#if FEATURE_WASM_THREADS +#if FEATURE_WASM_MANAGED_THREADS var targetContext = JSProxyContext.SealJSImportCapturing(); arguments[0].slot.ContextHandle = targetContext.ContextHandle; arguments[1].slot.ContextHandle = targetContext.ContextHandle; @@ -280,7 +280,7 @@ internal static unsafe void InvokeJSImportImpl(JSFunctionBinding signature, Span arguments[1].slot.GCHandle = holder.GCHandle; } -#if FEATURE_WASM_THREADS +#if FEATURE_WASM_MANAGED_THREADS // if we are on correct thread already or this is synchronous call, just call it if (targetContext.IsCurrentThread()) { @@ -324,7 +324,7 @@ internal static unsafe void InvokeJSImportCurrent(JSFunctionBinding signature, S { fixed (JSMarshalerArgument* args = arguments) { -#if FEATURE_WASM_THREADS +#if FEATURE_WASM_MANAGED_THREADS Interop.Runtime.InvokeJSImportSync((nint)args, (nint)signature.Header); #else Interop.Runtime.InvokeJSImport(signature.ImportHandle, (nint)args); @@ -338,7 +338,7 @@ internal static unsafe void InvokeJSImportCurrent(JSFunctionBinding signature, S } } -#if FEATURE_WASM_THREADS +#if FEATURE_WASM_MANAGED_THREADS #if !DEBUG [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -387,7 +387,7 @@ internal static unsafe JSFunctionBinding BindJSImportImpl(string functionName, s { var signature = JSHostImplementation.GetMethodSignature(signatures, functionName, moduleName); -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS Interop.Runtime.BindJSImport(signature.Header, out int isException, out object exceptionMessage); if (isException != 0) @@ -415,7 +415,7 @@ internal static unsafe JSFunctionBinding BindManagedFunctionImpl(string fullyQua return signature; } -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static unsafe void ResolveOrRejectPromise(Span arguments) { diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSHostImplementation.Types.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSHostImplementation.Types.cs index 8d4dd3e6a3e877..f093ffb0d8b2e7 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSHostImplementation.Types.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSHostImplementation.Types.cs @@ -16,7 +16,7 @@ public sealed class PromiseHolder public ToManagedCallback? Callback; public JSProxyContext ProxyContext; public bool IsDisposed; -#if FEATURE_WASM_THREADS +#if FEATURE_WASM_MANAGED_THREADS public ManualResetEventSlim? CallbackReady; #endif diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSHostImplementation.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSHostImplementation.cs index 361997414e6e76..3035781eb730f1 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSHostImplementation.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSHostImplementation.cs @@ -147,7 +147,7 @@ public static unsafe JSFunctionBinding GetMethodSignature(ReadOnlySpan JSVHandleFreeList = new(); -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS private JSProxyContext() { } @@ -62,7 +62,7 @@ public JSProxyContext(bool isMainThread, JSSynchronizationContext synchronizatio #region Current operation context -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS public static readonly JSProxyContext MainThreadContext = new(); public static JSProxyContext CurrentThreadContext => MainThreadContext; public static JSProxyContext CurrentOperationContext => MainThreadContext; @@ -229,7 +229,7 @@ public static JSProxyContext CurrentOperationContext [MethodImpl(MethodImplOptions.AggressiveInlining)] public static JSProxyContext AssertIsInteropThread() { -#if FEATURE_WASM_THREADS +#if FEATURE_WASM_MANAGED_THREADS var ctx = CurrentThreadContext; if (ctx == null) { @@ -436,7 +436,7 @@ public static void ReleaseCSOwnedObject(JSObject proxy, bool skipJS) return; } var ctx = proxy.ProxyContext; -#if FEATURE_WASM_THREADS +#if FEATURE_WASM_MANAGED_THREADS if (!ctx.IsCurrentThread()) { throw new InvalidOperationException($"ReleaseCSOwnedObject has to run on the thread with same affinity as the proxy. ManagedThreadId: {Environment.CurrentManagedThreadId} JSHandle: {proxy.JSHandle}"); @@ -477,7 +477,7 @@ private void Dispose(bool disposing) { if (!_isDisposed) { -#if FEATURE_WASM_THREADS +#if FEATURE_WASM_MANAGED_THREADS if (!IsCurrentThread()) { Environment.FailFast($"JSProxyContext must be disposed on the thread which owns it, ManagedThreadId: {Environment.CurrentManagedThreadId}. {Environment.NewLine} {Environment.StackTrace}"); @@ -494,7 +494,7 @@ private void Dispose(bool disposing) } } -#if FEATURE_WASM_THREADS +#if FEATURE_WASM_MANAGED_THREADS Interop.Runtime.UninstallWebWorkerInterop(); #endif @@ -518,7 +518,7 @@ private void Dispose(bool disposing) if (disposing) { -#if FEATURE_WASM_THREADS +#if FEATURE_WASM_MANAGED_THREADS SynchronizationContext.Dispose(); #endif } diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSSynchronizationContext.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSSynchronizationContext.cs index f7fbb7fb5a79c4..6ea7c80b388134 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSSynchronizationContext.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSSynchronizationContext.cs @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -#if FEATURE_WASM_THREADS +#if FEATURE_WASM_MANAGED_THREADS using System.Threading; using System.Threading.Channels; diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSWebWorker.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSWebWorker.cs index ddbf5b8d619e57..27fe38e3f1991d 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSWebWorker.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSWebWorker.cs @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -#if FEATURE_WASM_THREADS +#if FEATURE_WASM_MANAGED_THREADS #pragma warning disable CA1416 diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Marshaling/JSMarshalerArgument.Exception.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Marshaling/JSMarshalerArgument.Exception.cs index d26d4e58dcadd2..e526fe4b52c891 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Marshaling/JSMarshalerArgument.Exception.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Marshaling/JSMarshalerArgument.Exception.cs @@ -68,7 +68,7 @@ public unsafe void ToJS(Exception? value) { var jsException = jse.jsException; jsException.AssertNotDisposed(); -#if FEATURE_WASM_THREADS +#if FEATURE_WASM_MANAGED_THREADS var ctx = jsException.ProxyContext; if (JSProxyContext.CapturingState == JSProxyContext.JSImportOperationState.JSImportParams) diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Marshaling/JSMarshalerArgument.Func.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Marshaling/JSMarshalerArgument.Func.cs index 3f713e15128859..271acab66bae0f 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Marshaling/JSMarshalerArgument.Func.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Marshaling/JSMarshalerArgument.Func.cs @@ -23,7 +23,7 @@ public void InvokeJS() Span arguments = stackalloc JSMarshalerArgument[4]; ref JSMarshalerArgument args_exception = ref arguments[0]; ref JSMarshalerArgument args_return = ref arguments[1]; -#if FEATURE_WASM_THREADS +#if FEATURE_WASM_MANAGED_THREADS args_exception.InitializeWithContext(JSObject.ProxyContext); args_return.InitializeWithContext(JSObject.ProxyContext); JSProxyContext.JSImportNoCapture(); @@ -56,7 +56,7 @@ public void InvokeJS(T arg1) ref JSMarshalerArgument args_return = ref arguments[1]; ref JSMarshalerArgument args_arg1 = ref arguments[2]; -#if FEATURE_WASM_THREADS +#if FEATURE_WASM_MANAGED_THREADS args_exception.InitializeWithContext(JSObject.ProxyContext); args_return.InitializeWithContext(JSObject.ProxyContext); args_arg1.InitializeWithContext(JSObject.ProxyContext); @@ -94,7 +94,7 @@ public void InvokeJS(T1 arg1, T2 arg2) ref JSMarshalerArgument args_arg1 = ref arguments[2]; ref JSMarshalerArgument args_arg2 = ref arguments[3]; -#if FEATURE_WASM_THREADS +#if FEATURE_WASM_MANAGED_THREADS args_exception.InitializeWithContext(JSObject.ProxyContext); args_return.InitializeWithContext(JSObject.ProxyContext); args_arg1.InitializeWithContext(JSObject.ProxyContext); @@ -137,7 +137,7 @@ public void InvokeJS(T1 arg1, T2 arg2, T3 arg3) ref JSMarshalerArgument args_arg2 = ref arguments[3]; ref JSMarshalerArgument args_arg3 = ref arguments[4]; -#if FEATURE_WASM_THREADS +#if FEATURE_WASM_MANAGED_THREADS args_exception.InitializeWithContext(JSObject.ProxyContext); args_return.InitializeWithContext(JSObject.ProxyContext); args_arg1.InitializeWithContext(JSObject.ProxyContext); @@ -261,7 +261,7 @@ public TResult InvokeJS() Span arguments = stackalloc JSMarshalerArgument[4]; ref JSMarshalerArgument args_exception = ref arguments[0]; ref JSMarshalerArgument args_return = ref arguments[1]; -#if FEATURE_WASM_THREADS +#if FEATURE_WASM_MANAGED_THREADS args_exception.InitializeWithContext(JSObject.ProxyContext); args_return.InitializeWithContext(JSObject.ProxyContext); JSProxyContext.JSImportNoCapture(); @@ -300,7 +300,7 @@ public TResult InvokeJS(T arg1) ref JSMarshalerArgument args_return = ref arguments[1]; ref JSMarshalerArgument args_arg1 = ref arguments[2]; -#if FEATURE_WASM_THREADS +#if FEATURE_WASM_MANAGED_THREADS args_exception.InitializeWithContext(JSObject.ProxyContext); args_return.InitializeWithContext(JSObject.ProxyContext); args_arg1.InitializeWithContext(JSObject.ProxyContext); @@ -342,7 +342,7 @@ public TResult InvokeJS(T1 arg1, T2 arg2) ref JSMarshalerArgument args_arg1 = ref arguments[2]; ref JSMarshalerArgument args_arg2 = ref arguments[3]; -#if FEATURE_WASM_THREADS +#if FEATURE_WASM_MANAGED_THREADS args_exception.InitializeWithContext(JSObject.ProxyContext); args_return.InitializeWithContext(JSObject.ProxyContext); args_arg1.InitializeWithContext(JSObject.ProxyContext); @@ -389,7 +389,7 @@ public TResult InvokeJS(T1 arg1, T2 arg2, T3 arg3) ref JSMarshalerArgument args_arg2 = ref arguments[3]; ref JSMarshalerArgument args_arg3 = ref arguments[4]; -#if FEATURE_WASM_THREADS +#if FEATURE_WASM_MANAGED_THREADS args_exception.InitializeWithContext(JSObject.ProxyContext); args_return.InitializeWithContext(JSObject.ProxyContext); args_arg1.InitializeWithContext(JSObject.ProxyContext); diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Marshaling/JSMarshalerArgument.JSObject.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Marshaling/JSMarshalerArgument.JSObject.cs index 7a1d8a2695e554..7eb4440c565d6f 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Marshaling/JSMarshalerArgument.JSObject.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Marshaling/JSMarshalerArgument.JSObject.cs @@ -41,7 +41,7 @@ public void ToJS(JSObject? value) else { value.AssertNotDisposed(); -#if FEATURE_WASM_THREADS +#if FEATURE_WASM_MANAGED_THREADS var ctx = value.ProxyContext; if (JSProxyContext.CapturingState == JSProxyContext.JSImportOperationState.JSImportParams) diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Marshaling/JSMarshalerArgument.Task.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Marshaling/JSMarshalerArgument.Task.cs index d00636cbbfea7d..b4ebf1b115daed 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Marshaling/JSMarshalerArgument.Task.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Marshaling/JSMarshalerArgument.Task.cs @@ -74,7 +74,7 @@ public unsafe void ToManaged(out Task? value) }; holder.Callback = callback; value = tcs.Task; -#if FEATURE_WASM_THREADS +#if FEATURE_WASM_MANAGED_THREADS // if the other thread created it, signal that it's ready holder.CallbackReady?.Set(); #endif @@ -128,7 +128,7 @@ public unsafe void ToManaged(out Task? value, ArgumentToManagedCallback }; holder.Callback = callback; value = tcs.Task; -#if FEATURE_WASM_THREADS +#if FEATURE_WASM_MANAGED_THREADS // if the other thread created it, signal that it's ready holder.CallbackReady?.Set(); #endif @@ -188,7 +188,7 @@ internal void ToJSDynamic(Task? value) var taskHolder = ctx.CreateCSOwnedProxy(slot.JSHandle); -#if FEATURE_WASM_THREADS +#if FEATURE_WASM_MANAGED_THREADS task.ContinueWith(Complete, taskHolder, TaskScheduler.FromCurrentSynchronizationContext()); #else task.ContinueWith(Complete, taskHolder, TaskScheduler.Current); @@ -268,7 +268,7 @@ public void ToJS(Task? value) var taskHolder = ctx.CreateCSOwnedProxy(slot.JSHandle); -#if FEATURE_WASM_THREADS +#if FEATURE_WASM_MANAGED_THREADS task.ContinueWith(Complete, taskHolder, TaskScheduler.FromCurrentSynchronizationContext()); #else task.ContinueWith(Complete, taskHolder, TaskScheduler.Current); @@ -340,7 +340,7 @@ public void ToJS(Task? value, ArgumentToJSCallback marshaler) var taskHolder = ctx.CreateCSOwnedProxy(slot.JSHandle); -#if FEATURE_WASM_THREADS +#if FEATURE_WASM_MANAGED_THREADS task.ContinueWith(Complete, new HolderAndMarshaler(taskHolder, marshaler), TaskScheduler.FromCurrentSynchronizationContext()); #else task.ContinueWith(Complete, new HolderAndMarshaler(taskHolder, marshaler), TaskScheduler.Current); @@ -373,7 +373,7 @@ private static void RejectPromise(JSObject holder, Exception ex) ref JSMarshalerArgument arg_handle = ref args[2]; ref JSMarshalerArgument arg_value = ref args[3]; -#if FEATURE_WASM_THREADS +#if FEATURE_WASM_MANAGED_THREADS exc.InitializeWithContext(holder.ProxyContext); res.InitializeWithContext(holder.ProxyContext); arg_value.InitializeWithContext(holder.ProxyContext); @@ -394,7 +394,7 @@ private static void RejectPromise(JSObject holder, Exception ex) // we can free the JSHandle here and the holder.resolve_or_reject will do the rest holder.DisposeImpl(skipJsCleanup: true); -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS // order of operations with DisposeImpl matters JSFunctionBinding.ResolveOrRejectPromise(args); #else @@ -413,7 +413,7 @@ private static void ResolveVoidPromise(JSObject holder) ref JSMarshalerArgument arg_handle = ref args[2]; ref JSMarshalerArgument arg_value = ref args[3]; -#if FEATURE_WASM_THREADS +#if FEATURE_WASM_MANAGED_THREADS exc.InitializeWithContext(holder.ProxyContext); res.InitializeWithContext(holder.ProxyContext); arg_value.InitializeWithContext(holder.ProxyContext); @@ -433,7 +433,7 @@ private static void ResolveVoidPromise(JSObject holder) // we can free the JSHandle here and the holder.resolve_or_reject will do the rest holder.DisposeImpl(skipJsCleanup: true); -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS // order of operations with DisposeImpl matters JSFunctionBinding.ResolveOrRejectPromise(args); #else @@ -452,7 +452,7 @@ private static void ResolvePromise(JSObject holder, T value, ArgumentToJSCall ref JSMarshalerArgument arg_handle = ref args[2]; ref JSMarshalerArgument arg_value = ref args[3]; -#if FEATURE_WASM_THREADS +#if FEATURE_WASM_MANAGED_THREADS exc.InitializeWithContext(holder.ProxyContext); res.InitializeWithContext(holder.ProxyContext); arg_value.InitializeWithContext(holder.ProxyContext); @@ -473,7 +473,7 @@ private static void ResolvePromise(JSObject holder, T value, ArgumentToJSCall // we can free the JSHandle here and the holder.resolve_or_reject will do the rest holder.DisposeImpl(skipJsCleanup: true); -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS // order of operations with DisposeImpl matters JSFunctionBinding.ResolveOrRejectPromise(args); #else diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System.Runtime.InteropServices.JavaScript.Tests.csproj b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System.Runtime.InteropServices.JavaScript.Tests.csproj index a92784e30e2086..19d2fcef6d4edf 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System.Runtime.InteropServices.JavaScript.Tests.csproj +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System.Runtime.InteropServices.JavaScript.Tests.csproj @@ -9,7 +9,7 @@ true true true - $(DefineConstants);FEATURE_WASM_THREADS + $(DefineConstants);FEATURE_WASM_MANAGED_THREADS true diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JSImportExportTest.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JSImportExportTest.cs index e7e058e120fb48..bd76d9e80f8fd2 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JSImportExportTest.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JSImportExportTest.cs @@ -36,7 +36,7 @@ public async Task MultipleImportAsync() instance1.Dispose(); } -#if !FEATURE_WASM_THREADS // because in MT JSHost.ImportAsync is really async, it will finish before the caller could cancel it +#if !FEATURE_WASM_MANAGED_THREADS // because in MT JSHost.ImportAsync is really async, it will finish before the caller could cancel it [Fact] public async Task CancelableImportAsync() { @@ -185,7 +185,7 @@ public unsafe void CreateFunctionDoubleThrow() var ex = Assert.Throws(() => doubleThrows(1, 2)); Assert.Equal("Error: test 1 2", ex.Message); -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS Assert.Contains("create_function", ex.StackTrace); #else Assert.Contains("omitted JavaScript stack trace", ex.StackTrace); @@ -2004,7 +2004,7 @@ public void JsImportMath() var exThrow0 = Assert.Throws(() => JavaScriptTestHelper.throw0()); Assert.Contains("throw-0-msg", exThrow0.Message); Assert.DoesNotContain(" at ", exThrow0.Message); -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS Assert.Contains("throw0fn", exThrow0.StackTrace); #else Assert.Contains("omitted JavaScript stack trace", exThrow0.StackTrace); @@ -2013,7 +2013,7 @@ public void JsImportMath() var exThrow1 = Assert.Throws(() => throw1(value)); Assert.Contains("throw1-msg", exThrow1.Message); Assert.DoesNotContain(" at ", exThrow1.Message); -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS Assert.Contains("throw1fn", exThrow1.StackTrace); #else Assert.Contains("omitted JavaScript stack trace", exThrow0.StackTrace); diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs index d3e63213078adf..bfd645039b56cb 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs @@ -1003,7 +1003,7 @@ public static async Task InitializeAsync() await Setup(); } -#if FEATURE_WASM_THREADS +#if FEATURE_WASM_MANAGED_THREADS // are we in the UI thread ? if (Environment.CurrentManagedThreadId == 1) #endif diff --git a/src/libraries/System.Threading.Tasks.Parallel/src/System.Threading.Tasks.Parallel.csproj b/src/libraries/System.Threading.Tasks.Parallel/src/System.Threading.Tasks.Parallel.csproj index 03b1f303bed216..3278b9f2c5e19d 100644 --- a/src/libraries/System.Threading.Tasks.Parallel/src/System.Threading.Tasks.Parallel.csproj +++ b/src/libraries/System.Threading.Tasks.Parallel/src/System.Threading.Tasks.Parallel.csproj @@ -9,7 +9,7 @@ $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) true - $(DefineConstants);FEATURE_WASM_THREADS + $(DefineConstants);FEATURE_WASM_MANAGED_THREADS diff --git a/src/libraries/System.Threading.Tasks.Parallel/src/System/Threading/Tasks/Parallel.cs b/src/libraries/System.Threading.Tasks.Parallel/src/System/Threading/Tasks/Parallel.cs index d7bca6aa996425..7a466d0501c2a0 100644 --- a/src/libraries/System.Threading.Tasks.Parallel/src/System/Threading/Tasks/Parallel.cs +++ b/src/libraries/System.Threading.Tasks.Parallel/src/System/Threading/Tasks/Parallel.cs @@ -238,7 +238,7 @@ 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 +#if !FEATURE_WASM_MANAGED_THREADS // Web browsers need special treatment that is implemented in TaskReplicator if (OperatingSystem.IsBrowser() || #else diff --git a/src/libraries/System.Threading.Tasks.Parallel/src/System/Threading/Tasks/TaskReplicator.cs b/src/libraries/System.Threading.Tasks.Parallel/src/System/Threading/Tasks/TaskReplicator.cs index eb09ba672f4239..0239770284e4ac 100644 --- a/src/libraries/System.Threading.Tasks.Parallel/src/System/Threading/Tasks/TaskReplicator.cs +++ b/src/libraries/System.Threading.Tasks.Parallel/src/System/Threading/Tasks/TaskReplicator.cs @@ -131,7 +131,7 @@ public static void Run(ReplicatableUserAction 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 !FEATURE_WASM_MANAGED_THREADS if (OperatingSystem.IsBrowser()) { // Since we are running on a single thread, we don't want the action to time out diff --git a/src/libraries/System.Threading.Thread.WebAssembly.Threading/ref/System.Threading.Thread.WebAssembly.Threading.csproj b/src/libraries/System.Threading.Thread.WebAssembly.Threading/ref/System.Threading.Thread.WebAssembly.Threading.csproj index a5805dc57bad7c..074ca5b7f7ede8 100644 --- a/src/libraries/System.Threading.Thread.WebAssembly.Threading/ref/System.Threading.Thread.WebAssembly.Threading.csproj +++ b/src/libraries/System.Threading.Thread.WebAssembly.Threading/ref/System.Threading.Thread.WebAssembly.Threading.csproj @@ -11,7 +11,7 @@ false Microsoft true - $(DefineConstants);FEATURE_WASM_THREADS + $(DefineConstants);FEATURE_WASM_MANAGED_THREADS diff --git a/src/libraries/System.Threading.Thread/ref/System.Threading.Thread.cs b/src/libraries/System.Threading.Thread/ref/System.Threading.Thread.cs index 6e90254a45f550..c4c038036ce341 100644 --- a/src/libraries/System.Threading.Thread/ref/System.Threading.Thread.cs +++ b/src/libraries/System.Threading.Thread/ref/System.Threading.Thread.cs @@ -91,22 +91,22 @@ public static void SetData(System.LocalDataStoreSlot slot, object? data) { } public static void Sleep(int millisecondsTimeout) { } public static void Sleep(System.TimeSpan timeout) { } public static void SpinWait(int iterations) { } -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] #endif public void Start() { } -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] #endif public void Start(object? parameter) { } [System.ObsoleteAttribute("Thread.Suspend has been deprecated. Use other classes in System.Threading, such as Monitor, Mutex, Event, and Semaphore, to synchronize Threads or protect resources.")] public void Suspend() { } public bool TrySetApartmentState(System.Threading.ApartmentState state) { throw null; } -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] #endif public void UnsafeStart() { } -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] #endif public void UnsafeStart(object? parameter) { } diff --git a/src/libraries/System.Threading.ThreadPool.WebAssembly.Threading/ref/System.Threading.ThreadPool.WebAssembly.Threading.csproj b/src/libraries/System.Threading.ThreadPool.WebAssembly.Threading/ref/System.Threading.ThreadPool.WebAssembly.Threading.csproj index 370e00b99272cc..a354d46a0a98bb 100644 --- a/src/libraries/System.Threading.ThreadPool.WebAssembly.Threading/ref/System.Threading.ThreadPool.WebAssembly.Threading.csproj +++ b/src/libraries/System.Threading.ThreadPool.WebAssembly.Threading/ref/System.Threading.ThreadPool.WebAssembly.Threading.csproj @@ -10,7 +10,7 @@ false Microsoft true - $(DefineConstants);FEATURE_WASM_THREADS + $(DefineConstants);FEATURE_WASM_MANAGED_THREADS diff --git a/src/libraries/System.Threading.ThreadPool/ref/System.Threading.ThreadPool.cs b/src/libraries/System.Threading.ThreadPool/ref/System.Threading.ThreadPool.cs index 20ca9318b980c4..5ff1eb3924e8e0 100644 --- a/src/libraries/System.Threading.ThreadPool/ref/System.Threading.ThreadPool.cs +++ b/src/libraries/System.Threading.ThreadPool/ref/System.Threading.ThreadPool.cs @@ -10,7 +10,7 @@ public partial interface IThreadPoolWorkItem { void Execute(); } -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] #endif public sealed partial class RegisteredWaitHandle : System.MarshalByRefObject @@ -34,20 +34,20 @@ public static partial class ThreadPool public static bool QueueUserWorkItem(System.Threading.WaitCallback callBack) { throw null; } public static bool QueueUserWorkItem(System.Threading.WaitCallback callBack, object? state) { throw null; } public static bool QueueUserWorkItem(System.Action callBack, TState state, bool preferLocal) { throw null; } -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] #endif public static System.Threading.RegisteredWaitHandle RegisterWaitForSingleObject(System.Threading.WaitHandle waitObject, System.Threading.WaitOrTimerCallback callBack, object? state, int millisecondsTimeOutInterval, bool executeOnlyOnce) { throw null; } -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] #endif public static System.Threading.RegisteredWaitHandle RegisterWaitForSingleObject(System.Threading.WaitHandle waitObject, System.Threading.WaitOrTimerCallback callBack, object? state, long millisecondsTimeOutInterval, bool executeOnlyOnce) { throw null; } -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] #endif public static System.Threading.RegisteredWaitHandle RegisterWaitForSingleObject(System.Threading.WaitHandle waitObject, System.Threading.WaitOrTimerCallback callBack, object? state, System.TimeSpan timeout, bool executeOnlyOnce) { throw null; } [System.CLSCompliantAttribute(false)] -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] #endif public static System.Threading.RegisteredWaitHandle RegisterWaitForSingleObject(System.Threading.WaitHandle waitObject, System.Threading.WaitOrTimerCallback callBack, object? state, uint millisecondsTimeOutInterval, bool executeOnlyOnce) { throw null; } @@ -59,20 +59,20 @@ public static partial class ThreadPool public static bool UnsafeQueueUserWorkItem(System.Threading.IThreadPoolWorkItem callBack, bool preferLocal) { throw null; } public static bool UnsafeQueueUserWorkItem(System.Threading.WaitCallback callBack, object? state) { throw null; } public static bool UnsafeQueueUserWorkItem(System.Action callBack, TState state, bool preferLocal) { throw null; } -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] #endif public static System.Threading.RegisteredWaitHandle UnsafeRegisterWaitForSingleObject(System.Threading.WaitHandle waitObject, System.Threading.WaitOrTimerCallback callBack, object? state, int millisecondsTimeOutInterval, bool executeOnlyOnce) { throw null; } -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] #endif public static System.Threading.RegisteredWaitHandle UnsafeRegisterWaitForSingleObject(System.Threading.WaitHandle waitObject, System.Threading.WaitOrTimerCallback callBack, object? state, long millisecondsTimeOutInterval, bool executeOnlyOnce) { throw null; } -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] #endif public static System.Threading.RegisteredWaitHandle UnsafeRegisterWaitForSingleObject(System.Threading.WaitHandle waitObject, System.Threading.WaitOrTimerCallback callBack, object? state, System.TimeSpan timeout, bool executeOnlyOnce) { throw null; } [System.CLSCompliantAttribute(false)] -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] #endif public static System.Threading.RegisteredWaitHandle UnsafeRegisterWaitForSingleObject(System.Threading.WaitHandle waitObject, System.Threading.WaitOrTimerCallback callBack, object? state, uint millisecondsTimeOutInterval, bool executeOnlyOnce) { throw null; } diff --git a/src/libraries/System.Threading.ThreadPool/ref/System.Threading.ThreadPool.csproj b/src/libraries/System.Threading.ThreadPool/ref/System.Threading.ThreadPool.csproj index c7c5d2c26ecfb0..5c55020cf70bc1 100644 --- a/src/libraries/System.Threading.ThreadPool/ref/System.Threading.ThreadPool.csproj +++ b/src/libraries/System.Threading.ThreadPool/ref/System.Threading.ThreadPool.csproj @@ -2,7 +2,7 @@ $(NetCoreAppCurrent) true - $(DefineConstants);FEATURE_WASM_THREADS + $(DefineConstants);FEATURE_WASM_MANAGED_THREADS diff --git a/src/libraries/System.Threading.WebAssembly.Threading/ref/System.Threading.WebAssembly.Threading.csproj b/src/libraries/System.Threading.WebAssembly.Threading/ref/System.Threading.WebAssembly.Threading.csproj index 3f0a38381ff0f6..63dec7d5e54c2a 100644 --- a/src/libraries/System.Threading.WebAssembly.Threading/ref/System.Threading.WebAssembly.Threading.csproj +++ b/src/libraries/System.Threading.WebAssembly.Threading/ref/System.Threading.WebAssembly.Threading.csproj @@ -11,7 +11,7 @@ false Microsoft true - $(DefineConstants);FEATURE_WASM_THREADS + $(DefineConstants);FEATURE_WASM_MANAGED_THREADS diff --git a/src/libraries/System.Threading/ref/System.Threading.cs b/src/libraries/System.Threading/ref/System.Threading.cs index 104d2e925c2619..74743e946890c8 100644 --- a/src/libraries/System.Threading/ref/System.Threading.cs +++ b/src/libraries/System.Threading/ref/System.Threading.cs @@ -14,11 +14,11 @@ public Barrier(int participantCount, System.Action? po public long CurrentPhaseNumber { get { throw null; } } public int ParticipantCount { get { throw null; } } public int ParticipantsRemaining { get { throw null; } } -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] #endif public long AddParticipant() { throw null; } -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] #endif public long AddParticipants(int participantCount) { throw null; } @@ -26,27 +26,27 @@ public void Dispose() { } protected virtual void Dispose(bool disposing) { } public void RemoveParticipant() { } public void RemoveParticipants(int participantCount) { } -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] #endif public void SignalAndWait() { } -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] #endif public bool SignalAndWait(int millisecondsTimeout) { throw null; } -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] #endif public bool SignalAndWait(int millisecondsTimeout, System.Threading.CancellationToken cancellationToken) { throw null; } -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] #endif public void SignalAndWait(System.Threading.CancellationToken cancellationToken) { } -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] #endif public bool SignalAndWait(System.TimeSpan timeout) { throw null; } -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] #endif public bool SignalAndWait(System.TimeSpan timeout, System.Threading.CancellationToken cancellationToken) { throw null; } @@ -78,27 +78,27 @@ 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 +#if !FEATURE_WASM_MANAGED_THREADS [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] #endif public void Wait() { } -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] #endif public bool Wait(int millisecondsTimeout) { throw null; } -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] #endif public bool Wait(int millisecondsTimeout, System.Threading.CancellationToken cancellationToken) { throw null; } -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] #endif public void Wait(System.Threading.CancellationToken cancellationToken) { } -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] #endif public bool Wait(System.TimeSpan timeout) { throw null; } -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] #endif public bool Wait(System.TimeSpan timeout, System.Threading.CancellationToken cancellationToken) { throw null; } @@ -353,27 +353,27 @@ public void Dispose() { } protected virtual void Dispose(bool disposing) { } public void Reset() { } public void Set() { } -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] #endif public void Wait() { } -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] #endif public bool Wait(int millisecondsTimeout) { throw null; } -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] #endif public bool Wait(int millisecondsTimeout, System.Threading.CancellationToken cancellationToken) { throw null; } -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] #endif public void Wait(System.Threading.CancellationToken cancellationToken) { } -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] #endif public bool Wait(System.TimeSpan timeout) { throw null; } -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] #endif public bool Wait(System.TimeSpan timeout, System.Threading.CancellationToken cancellationToken) { throw null; } @@ -393,23 +393,23 @@ 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 +#if !FEATURE_WASM_MANAGED_THREADS [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] #endif public static bool Wait(object obj) { throw null; } -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] #endif public static bool Wait(object obj, int millisecondsTimeout) { throw null; } -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] #endif public static bool Wait(object obj, int millisecondsTimeout, bool exitContext) { throw null; } -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] #endif public static bool Wait(object obj, System.TimeSpan timeout) { throw null; } -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] #endif public static bool Wait(object obj, System.TimeSpan timeout, bool exitContext) { throw null; } diff --git a/src/libraries/System.Threading/src/System.Threading.csproj b/src/libraries/System.Threading/src/System.Threading.csproj index 34e367ac90a399..e09ac58c61c410 100644 --- a/src/libraries/System.Threading/src/System.Threading.csproj +++ b/src/libraries/System.Threading/src/System.Threading.csproj @@ -7,7 +7,7 @@ true false true - $(DefineConstants);FEATURE_WASM_THREADS + $(DefineConstants);FEATURE_WASM_MANAGED_THREADS diff --git a/src/libraries/System.Threading/src/System/Threading/Barrier.cs b/src/libraries/System.Threading/src/System/Threading/Barrier.cs index c1f35c961184a2..e5cd44e77fe9fc 100644 --- a/src/libraries/System.Threading/src/System/Threading/Barrier.cs +++ b/src/libraries/System.Threading/src/System/Threading/Barrier.cs @@ -284,7 +284,7 @@ private bool SetCurrentTotal(int currentTotal, int current, int total, bool sens /// /// The current instance has already been /// disposed. -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [UnsupportedOSPlatform("browser")] #endif public long AddParticipant() @@ -315,7 +315,7 @@ public long AddParticipant() /// /// The current instance has already been /// disposed. -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [UnsupportedOSPlatform("browser")] #endif public long AddParticipants(int participantCount) @@ -475,7 +475,7 @@ public void RemoveParticipants(int participantCount) /// /// The current instance has already been /// disposed. -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [UnsupportedOSPlatform("browser")] #endif public void SignalAndWait() @@ -498,7 +498,7 @@ public void SignalAndWait() /// canceled. /// The current instance has already been /// disposed. -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [UnsupportedOSPlatform("browser")] #endif public void SignalAndWait(CancellationToken cancellationToken) @@ -530,7 +530,7 @@ public void SignalAndWait(CancellationToken cancellationToken) /// /// The current instance has already been /// disposed. -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [UnsupportedOSPlatform("browser")] #endif public bool SignalAndWait(TimeSpan timeout) @@ -560,7 +560,7 @@ public bool SignalAndWait(TimeSpan timeout) /// canceled. /// The current instance has already been /// disposed. -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [UnsupportedOSPlatform("browser")] #endif public bool SignalAndWait(TimeSpan timeout, CancellationToken cancellationToken) @@ -590,7 +590,7 @@ public bool SignalAndWait(TimeSpan timeout, CancellationToken cancellationToken) /// /// The current instance has already been /// disposed. -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [UnsupportedOSPlatform("browser")] #endif public bool SignalAndWait(int millisecondsTimeout) @@ -619,7 +619,7 @@ public bool SignalAndWait(int millisecondsTimeout) /// canceled. /// The current instance has already been /// disposed. -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [UnsupportedOSPlatform("browser")] #endif public bool SignalAndWait(int millisecondsTimeout, CancellationToken cancellationToken) @@ -861,7 +861,7 @@ private void WaitCurrentPhase(ManualResetEventSlim currentPhaseEvent, long obser /// cancellation token passed to SignalAndWait /// The current phase number for this thread /// True if the event is set or the phase number changed, false if the timeout expired -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [UnsupportedOSPlatform("browser")] #endif private bool DiscontinuousWait(ManualResetEventSlim currentPhaseEvent, int totalTimeout, CancellationToken token, long observedPhase) diff --git a/src/libraries/System.Threading/src/System/Threading/CountdownEvent.cs b/src/libraries/System.Threading/src/System/Threading/CountdownEvent.cs index 81afcb5d5e5742..837be45812ac31 100644 --- a/src/libraries/System.Threading/src/System/Threading/CountdownEvent.cs +++ b/src/libraries/System.Threading/src/System/Threading/CountdownEvent.cs @@ -403,7 +403,7 @@ public void Reset(int count) /// /// The current instance has already been /// disposed. -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [UnsupportedOSPlatform("browser")] #endif public void Wait() @@ -429,7 +429,7 @@ public void Wait() /// canceled. /// The current instance has already been /// disposed. -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [UnsupportedOSPlatform("browser")] #endif public void Wait(CancellationToken cancellationToken) @@ -451,7 +451,7 @@ public void Wait(CancellationToken cancellationToken) /// than . /// The current instance has already been /// disposed. -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [UnsupportedOSPlatform("browser")] #endif public bool Wait(TimeSpan timeout) @@ -482,7 +482,7 @@ public bool Wait(TimeSpan timeout) /// disposed. /// has /// been canceled. -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [UnsupportedOSPlatform("browser")] #endif public bool Wait(TimeSpan timeout, CancellationToken cancellationToken) @@ -506,7 +506,7 @@ public bool Wait(TimeSpan timeout, CancellationToken cancellationToken) /// negative number other than -1, which represents an infinite time-out. /// The current instance has already been /// disposed. -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [UnsupportedOSPlatform("browser")] #endif public bool Wait(int millisecondsTimeout) @@ -531,7 +531,7 @@ public bool Wait(int millisecondsTimeout) /// disposed. /// has /// been canceled. -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [UnsupportedOSPlatform("browser")] #endif public bool Wait(int millisecondsTimeout, CancellationToken cancellationToken) diff --git a/src/mono/System.Private.CoreLib/System.Private.CoreLib.csproj b/src/mono/System.Private.CoreLib/System.Private.CoreLib.csproj index 7c9012951a4f5f..cf157fee87514c 100644 --- a/src/mono/System.Private.CoreLib/System.Private.CoreLib.csproj +++ b/src/mono/System.Private.CoreLib/System.Private.CoreLib.csproj @@ -14,7 +14,7 @@ true true - $(DefineConstants);FEATURE_WASM_THREADS + $(DefineConstants);FEATURE_WASM_MANAGED_THREADS @@ -133,7 +133,7 @@ $(DefineConstants);FEATURE_PERFTRACING $(DefineConstants);FEATURE_OBJCMARSHAL - $(DefineConstants);FEATURE_WASM_THREADS + $(DefineConstants);FEATURE_WASM_MANAGED_THREADS $(DefineConstants);FEATURE_WASM_PERFTRACING diff --git a/src/mono/System.Private.CoreLib/src/System/Threading/Monitor.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Threading/Monitor.Mono.cs index 07aea6c347929e..8f17beb9394382 100644 --- a/src/mono/System.Private.CoreLib/src/System/Threading/Monitor.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Threading/Monitor.Mono.cs @@ -71,7 +71,7 @@ public static bool IsEntered(object obj) return ObjectHeader.IsEntered(obj); } -#if !FEATURE_WASM_THREADS +#if !FEATURE_WASM_MANAGED_THREADS [UnsupportedOSPlatform("browser")] #endif public static bool Wait(object obj, int millisecondsTimeout) diff --git a/src/mono/System.Private.CoreLib/src/System/Threading/ThreadPool.Browser.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Threading/ThreadPool.Browser.Mono.cs index a6690cea44a279..c707dd3506334e 100644 --- a/src/mono/System.Private.CoreLib/src/System/Threading/ThreadPool.Browser.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Threading/ThreadPool.Browser.Mono.cs @@ -13,8 +13,8 @@ namespace System.Threading { -#if FEATURE_WASM_THREADS -#error when compiled with FEATURE_WASM_THREADS, we use PortableThreadPool.WorkerThread.Browser.Threads.Mono.cs +#if FEATURE_WASM_MANAGED_THREADS +#error when compiled with FEATURE_WASM_MANAGED_THREADS, we use PortableThreadPool.WorkerThread.Browser.Threads.Mono.cs #endif [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public sealed class RegisteredWaitHandle : MarshalByRefObject diff --git a/src/mono/System.Private.CoreLib/src/System/Threading/ThreadPool.Wasi.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Threading/ThreadPool.Wasi.Mono.cs index 68a4844de5d3dc..557020c913efd3 100644 --- a/src/mono/System.Private.CoreLib/src/System/Threading/ThreadPool.Wasi.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Threading/ThreadPool.Wasi.Mono.cs @@ -13,8 +13,8 @@ namespace System.Threading { -#if FEATURE_WASM_THREADS -#error when compiled with FEATURE_WASM_THREADS +#if FEATURE_WASM_MANAGED_THREADS +#error when compiled with FEATURE_WASM_MANAGED_THREADS #endif [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public sealed class RegisteredWaitHandle : MarshalByRefObject diff --git a/src/mono/browser/build/BrowserWasmApp.targets b/src/mono/browser/build/BrowserWasmApp.targets index 95ab7c6a08a46b..696a7c902cb803 100644 --- a/src/mono/browser/build/BrowserWasmApp.targets +++ b/src/mono/browser/build/BrowserWasmApp.targets @@ -28,7 +28,7 @@ _WasmGenerateRunV8Script; - true + true false diff --git a/src/mono/wasm/threads.md b/src/mono/wasm/threads.md index 409d8de4c972d4..91ebb7c929aa57 100644 --- a/src/mono/wasm/threads.md +++ b/src/mono/wasm/threads.md @@ -12,7 +12,7 @@ This also works with released versions of .NET 7 or later and the `wasmbrowser` ## Libraries feature defines ## We use the `FeatureWasmManagedThreads` property in the libraries projects to conditionally define -`FEATURE_WASM_THREADS` which is used to affect how the libraries are built for the multi-threaded +`FEATURE_WASM_MANAGED_THREADS` which is used to affect how the libraries are built for the multi-threaded runtime. We use the `FeatureWasmPerfTracing` property in the libraries projects to @@ -23,7 +23,7 @@ internally can use multithreading for EventPipe diagnostics. ### Ref asssemblies ### For ref assemblies that have APIs that are related to threading, we use -`[UnsupportedOSPlatform("browser")]` under a `FEATURE_WASM_THREADS` define to mark APIs that are not +`[UnsupportedOSPlatform("browser")]` under a `FEATURE_WASM_MANAGED_THREADS` define to mark APIs that are not supported with the single-threaded runtime. Each such ref assembly (for example `System.Threading.Thread`) is defined in two places: `src/libraries/System.Threading.Thread/ref` for the single-threaded ref assemblies, and From d78c861bea2318781e58cfe14f4544323378af93 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz <32700855+ilonatommy@users.noreply.github.com> Date: Thu, 1 Feb 2024 09:38:11 +0000 Subject: [PATCH 11/18] Missing quote --- src/mono/browser/build/BrowserWasmApp.targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/browser/build/BrowserWasmApp.targets b/src/mono/browser/build/BrowserWasmApp.targets index 696a7c902cb803..ec2a81e1e066b9 100644 --- a/src/mono/browser/build/BrowserWasmApp.targets +++ b/src/mono/browser/build/BrowserWasmApp.targets @@ -28,7 +28,7 @@ _WasmGenerateRunV8Script; - true + true false From 0a9e0d2d4f04023c0a7b46daeb68f1a3c21305b2 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz <32700855+ilonatommy@users.noreply.github.com> Date: Thu, 1 Feb 2024 10:08:57 +0000 Subject: [PATCH 12/18] Remove unused variable. --- src/mono/browser/runtime/loader/config.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/mono/browser/runtime/loader/config.ts b/src/mono/browser/runtime/loader/config.ts index 4a311bc589b9ce..ec3ddacb2e6c6e 100644 --- a/src/mono/browser/runtime/loader/config.ts +++ b/src/mono/browser/runtime/loader/config.ts @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. import BuildConfiguration from "consts:configuration"; -import WasmEnableThreads from "consts:wasmEnableThreads"; import type { DotnetModuleInternal, MonoConfigInternal } from "../types/internal"; import type { DotnetModuleConfig, MonoConfig, ResourceGroups, ResourceList } from "../types"; From 814df26cc29c01e76e6915d58ed394417bb22dfe Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz <32700855+ilonatommy@users.noreply.github.com> Date: Thu, 1 Feb 2024 10:24:11 +0000 Subject: [PATCH 13/18] Fix merge error. --- src/mono/browser/runtime/loader/config.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mono/browser/runtime/loader/config.ts b/src/mono/browser/runtime/loader/config.ts index ec3ddacb2e6c6e..68f62e2261dddf 100644 --- a/src/mono/browser/runtime/loader/config.ts +++ b/src/mono/browser/runtime/loader/config.ts @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. import BuildConfiguration from "consts:configuration"; +import WasmEnableThreads from "consts:wasmEnableThreads"; import type { DotnetModuleInternal, MonoConfigInternal } from "../types/internal"; import type { DotnetModuleConfig, MonoConfig, ResourceGroups, ResourceList } from "../types"; @@ -187,7 +188,7 @@ export function normalizeConfig() { config.cachedResourcesPurgeDelay = 10000; } - if (MonoWasmThreads && !Number.isInteger(config.pthreadPoolSize)) { + if (WasmEnableThreads && !Number.isInteger(config.pthreadPoolSize)) { // ActiveIssue https://github.com/dotnet/runtime/issues/75602 config.pthreadPoolSize = 7; } From ea2f9b5c6e23891c7c46d88a3fa5617f91148f48 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz <32700855+ilonatommy@users.noreply.github.com> Date: Thu, 1 Feb 2024 11:03:29 +0000 Subject: [PATCH 14/18] @maraf's feedback --- eng/testing/workloads-browser.targets | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/eng/testing/workloads-browser.targets b/eng/testing/workloads-browser.targets index e8298cad72b413..a312347ff12f6b 100644 --- a/eng/testing/workloads-browser.targets +++ b/eng/testing/workloads-browser.targets @@ -71,8 +71,7 @@ Project="$(InstallerProjectRoot)pkg/sfx/Microsoft.NETCore.App/Microsoft.NETCore.App.Runtime.sfxproj" Dependencies="$(_DefaultRuntimePackNuGetPath)" Properties="@(_DefaultPropsForNuGetBuild, ';');WasmEnableThreads=$(WasmEnableThreads)" - Descriptor="$(_Descriptor)" - Condition="'$(WasmEnableThreads)' == 'true'"/> + Descriptor="$(_Descriptor)"/> Date: Thu, 1 Feb 2024 11:10:25 +0000 Subject: [PATCH 15/18] merge fix --- .../ref/System.Private.CoreLib.ExtraApis.cs | 2 +- .../src/System/Threading/Monitor.Mono.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/ref/System.Private.CoreLib.ExtraApis.cs b/src/libraries/System.Private.CoreLib/ref/System.Private.CoreLib.ExtraApis.cs index dedbdd6e27692e..4294279eefc574 100644 --- a/src/libraries/System.Private.CoreLib/ref/System.Private.CoreLib.ExtraApis.cs +++ b/src/libraries/System.Private.CoreLib/ref/System.Private.CoreLib.ExtraApis.cs @@ -38,7 +38,7 @@ public static partial class Debug } } -#if FEATURE_WASM_THREADS +#if FEATURE_WASM_MANAGED_THREADS namespace System.Threading { public partial class Monitor diff --git a/src/mono/System.Private.CoreLib/src/System/Threading/Monitor.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Threading/Monitor.Mono.cs index ba1bf98cb1fc4b..393c33d83d9f41 100644 --- a/src/mono/System.Private.CoreLib/src/System/Threading/Monitor.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Threading/Monitor.Mono.cs @@ -9,7 +9,7 @@ namespace System.Threading { public static partial class Monitor { -#if FEATURE_WASM_THREADS +#if FEATURE_WASM_MANAGED_THREADS [ThreadStatic] public static bool ThrowOnBlockingWaitOnJSInteropThread; #endif @@ -82,7 +82,7 @@ public static bool IsEntered(object obj) public static bool Wait(object obj, int millisecondsTimeout) { ArgumentNullException.ThrowIfNull(obj); -#if FEATURE_WASM_THREADS +#if FEATURE_WASM_MANAGED_THREADS if (ThrowOnBlockingWaitOnJSInteropThread) { throw new PlatformNotSupportedException("blocking Wait is not supported on the JS interop threads."); From 6475dcfc750187af6ee1339b2821524e324955f5 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz <32700855+ilonatommy@users.noreply.github.com> Date: Thu, 1 Feb 2024 13:22:15 +0000 Subject: [PATCH 16/18] . --- src/mono/browser/runtime/loader/exit.ts | 6 +++--- src/mono/browser/runtime/startup.ts | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/mono/browser/runtime/loader/exit.ts b/src/mono/browser/runtime/loader/exit.ts index 0ebbb32b1eb05c..880b52a8788b03 100644 --- a/src/mono/browser/runtime/loader/exit.ts +++ b/src/mono/browser/runtime/loader/exit.ts @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import MonoWasmThreads from "consts:monoWasmThreads"; +import WasmEnableThreads from "consts:monoWasmThreads"; import { ENVIRONMENT_IS_NODE, ENVIRONMENT_IS_WEB, ENVIRONMENT_IS_WORKER, INTERNAL, emscriptenModule, loaderHelpers, mono_assert, runtimeHelpers } from "./globals"; import { mono_log_debug, mono_log_error, mono_log_info_no_prefix, mono_log_warn, teardown_proxy_console } from "./logging"; @@ -16,7 +16,7 @@ export function is_runtime_running() { export function assert_runtime_running() { if (!is_exited()) { - if (MonoWasmThreads && ENVIRONMENT_IS_WORKER) { + if (WasmEnableThreads && ENVIRONMENT_IS_WORKER) { mono_assert(runtimeHelpers.runtimeReady, "The WebWorker is not attached to the runtime. See https://github.com/dotnet/runtime/blob/main/src/mono/wasm/threads.md#JS-interop-on-dedicated-threads"); } else { mono_assert(runtimeHelpers.runtimeReady, ".NET runtime didn't start yet. Please call dotnet.create() first."); @@ -151,7 +151,7 @@ export function mono_exit(exit_code: number, reason?: any): void { } function set_exit_code_and_quit_now(exit_code: number, reason?: any): void { - if (MonoWasmThreads && ENVIRONMENT_IS_WORKER && runtimeHelpers.runtimeReady && runtimeHelpers.nativeAbort) { + if (WasmEnableThreads && ENVIRONMENT_IS_WORKER && runtimeHelpers.runtimeReady && runtimeHelpers.nativeAbort) { // note that the reason is not passed to UI thread runtimeHelpers.runtimeReady = false; runtimeHelpers.nativeAbort(reason); diff --git a/src/mono/browser/runtime/startup.ts b/src/mono/browser/runtime/startup.ts index 11fbcdcd6f0eae..5b7eccc62ec569 100644 --- a/src/mono/browser/runtime/startup.ts +++ b/src/mono/browser/runtime/startup.ts @@ -122,7 +122,7 @@ async function instantiateWasmWorker( imports: WebAssembly.Imports, successCallback: InstantiateWasmSuccessCallback ): Promise { - if (!MonoWasmThreads) return; + if (!WasmEnableThreads) return; // wait for the config to arrive by message from the main thread await loaderHelpers.afterConfigLoaded.promise; @@ -169,7 +169,7 @@ function preInit(userPreInit: (() => void)[]) { } async function preInitWorkerAsync() { - if (!MonoWasmThreads) return; + if (!WasmEnableThreads) return; const mark = startMeasure(); try { mono_log_debug("preInitWorker"); @@ -193,7 +193,7 @@ async function preInitWorkerAsync() { // runs for each re-attached worker export function preRunWorker() { - if (!MonoWasmThreads) return; + if (!WasmEnableThreads) return; const mark = startMeasure(); try { jiterpreter_allocate_tables(); // this will return quickly if already allocated @@ -362,7 +362,7 @@ async function postRunAsync(userpostRun: (() => void)[]) { // runs for each re-detached worker export function postRunWorker() { - if (!MonoWasmThreads) return; + if (!WasmEnableThreads) return; const mark = startMeasure(); try { if (runtimeHelpers.proxy_context_gc_handle) { @@ -664,7 +664,7 @@ export function mono_wasm_set_main_args(name: string, allRuntimeArguments: strin /// 2. Emscripten does not run any event but preInit in the workers. /// 3. At the point when this executes there is no pthread assigned to the worker yet. export async function configureWorkerStartup(module: DotnetModuleInternal): Promise { - if (!MonoWasmThreads) return; + if (!WasmEnableThreads) return; initWorkerThreadEvents(); currentWorkerThreadEvents.addEventListener(dotnetPthreadCreated, () => { From 34bec8d52a1556170ef023656746d4960a011862 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz <32700855+ilonatommy@users.noreply.github.com> Date: Thu, 1 Feb 2024 13:29:49 +0000 Subject: [PATCH 17/18] Fix duplicate --- src/mono/browser/runtime/startup.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/mono/browser/runtime/startup.ts b/src/mono/browser/runtime/startup.ts index 5b7eccc62ec569..d7db9bc9a55675 100644 --- a/src/mono/browser/runtime/startup.ts +++ b/src/mono/browser/runtime/startup.ts @@ -296,9 +296,6 @@ async function onRuntimeInitializedAsync(userOnRuntimeInitialized: () => void) { runtimeHelpers.runtimeReady = true; runtimeList.registerRuntime(exportedRuntimeAPI); - runtimeHelpers.runtimeReady = true; - runtimeList.registerRuntime(exportedRuntimeAPI); - if (WasmEnableThreads) { runtimeHelpers.javaScriptExports.install_main_synchronization_context(); } From 1b6003521cb88159030f0442e56f8ccdddd09d0a Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz <32700855+ilonatommy@users.noreply.github.com> Date: Thu, 1 Feb 2024 14:10:51 +0000 Subject: [PATCH 18/18] fix --- src/mono/browser/runtime/loader/exit.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/browser/runtime/loader/exit.ts b/src/mono/browser/runtime/loader/exit.ts index 880b52a8788b03..9a9c78775cfd90 100644 --- a/src/mono/browser/runtime/loader/exit.ts +++ b/src/mono/browser/runtime/loader/exit.ts @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import WasmEnableThreads from "consts:monoWasmThreads"; +import WasmEnableThreads from "consts:wasmEnableThreads"; import { ENVIRONMENT_IS_NODE, ENVIRONMENT_IS_WEB, ENVIRONMENT_IS_WORKER, INTERNAL, emscriptenModule, loaderHelpers, mono_assert, runtimeHelpers } from "./globals"; import { mono_log_debug, mono_log_error, mono_log_info_no_prefix, mono_log_warn, teardown_proxy_console } from "./logging";