Bug 1267930 - When the wasapi rendering loop is stuck and we're shuttin down, leak the thread and continue the shutdown process. r?kinetik draft
authorPaul Adenot <paul@paul.cx>
Wed, 27 Apr 2016 14:45:07 +0200
changeset 356898 0b8e29f1efece22e0fb4f34d00988b7bce3a1879
parent 356897 abba4ab022aed3fc28710969f0139e8e21fbc547
child 519514 544382a8b081482552dccdfa51de07d2682a35e3
push id16635
push userpaul@paul.cx
push dateWed, 27 Apr 2016 12:45:32 +0000
reviewerskinetik
bugs1267930
milestone48.0a1
Bug 1267930 - When the wasapi rendering loop is stuck and we're shuttin down, leak the thread and continue the shutdown process. r?kinetik It's probably better to not TerminateThread here, because we don't really know what happened down the stack of the rendering loop, so we just leak it. This happens during shutdown so it's not really an issue, it's going to be cleaned up by the OS anyways. MozReview-Commit-ID: G8RZhitfASC
media/libcubeb/src/cubeb_wasapi.cpp
--- a/media/libcubeb/src/cubeb_wasapi.cpp
+++ b/media/libcubeb/src/cubeb_wasapi.cpp
@@ -1173,17 +1173,25 @@ void stop_and_join_render_thread(cubeb_s
     return;
   }
 
   BOOL ok = SetEvent(stm->shutdown_event);
   if (!ok) {
     LOG("Destroy SetEvent failed: %d\n", GetLastError());
   }
 
-  DWORD r = WaitForSingleObject(stm->thread, INFINITE);
+  /* Wait one second for the rendering thread to return. It's supposed to check
+   * its event loop very often, one second is rather conservative. */
+  DWORD r = WaitForSingleObject(stm->thread, 1000);
+  if (r == WAIT_TIMEOUT) {
+    /* Something weird happened, leak the thread and continue the shutdown
+     * process. */
+    LOG("Destroy WaitForSingleObject on thread timed out,"
+        " leaking the thread: %d\n", GetLastError());
+  }
   if (r == WAIT_FAILED) {
     LOG("Destroy WaitForSingleObject on thread failed: %d\n", GetLastError());
   }
 
   CloseHandle(stm->thread);
   stm->thread = NULL;
 
   CloseHandle(stm->shutdown_event);