Skip to content

Commit 51b1e92

Browse files
authored
Revert "A few fixes in the threadpool semaphore. Unify Windows/Unix implementation of LIFO policy." (#125193)
Reverts #123921 This change appears to have caused a large regression in NuGet restore performance. Reverting is confirmed to produce a significant improvement (10-15%).
1 parent d4a8aa2 commit 51b1e92

21 files changed

Lines changed: 194 additions & 682 deletions

docs/coding-guidelines/interop-guidelines.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ internal static partial class Interop
3434
...
3535
internal static partial class Interop
3636
{
37-
internal static partial class Mincore { ... }
37+
internal static partial class mincore { ... }
3838
}
3939
```
4040
- With few exceptions, the only methods that should be defined in these interop types are DllImports.
@@ -49,9 +49,7 @@ internal static partial class Interop
4949
```
5050
\Common\src\Interop
5151
\Windows
52-
\Kernel32
53-
... interop files
54-
\Mincore
52+
\mincore
5553
... interop files
5654
\Unix
5755
\libc
@@ -73,8 +71,8 @@ As shown above, platforms may be additive, in that an assembly may use functiona
7371
\libc
7472
\Interop.strerror.cs
7573
\Windows
76-
\Mincore
77-
\Interop.WaitOnAddress.cs <-- Also contains WakeByAddressSingle
74+
\mincore
75+
\Interop.OutputDebugString.cs
7876
```
7977

8078
- If structs/constants will be used on their own without an associated DllImport, or if they may be used with multiple DllImports not in the same file, they should be declared in a separate file.
@@ -83,9 +81,9 @@ As shown above, platforms may be additive, in that an assembly may use functiona
8381
```
8482
\Common\src\Interop
8583
\Windows
86-
\Kernel32
87-
\Interop.DuplicateHandle_SafeFileHandle.cs
88-
\Interop.DuplicateHandle_SafePipeHandle.cs
84+
\mincore
85+
\Interop.DuplicateHandle_SafeTokenHandle.cs
86+
\Interop.DuplicateHandle_IntPtr.cs
8987
```
9088

9189
- The library names used per-platform are stored in internal constants in the Interop class in a private Libraries class in a per-platform file named Interop.Libraries.cs. These constants are then used for all DllImports to that library, rather than having the string duplicated each time, e.g.
@@ -96,9 +94,12 @@ internal static partial class Interop // contents of Common\src\Interop\Windows\
9694
private static class Libraries
9795
{
9896
internal const string Kernel32 = "kernel32.dll";
99-
internal const string OleAut32 = "oleaut32.dll";
10097
internal const string Localization = "api-ms-win-core-localization-l1-2-0.dll";
101-
internal const string Synch = "api-ms-win-core-synch-l1-2-0.dll";
98+
internal const string Handle = "api-ms-win-core-handle-l1-1-0.dll";
99+
internal const string ProcessThreads = "api-ms-win-core-processthreads-l1-1-0.dll";
100+
internal const string File = "api-ms-win-core-file-l1-1-0.dll";
101+
internal const string NamedPipe = "api-ms-win-core-namedpipe-l1-1-0.dll";
102+
internal const string IO = "api-ms-win-core-io-l1-1-0.dll";
102103
...
103104
}
104105
}

src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ The .NET Foundation licenses this file to you under the MIT license.
8282
<SdkNativeLibrary Include="user32.lib" />
8383
<SdkNativeLibrary Include="version.lib" />
8484
<SdkNativeLibrary Include="ws2_32.lib" />
85-
<SdkNativeLibrary Include="Synchronization.lib" />
8685
</ItemGroup>
8786

8887
<ItemGroup>

src/coreclr/nativeaot/BuildIntegration/WindowsAPIs.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2340,12 +2340,6 @@ ws2_32!WSCUpdateProvider
23402340
ws2_32!WSCWriteNameSpaceOrder
23412341
ws2_32!WSCWriteProviderOrder
23422342

2343-
#
2344-
# Synchronization.lib
2345-
#
2346-
api-ms-win-core-synch-l1-2-0!WaitOnAddress
2347-
api-ms-win-core-synch-l1-2-0!WakeByAddressSingle
2348-
23492343
#
23502344
# Include all memory allocation APIs from ucrt to ensure that all of them use allocator
23512345
# from the same ucrt copy. Also include the frequently used basic memory manipulation APIs.

src/coreclr/tools/aot/ILCompiler/reproNative/reproNative.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
<NativeAotSourceRoot>$(CoreClrSourceRoot)nativeaot\</NativeAotSourceRoot>
4747
<ArtifactsRoot>$(CoreClrSourceRoot)..\..\artifacts\</ArtifactsRoot>
4848
<NativeRoot>$(CoreClrSourceRoot)..\native\</NativeRoot>
49-
<Win32SDKLibs>advapi32.lib;bcrypt.lib;crypt32.lib;iphlpapi.lib;kernel32.lib;mswsock.lib;ncrypt.lib;normaliz.lib;ntdll.lib;ole32.lib;oleaut32.lib;secur32.lib;user32.lib;version.lib;ws2_32.lib;Synchronization.lib</Win32SDKLibs>
49+
<Win32SDKLibs>advapi32.lib;bcrypt.lib;crypt32.lib;iphlpapi.lib;kernel32.lib;mswsock.lib;ncrypt.lib;normaliz.lib;ntdll.lib;ole32.lib;oleaut32.lib;secur32.lib;user32.lib;version.lib;ws2_32.lib</Win32SDKLibs>
5050
</PropertyGroup>
5151
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
5252
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">

src/libraries/Common/src/Interop/Unix/System.Native/Interop.Futex.cs

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/libraries/Common/src/Interop/Unix/System.Native/Interop.LowLevelMonitor.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ internal static partial class Sys
1717
[LibraryImport(Libraries.SystemNative, EntryPoint = "SystemNative_LowLevelMonitor_Acquire")]
1818
internal static partial void LowLevelMonitor_Acquire(IntPtr monitor);
1919

20-
[SuppressGCTransition]
2120
[LibraryImport(Libraries.SystemNative, EntryPoint = "SystemNative_LowLevelMonitor_Release")]
2221
internal static partial void LowLevelMonitor_Release(IntPtr monitor);
2322

src/libraries/Common/src/Interop/Windows/Interop.Libraries.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ internal static partial class Libraries
4848
internal const string Xolehlp = "xolehlp.dll";
4949
internal const string Comdlg32 = "comdlg32.dll";
5050
internal const string Gdiplus = "gdiplus.dll";
51+
internal const string Oleaut32 = "oleaut32.dll";
5152
internal const string Winspool = "winspool.drv";
52-
internal const string Synch = "api-ms-win-core-synch-l1-2-0.dll";
5353
}
5454
}

src/libraries/Common/src/Interop/Windows/Kernel32/Interop.CriticalSection.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ internal struct CRITICAL_SECTION
2525
[LibraryImport(Libraries.Kernel32)]
2626
internal static unsafe partial void EnterCriticalSection(CRITICAL_SECTION* lpCriticalSection);
2727

28-
[SuppressGCTransition]
2928
[LibraryImport(Libraries.Kernel32)]
3029
internal static unsafe partial void LeaveCriticalSection(CRITICAL_SECTION* lpCriticalSection);
3130

src/libraries/Common/src/Interop/Windows/Mincore/Interop.WaitOnAddress.cs

Lines changed: 0 additions & 17 deletions
This file was deleted.

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1852,9 +1852,6 @@
18521852
<Compile Include="$(CommonPath)Interop\Windows\Kernel32\Interop.CreateSymbolicLink.cs">
18531853
<Link>Common\Interop\Windows\Kernel32\Interop.CreateSymbolicLink.cs</Link>
18541854
</Compile>
1855-
<Compile Include="$(CommonPath)Interop\Windows\Mincore\Interop.WaitOnAddress.cs">
1856-
<Link>Common\Interop\Windows\Mincore\Interop.WaitOnAddress.cs</Link>
1857-
</Compile>
18581855
<Compile Include="$(CommonPath)Interop\Windows\Kernel32\Interop.CriticalSection.cs">
18591856
<Link>Common\Interop\Windows\Kernel32\Interop.CriticalSection.cs</Link>
18601857
</Compile>
@@ -2486,9 +2483,6 @@
24862483
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.LowLevelMonitor.cs">
24872484
<Link>Common\Interop\Unix\System.Native\Interop.LowLevelMonitor.cs</Link>
24882485
</Compile>
2489-
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.Futex.cs">
2490-
<Link>Common\Interop\Unix\System.Native\Interop.Futex.cs</Link>
2491-
</Compile>
24922486
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.LSeek.cs">
24932487
<Link>Common\Interop\Unix\System.Native\Interop.LSeek.cs</Link>
24942488
</Compile>
@@ -2845,9 +2839,8 @@
28452839
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\PortableThreadPool.Unix.cs" Condition="'$(TargetsUnix)' == 'true' or ('$(TargetsBrowser)' == 'true' and '$(FeatureWasmManagedThreads)' != 'true') or '$(TargetsWasi)' == 'true'" />
28462840
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\PortableThreadPool.Windows.cs" Condition="'$(TargetsWindows)' == 'true'" />
28472841
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\LowLevelLifoSemaphore.cs" />
2848-
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\LowLevelThreadBlocker.cs" />
2849-
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\LowLevelFutex.Windows.cs" Condition="'$(TargetsWindows)' == 'true'" />
2850-
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\LowLevelFutex.Unix.cs" Condition="'$(TargetsUnix)' == 'true'" />
2842+
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\LowLevelLifoSemaphore.Windows.cs" Condition="'$(TargetsWindows)' == 'true'" />
2843+
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\LowLevelLifoSemaphore.Unix.cs" Condition="'$(TargetsUnix)' == 'true' or '$(TargetsBrowser)' == 'true' or '$(TargetsWasi)' == 'true'" />
28512844
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\PreAllocatedOverlapped.Windows.cs" Condition="'$(TargetsWindows)' == 'true'" />
28522845
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\PreAllocatedOverlapped.Unix.cs" Condition="'$(TargetsUnix)' == 'true' or ('$(TargetsBrowser)' == 'true' and '$(FeatureWasmManagedThreads)' == 'true')" />
28532846
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\PreAllocatedOverlapped.Portable.cs" Condition="('$(TargetsBrowser)' != 'true' and '$(TargetsWasi)' != 'true') or '$(FeatureWasmManagedThreads)' == 'true'" />

0 commit comments

Comments
 (0)