未验证 提交 f891033d 编写于 作者: M Maxim Lipnin 提交者: GitHub

Remove redundant P/Invoke-s in S.D.Process on Apple platforms (#54273)

* Remove P/Invoke to SystemNative_ConfigureTerminalForChildProcess which doesn't exist on Apple platforms

* Address the feedback based on the ifdef approach

* Add IsiOSLike property

* Use a partial method approach

* Address the feedback
上级 30f42697
......@@ -10,6 +10,9 @@
<PropertyGroup>
<GeneratePlatformNotSupportedAssemblyMessage Condition="'$(TargetsAnyOS)' == 'true'">SR.Process_PlatformNotSupported</GeneratePlatformNotSupportedAssemblyMessage>
</PropertyGroup>
<PropertyGroup>
<IsiOSLike Condition="'$(TargetsMacCatalyst)' == 'true' or '$(TargetsiOS)' == 'true' or '$(TargetstvOS)' == 'true'">true</IsiOSLike>
</PropertyGroup>
<ItemGroup Condition="'$(TargetsAnyOS)' != 'true'">
<Compile Include="Microsoft\Win32\SafeHandles\SafeProcessHandle.cs" />
<Compile Include="System\Collections\Specialized\DictionaryWrapper.cs" />
......@@ -234,8 +237,6 @@
Link="Common\Interop\Unix\Interop.GetHostName.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.SysConf.cs"
Link="Common\Interop\Unix\Interop.SysConf.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.ConfigureTerminalForChildProcess.cs"
Link="Common\Interop\Unix\Interop.ConfigureTerminalForChildProcess.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.ForkAndExecProcess.cs"
Link="Common\Interop\Unix\Interop.ForkAndExecProcess.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.GetGroupList.cs"
......@@ -267,6 +268,11 @@
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.Access.cs"
Link="Common\Interop\Unix\System.Native\Interop.Access.cs" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetsUnix)' == 'true' and '$(IsiOSLike)' != 'true'">
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.ConfigureTerminalForChildProcess.cs"
Link="Common\Interop\Unix\Interop.ConfigureTerminalForChildProcess.cs" />
<Compile Include="System\Diagnostics\Process.Unix.ConfigureTerminalForChildProcesses.cs" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetsLinux)' == 'true'">
<Compile Include="System\Diagnostics\Process.Linux.cs" />
<Compile Include="System\Diagnostics\ProcessManager.Linux.cs" />
......
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Threading;
namespace System.Diagnostics
{
public partial class Process
{
private static int s_childrenUsingTerminalCount;
static partial void ConfigureTerminalForChildProcessesInner(int increment)
{
Debug.Assert(increment != 0);
int childrenUsingTerminalRemaining = Interlocked.Add(ref s_childrenUsingTerminalCount, increment);
if (increment > 0)
{
Debug.Assert(s_processStartLock.IsReadLockHeld);
// At least one child is using the terminal.
Interop.Sys.ConfigureTerminalForChildProcess(childUsesTerminal: true);
}
else
{
Debug.Assert(s_processStartLock.IsWriteLockHeld);
if (childrenUsingTerminalRemaining == 0)
{
// No more children are using the terminal.
Interop.Sys.ConfigureTerminalForChildProcess(childUsesTerminal: false);
}
}
}
}
}
......@@ -19,7 +19,6 @@ public partial class Process : IDisposable
private static volatile bool s_initialized;
private static readonly object s_initializedGate = new object();
private static readonly ReaderWriterLockSlim s_processStartLock = new ReaderWriterLockSlim();
private static int s_childrenUsingTerminalCount;
/// <summary>
/// Puts a Process component in state to interact with operating system processes that run in a
......@@ -1051,26 +1050,9 @@ private static void OnSigChild(int reapAll)
/// </summary>
internal static void ConfigureTerminalForChildProcesses(int increment)
{
Debug.Assert(increment != 0);
int childrenUsingTerminalRemaining = Interlocked.Add(ref s_childrenUsingTerminalCount, increment);
if (increment > 0)
{
Debug.Assert(s_processStartLock.IsReadLockHeld);
// At least one child is using the terminal.
Interop.Sys.ConfigureTerminalForChildProcess(childUsesTerminal: true);
}
else
{
Debug.Assert(s_processStartLock.IsWriteLockHeld);
if (childrenUsingTerminalRemaining == 0)
{
// No more children are using the terminal.
Interop.Sys.ConfigureTerminalForChildProcess(childUsesTerminal: false);
}
}
ConfigureTerminalForChildProcessesInner(increment);
}
static partial void ConfigureTerminalForChildProcessesInner(int increment);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册