Skip to content

Commit f8b8967

Browse files
committed
Prune some unnecessary code from Monitor.Enter/Exit in single-threaded wasm builds of corlib
1 parent d28c577 commit f8b8967

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
<IsBigEndian Condition="'$(Platform)' == 's390x'">true</IsBigEndian>
2525
<Is64Bit Condition="'$(Platform)' == 'arm64' or '$(Platform)' == 'x64' or '$(Platform)' == 's390x' or '$(Platform)' == 'loongarch64' or '$(Platform)' == 'ppc64le' or '$(Platform)' == 'riscv64'">true</Is64Bit>
2626
<UseMinimalGlobalizationData Condition="'$(TargetsBrowser)' == 'true' or '$(TargetsWasi)' == 'true'">true</UseMinimalGlobalizationData>
27+
<FeatureWasmManagedThreads Condition="'$(WasmEnableThreads)' == 'true'">true</FeatureWasmManagedThreads>
28+
<DefineConstants Condition="'$(FeatureWasmManagedThreads)' == 'true'">$(DefineConstants);FEATURE_WASM_MANAGED_THREADS</DefineConstants>
2729
</PropertyGroup>
2830
<PropertyGroup>
2931
<DefineConstants Condition="'$(IsBigEndian)' == 'true'">$(DefineConstants);BIGENDIAN</DefineConstants>
@@ -2766,4 +2768,4 @@
27662768
<Compile Include="$(MSBuildThisFileDirectory)System\Numerics\IUnaryPlusOperators.cs" />
27672769
<Compile Include="$(MSBuildThisFileDirectory)System\Numerics\IUnsignedNumber.cs" />
27682770
</ItemGroup>
2769-
</Project>
2771+
</Project>

src/mono/System.Private.CoreLib/src/System/Threading/Monitor.Mono.cs

+6
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,13 @@ public static void Exit(object obj)
3030
{
3131
if (obj == null)
3232
ArgumentNullException.ThrowIfNull(obj);
33+
#if TARGET_BROWSER && !FEATURE_WASM_MANAGED_THREADS
34+
#else
3335
if (ObjectHeader.TryExitChecked(obj))
3436
return;
3537

3638
InternalExit(obj);
39+
#endif
3740
}
3841

3942
public static bool TryEnter(object obj)
@@ -157,13 +160,16 @@ private static void ReliableEnterTimeout(object obj, int timeout, ref bool lockT
157160
if (timeout < 0 && timeout != (int)Timeout.Infinite)
158161
throw new ArgumentOutOfRangeException(nameof(timeout));
159162

163+
#if TARGET_BROWSER && !FEATURE_WASM_MANAGED_THREADS
164+
#else
160165
// fast path
161166
if (ObjectHeader.TryEnterFast(obj)) {
162167
lockTaken = true;
163168
return;
164169
}
165170

166171
try_enter_with_atomic_var(obj, timeout, true, ref lockTaken);
172+
#endif
167173
}
168174

169175
public static long LockContentionCount => Monitor_get_lock_contention_count() + Lock.ContentionCount;

0 commit comments

Comments
 (0)