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}
diff --git a/rtc_base/platform_thread.cc b/rtc_base/platform_thread.cc
index 163e1c3..63c8f65 100644
--- a/rtc_base/platform_thread.cc
+++ b/rtc_base/platform_thread.cc
@@ -129,8 +129,15 @@
#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;