Ignore ERROR_ACCESS_DENIED when stopping Windows platform threads.

Wine implements ::QueueUserAPC incorrectly and returns
ERROR_ACCESS_DENIED when the thread is terminating instead of
ERROR_GEN_FAILURE. This is (hopefully) safe to do, assuming
the correct Windows implementation would never use ERROR_ACCESS_DENIED
in an actual failure case. I can't find documentation that says one
way or the other.

Bug: None
Change-Id: If74a40bb7e1cd49cc2266c31684bd88f1c667422
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/131042
Commit-Queue: Tommi <tommi@webrtc.org>
Reviewed-by: Tommi <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27432}
This commit is contained in:
Noah Richards 2019-04-02 16:18:57 -07:00 committed by Commit Bot
parent d9bf720c20
commit dbfb58b850

View File

@ -129,8 +129,15 @@ void PlatformThread::Stop() {
#if defined(WEBRTC_WIN)
// Set stop_ to |true| on the worker thread.
bool queued = QueueAPC(&RaiseFlag, reinterpret_cast<ULONG_PTR>(&stop_));
// Queuing the APC can fail if the thread is being terminated.
RTC_CHECK(queued || GetLastError() == ERROR_GEN_FAILURE);
if (!queued) {
// Queuing the APC can fail if the thread is being terminated. This should
// return ERROR_GEN_FAILURE, though Wine returns ERROR_ACCESS_DENIED, so
// allow for either.
auto error = ::GetLastError();
if (error != ERROR_GEN_FAILURE && error != ERROR_ACCESS_DENIED) {
RTC_CHECK(false) << "Failed to QueueUserAPC, error: " << error;
}
}
WaitForSingleObject(thread_, INFINITE);
CloseHandle(thread_);
thread_ = nullptr;