Bug 1518946 - Use the Await method instead of a sync dispatch because the latter allows the event loop to run while waiting. r=pehrsons
authorAlex Chronopoulos <achronop@gmail.com>
Thu, 14 Mar 2019 12:44:57 +0000
changeset 521874 6e7fb729f772
parent 521873 802aec0783a7
child 521875 df7a6846edf5
push id10870
push usernbeleuzu@mozilla.com
push dateFri, 15 Mar 2019 20:00:07 +0000
treeherdermozilla-beta@c594aee5b7a4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspehrsons
bugs1518946
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1518946 - Use the Await method instead of a sync dispatch because the latter allows the event loop to run while waiting. r=pehrsons Differential Revision: https://phabricator.services.mozilla.com/D23476
dom/media/webrtc/MediaEngineDefault.cpp
--- a/dom/media/webrtc/MediaEngineDefault.cpp
+++ b/dom/media/webrtc/MediaEngineDefault.cpp
@@ -32,24 +32,28 @@ namespace mozilla {
 
 using namespace mozilla::gfx;
 
 static nsString DefaultVideoName() {
   // For the purpose of testing we allow to change the name of the fake device
   // by pref.
   nsAutoString cameraNameFromPref;
   nsresult rv;
-  NS_DispatchToMainThread(
-      NS_NewRunnableFunction(__func__,
-                             [&]() {
-                               rv = Preferences::GetString(
-                                   "media.getusermedia.fake-camera-name",
-                                   cameraNameFromPref);
-                             }),
-      NS_DISPATCH_SYNC);
+  // Here it is preferred a "hard" block, provided by the combination of Await &
+  // InvokeAsync, instead of "soft" block, provided by sync dispatch which
+  // allows the waiting thread to spin its event loop. The latter would allow
+  // miltiple enumeration requests being processed out-of-order.
+  media::Await(
+      do_AddRef(SystemGroup::EventTargetFor(TaskCategory::Other)),
+      InvokeAsync(
+          SystemGroup::EventTargetFor(TaskCategory::Other), __func__, [&]() {
+            rv = Preferences::GetString("media.getusermedia.fake-camera-name",
+                                        cameraNameFromPref);
+            return GenericPromise::CreateAndResolve(true, __func__);
+          }));
 
   if (NS_SUCCEEDED(rv)) {
     return std::move(cameraNameFromPref);
   }
   return NS_LITERAL_STRING(u"Default Video Device");
 }
 
 /**