Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit e57157a

Browse files
authored
Expose Thread.GetCurrentProcessorId() (#27541)
Fixes #16767
1 parent f25eb28 commit e57157a

File tree

6 files changed

+28
-1
lines changed

6 files changed

+28
-1
lines changed

src/System.Threading.Thread/ref/System.Threading.Thread.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public static void FreeNamedDataSlot(string name) { }
6565
public System.Threading.ApartmentState GetApartmentState() { throw null; }
6666
[System.ObsoleteAttribute("Thread.GetCompressedStack is no longer supported. Please use the System.Threading.CompressedStack class")]
6767
public System.Threading.CompressedStack GetCompressedStack() { throw null; }
68+
public static int GetCurrentProcessorId() { throw null; }
6869
public static object GetData(System.LocalDataStoreSlot slot) { throw null; }
6970
public static System.AppDomain GetDomain() { throw null; }
7071
public static int GetDomainID() { throw null; }

src/System.Threading.Thread/src/System/Threading/Thread.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ public void SetCompressedStack(CompressedStack stack)
272272
throw new InvalidOperationException(SR.Thread_GetSetCompressedStack_NotSupported);
273273
}
274274

275+
public static int GetCurrentProcessorId() => RuntimeThread.GetCurrentProcessorId();
275276
public static AppDomain GetDomain() => AppDomain.CurrentDomain;
276277
public static int GetDomainID() => GetDomain().Id;
277278
public override int GetHashCode() => ManagedThreadId;

src/System.Threading.Thread/tests/Configurations.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
<PropertyGroup>
44
<BuildConfigurations>
55
netstandard;
6+
netcoreapp;
7+
uap;
68
</BuildConfigurations>
79
</PropertyGroup>
810
</Project>

src/System.Threading.Thread/tests/System.Threading.Thread.Tests.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,19 @@
77
</PropertyGroup>
88
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netstandard-Debug|AnyCPU'" />
99
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netstandard-Release|AnyCPU'" />
10+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netcoreapp-Debug|AnyCPU'" />
11+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netcoreapp-Release|AnyCPU'" />
12+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='uap-Debug|AnyCPU'" />
13+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='uap-Release|AnyCPU'" />
1014
<ItemGroup>
1115
<Compile Include="CompressedStackTests.cs" />
1216
<Compile Include="ExceptionTests.cs" />
1317
<Compile Include="ThreadExceptionEventArgsTests.cs" />
1418
<Compile Include="ThreadTests.cs" />
1519
</ItemGroup>
20+
<ItemGroup Condition="'$(TargetGroup)' != 'netstandard'">
21+
<Compile Include="ThreadTests.netcoreapp.cs" />
22+
</ItemGroup>
1623
<ItemGroup>
1724
<Compile Include="$(CommonTestPath)\System\Threading\ThreadTestHelpers.cs">
1825
<Link>CommonTest\System\Threading\ThreadPoolHelpers.cs</Link>

src/System.Threading.Thread/tests/ThreadTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class DummyClass : RemoteExecutorTestBase
1818
public static string HostRunnerTest = HostRunner;
1919
}
2020

21-
public static class ThreadTests
21+
public static partial class ThreadTests
2222
{
2323
private const int UnexpectedTimeoutMilliseconds = ThreadTestHelpers.UnexpectedTimeoutMilliseconds;
2424
private const int ExpectedTimeoutMilliseconds = ThreadTestHelpers.ExpectedTimeoutMilliseconds;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using Xunit;
6+
7+
namespace System.Threading.Threads.Tests
8+
{
9+
public static partial class ThreadTests
10+
{
11+
public static void GetCurrentProcessorId()
12+
{
13+
Assert.True(Thread.GetCurrentProcessorId() >= 0);
14+
}
15+
}
16+
}

0 commit comments

Comments
 (0)