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

Enable thread interrupt in finally blocks, remove some invalid asserts #8953

Merged
merged 2 commits into from
Jan 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 4 additions & 15 deletions src/vm/threads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4533,9 +4533,6 @@ DWORD Thread::DoAppropriateWaitWorker(int countHandles, HANDLE *handles, BOOL wa
{
// Probe all handles with a timeout of zero. When we find one that's
// invalid, move it out of the list and retry the wait.
#ifdef _DEBUG
BOOL fFoundInvalid = FALSE;
#endif
for (int i = 0; i < countHandles; i++)
{
// WaitForSingleObject won't pump memssage; we already probe enough space
Expand All @@ -4548,12 +4545,8 @@ DWORD Thread::DoAppropriateWaitWorker(int countHandles, HANDLE *handles, BOOL wa
if ((countHandles - i - 1) > 0)
memmove(&handles[i], &handles[i+1], (countHandles - i - 1) * sizeof(HANDLE));
countHandles--;
#ifdef _DEBUG
fFoundInvalid = TRUE;
#endif
break;
}
_ASSERTE(fFoundInvalid);

// Compute the new timeout value by assume that the timeout
// is not large enough for more than one wrap
Expand Down Expand Up @@ -4599,7 +4592,6 @@ DWORD Thread::DoAppropriateWaitWorker(int countHandles, HANDLE *handles, BOOL wa
_ASSERTE(subRet == WAIT_TIMEOUT);
ret++;
}
_ASSERTE(i != countHandles);
}
}

Expand Down Expand Up @@ -6807,17 +6799,14 @@ void Thread::HandleThreadInterrupt (BOOL fWaitForADUnload)
}
if ((m_UserInterrupt & TI_Interrupt) != 0)
{
if (ReadyForInterrupt())
{
ResetThreadState ((ThreadState)(TS_Interrupted | TS_Interruptible));
FastInterlockAnd ((DWORD*)&m_UserInterrupt, ~TI_Interrupt);
ResetThreadState ((ThreadState)(TS_Interrupted | TS_Interruptible));
FastInterlockAnd ((DWORD*)&m_UserInterrupt, ~TI_Interrupt);

#ifdef _DEBUG
AddFiberInfo(ThreadTrackInfo_Abort);
AddFiberInfo(ThreadTrackInfo_Abort);
#endif

COMPlusThrow(kThreadInterruptedException);
}
COMPlusThrow(kThreadInterruptedException);
}
END_SO_INTOLERANT_CODE;
}
Expand Down
9 changes: 2 additions & 7 deletions src/vm/threads.h
Original file line number Diff line number Diff line change
Expand Up @@ -3166,12 +3166,7 @@ class Thread: public IUnknown
};

private:
BOOL ReadyForInterrupt()
{
return ReadyForAsyncException(TI_Interrupt);
}

BOOL ReadyForAsyncException(ThreadInterruptMode mode);
BOOL ReadyForAsyncException();

public:
inline BOOL IsYieldRequested()
Expand All @@ -3185,7 +3180,7 @@ class Thread: public IUnknown
void SetAbortRequest(EEPolicy::ThreadAbortTypes abortType); // Should only be called by ADUnload
BOOL ReadyForAbort()
{
return ReadyForAsyncException(TI_Abort);
return ReadyForAsyncException();
}

BOOL IsRudeAbort();
Expand Down
5 changes: 2 additions & 3 deletions src/vm/threadsuspend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1345,7 +1345,7 @@ BOOL Thread::IsSafeToInjectThreadAbort(PTR_CONTEXT pContextToCheck)
#endif


BOOL Thread::ReadyForAsyncException(ThreadInterruptMode mode)
BOOL Thread::ReadyForAsyncException()
{
CONTRACTL {
NOTHROW;
Expand All @@ -1354,8 +1354,7 @@ BOOL Thread::ReadyForAsyncException(ThreadInterruptMode mode)
}
CONTRACTL_END;

if (((mode & TI_Abort) != 0 && !IsAbortRequested()) ||
((mode & TI_Interrupt) != 0 && (m_UserInterrupt & TI_Interrupt) == 0))
if (!IsAbortRequested())
{
return FALSE;
}
Expand Down