@@ -23,9 +23,6 @@ public sealed partial class Thread
23
23
[ ThreadStatic ]
24
24
private static bool t_interruptRequested ;
25
25
26
- [ ThreadStatic ]
27
- private static bool t_inAlertableWait ;
28
-
29
26
private SafeWaitHandle _osHandle ;
30
27
31
28
private ApartmentState _initialApartmentState = ApartmentState . Unknown ;
@@ -171,27 +168,25 @@ private bool JoinInternal(int millisecondsTimeout)
171
168
else
172
169
{
173
170
Thread ? currentThread = t_currentThread ;
174
-
171
+
175
172
// Check for pending interrupt from before thread started
176
- if ( currentThread != null && currentThread . _pendingInterrupt )
173
+ if ( currentThread is not null && currentThread . _pendingInterrupt )
177
174
{
178
175
currentThread . _pendingInterrupt = false ;
179
176
throw new ThreadInterruptedException ( ) ;
180
177
}
181
178
182
- if ( currentThread != null )
179
+ if ( currentThread is not null )
183
180
{
184
181
currentThread . SetWaitSleepJoinState ( ) ;
185
182
}
186
183
187
184
try
188
185
{
189
- t_inAlertableWait = true ;
190
-
191
186
// 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 ( ) ,
193
188
( uint ) millisecondsTimeout , Interop . BOOL . TRUE ) ;
194
-
189
+
195
190
// Check if we were interrupted by an APC
196
191
if ( result == Interop . Kernel32 . WAIT_IO_COMPLETION )
197
192
{
@@ -201,8 +196,7 @@ private bool JoinInternal(int millisecondsTimeout)
201
196
}
202
197
finally
203
198
{
204
- t_inAlertableWait = false ;
205
- if ( currentThread != null )
199
+ if ( currentThread is not null )
206
200
{
207
201
currentThread . ClearWaitSleepJoinState ( ) ;
208
202
}
@@ -273,14 +267,14 @@ private static uint ThreadEntryPoint(IntPtr parameter)
273
267
private static void CheckPendingInterrupt ( )
274
268
{
275
269
Thread ? currentThread = t_currentThread ;
276
- if ( currentThread != null && currentThread . _pendingInterrupt )
270
+ if ( currentThread is not null && currentThread . _pendingInterrupt )
277
271
{
278
272
currentThread . _pendingInterrupt = false ;
279
273
throw new ThreadInterruptedException ( ) ;
280
274
}
281
275
}
282
276
283
- partial void CheckForPendingInterrupt ( )
277
+ private static void CheckForPendingInterrupt ( )
284
278
{
285
279
CheckPendingInterrupt ( ) ;
286
280
}
@@ -462,8 +456,8 @@ private static void CheckForInterrupt()
462
456
}
463
457
}
464
458
465
- public void Interrupt ( )
466
- {
459
+ public void Interrupt ( )
460
+ {
467
461
using ( _lock . EnterScope ( ) )
468
462
{
469
463
// If thread is dead, do nothing
@@ -479,7 +473,7 @@ public void Interrupt()
479
473
480
474
// Queue APC to interrupt the thread
481
475
SafeWaitHandle osHandle = _osHandle ;
482
- if ( osHandle != null && ! osHandle . IsInvalid && ! osHandle . IsClosed )
476
+ if ( osHandle is not null && ! osHandle . IsInvalid && ! osHandle . IsClosed )
483
477
{
484
478
nint callbackPtr ;
485
479
unsafe
0 commit comments