From dbfb58b850c14eeadac5ac66689fb855c79abf36 Mon Sep 17 00:00:00 2001 From: Noah Richards Date: Tue, 2 Apr 2019 16:18:57 -0700 Subject: [PATCH] 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 Reviewed-by: Tommi Cr-Commit-Position: refs/heads/master@{#27432} --- rtc_base/platform_thread.cc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/rtc_base/platform_thread.cc b/rtc_base/platform_thread.cc index 163e1c378e..63c8f65351 100644 --- a/rtc_base/platform_thread.cc +++ b/rtc_base/platform_thread.cc @@ -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(&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;