Skip to content

Commit b7af339

Browse files
Copilotjkotas
andcommitted
Fix build errors in Thread.Interrupt implementation
Co-authored-by: jkotas <[email protected]>
1 parent e1028d5 commit b7af339

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,12 @@
284284
<Compile Include="$(CommonPath)\Interop\Windows\Kernel32\Interop.DynamicLoad.cs">
285285
<Link>Interop\Windows\Kernel32\Interop.DynamicLoad.cs</Link>
286286
</Compile>
287+
<Compile Include="$(CommonPath)\Interop\Windows\Kernel32\Interop.QueueUserAPC.cs">
288+
<Link>Interop\Windows\Kernel32\Interop.QueueUserAPC.cs</Link>
289+
</Compile>
290+
<Compile Include="$(CommonPath)\Interop\Windows\Kernel32\Interop.Threading.cs">
291+
<Link>Interop\Windows\Kernel32\Interop.Threading.cs</Link>
292+
</Compile>
287293
<Compile Include="System\Threading\Thread.NativeAot.Windows.cs" />
288294
</ItemGroup>
289295
<ItemGroup Condition="'$(TargetsWindows)'=='true'">

src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Thread.NativeAot.Windows.cs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ public sealed partial class Thread
2323
[ThreadStatic]
2424
private static bool t_interruptRequested;
2525

26-
[ThreadStatic]
27-
private static bool t_inAlertableWait;
28-
2926
private SafeWaitHandle _osHandle;
3027

3128
private ApartmentState _initialApartmentState = ApartmentState.Unknown;
@@ -171,27 +168,25 @@ private bool JoinInternal(int millisecondsTimeout)
171168
else
172169
{
173170
Thread? currentThread = t_currentThread;
174-
171+
175172
// Check for pending interrupt from before thread started
176-
if (currentThread != null && currentThread._pendingInterrupt)
173+
if (currentThread is not null && currentThread._pendingInterrupt)
177174
{
178175
currentThread._pendingInterrupt = false;
179176
throw new ThreadInterruptedException();
180177
}
181178

182-
if (currentThread != null)
179+
if (currentThread is not null)
183180
{
184181
currentThread.SetWaitSleepJoinState();
185182
}
186183

187184
try
188185
{
189-
t_inAlertableWait = true;
190-
191186
// Use alertable wait so we can be interrupted by APC
192-
result = (int)Interop.Kernel32.WaitForSingleObjectEx(waitHandle.DangerousGetHandle(),
187+
result = (int)Interop.Kernel32.WaitForSingleObjectEx(waitHandle.DangerousGetHandle(),
193188
(uint)millisecondsTimeout, Interop.BOOL.TRUE);
194-
189+
195190
// Check if we were interrupted by an APC
196191
if (result == Interop.Kernel32.WAIT_IO_COMPLETION)
197192
{
@@ -201,8 +196,7 @@ private bool JoinInternal(int millisecondsTimeout)
201196
}
202197
finally
203198
{
204-
t_inAlertableWait = false;
205-
if (currentThread != null)
199+
if (currentThread is not null)
206200
{
207201
currentThread.ClearWaitSleepJoinState();
208202
}
@@ -273,14 +267,14 @@ private static uint ThreadEntryPoint(IntPtr parameter)
273267
private static void CheckPendingInterrupt()
274268
{
275269
Thread? currentThread = t_currentThread;
276-
if (currentThread != null && currentThread._pendingInterrupt)
270+
if (currentThread is not null && currentThread._pendingInterrupt)
277271
{
278272
currentThread._pendingInterrupt = false;
279273
throw new ThreadInterruptedException();
280274
}
281275
}
282276

283-
partial void CheckForPendingInterrupt()
277+
private static void CheckForPendingInterrupt()
284278
{
285279
CheckPendingInterrupt();
286280
}
@@ -462,8 +456,8 @@ private static void CheckForInterrupt()
462456
}
463457
}
464458

465-
public void Interrupt()
466-
{
459+
public void Interrupt()
460+
{
467461
using (_lock.EnterScope())
468462
{
469463
// If thread is dead, do nothing
@@ -479,7 +473,7 @@ public void Interrupt()
479473

480474
// Queue APC to interrupt the thread
481475
SafeWaitHandle osHandle = _osHandle;
482-
if (osHandle != null && !osHandle.IsInvalid && !osHandle.IsClosed)
476+
if (osHandle is not null && !osHandle.IsInvalid && !osHandle.IsClosed)
483477
{
484478
nint callbackPtr;
485479
unsafe

0 commit comments

Comments
 (0)