Skip to content

Commit

Permalink
Prune some unnecessary code from Monitor.Enter/Exit in single-threade…
Browse files Browse the repository at this point in the history
…d wasm builds of corlib
  • Loading branch information
kg committed Apr 18, 2024
1 parent b35b67d commit 96949a0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
<IsBigEndian Condition="'$(Platform)' == 's390x'">true</IsBigEndian>
<Is64Bit Condition="'$(Platform)' == 'arm64' or '$(Platform)' == 'x64' or '$(Platform)' == 's390x' or '$(Platform)' == 'loongarch64' or '$(Platform)' == 'ppc64le' or '$(Platform)' == 'riscv64'">true</Is64Bit>
<UseMinimalGlobalizationData Condition="'$(TargetsBrowser)' == 'true' or '$(TargetsWasi)' == 'true'">true</UseMinimalGlobalizationData>
<FeatureWasmManagedThreads Condition="'$(WasmEnableThreads)' == 'true'">true</FeatureWasmManagedThreads>
<DefineConstants Condition="'$(FeatureWasmManagedThreads)' == 'true'">$(DefineConstants);FEATURE_WASM_MANAGED_THREADS</DefineConstants>
</PropertyGroup>
<PropertyGroup>
<DefineConstants Condition="'$(IsBigEndian)' == 'true'">$(DefineConstants);BIGENDIAN</DefineConstants>
Expand Down Expand Up @@ -2766,4 +2768,4 @@
<Compile Include="$(MSBuildThisFileDirectory)System\Numerics\IUnaryPlusOperators.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Numerics\IUnsignedNumber.cs" />
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ public static void Exit(object obj)
{
if (obj == null)
ArgumentNullException.ThrowIfNull(obj);
#if TARGET_BROWSER && !FEATURE_WASM_MANAGED_THREADS
#else
if (ObjectHeader.TryExitChecked(obj))
return;

InternalExit(obj);
#endif
}

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

#if TARGET_BROWSER && !FEATURE_WASM_MANAGED_THREADS
#else
// fast path
if (ObjectHeader.TryEnterFast(obj)) {
lockTaken = true;
return;
}

try_enter_with_atomic_var(obj, timeout, true, ref lockTaken);
#endif
}

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

0 comments on commit 96949a0

Please sign in to comment.