Bug 1388464: Use SyncRunnable instead of DISPATCH_SYNC to actually block the main thread during the blocking preference file write. r?smaug draft
authorMilan Sreckovic <milan@mozilla.com>
Tue, 08 Aug 2017 17:14:28 -0400
changeset 642863 98327f468bae2b269b15b5987a0f2f2b53a5aeb0
parent 642518 a921bfb8a2cf3db4d9edebe9b35799a3f9d035da
child 725122 40acbb44349cfc101456ecf5eda342a03e66e29c
push id72890
push userbmo:milan@mozilla.com
push dateTue, 08 Aug 2017 21:14:50 +0000
reviewerssmaug
bugs1388464
milestone57.0a1
Bug 1388464: Use SyncRunnable instead of DISPATCH_SYNC to actually block the main thread during the blocking preference file write. r?smaug MozReview-Commit-ID: 6J1252Q3pBr
modules/libpref/Preferences.cpp
--- a/modules/libpref/Preferences.cpp
+++ b/modules/libpref/Preferences.cpp
@@ -6,16 +6,17 @@
 
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/dom/PContent.h"
 
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/HashFunctions.h"
 #include "mozilla/ServoStyleSet.h"
+#include "mozilla/SyncRunnable.h"
 #include "mozilla/Telemetry.h"
 #include "mozilla/UniquePtrExtensions.h"
 
 #include "nsXULAppAPI.h"
 
 #include "mozilla/Preferences.h"
 #include "nsAppDirectoryServiceDefs.h"
 #include "nsDataHashtable.h"
@@ -1236,19 +1237,23 @@ Preferences::WritePrefFile(nsIFile* aFil
       return rv;
     } else {
       // There were no previous requests, dispatch one since
       // sPendingWriteData has the up to date information.
       nsCOMPtr<nsIEventTarget> target =
         do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID, &rv);
       if (NS_SUCCEEDED(rv)) {
         bool async = aSaveMethod == SaveMethod::Asynchronous;
-        rv = target->Dispatch(new PWRunnable(aFile),
-                              async ? nsIEventTarget::DISPATCH_NORMAL :
-                                      nsIEventTarget::DISPATCH_SYNC);
+        if (async) {
+          rv = target->Dispatch(new PWRunnable(aFile),
+                                nsIEventTarget::DISPATCH_NORMAL);
+        } else {
+          // Note that we don't get the nsresult return value here
+          SyncRunnable::DispatchToThread(target, new PWRunnable(aFile), true);
+        }
         return rv;
       }
     }
 
     // If we can't get the thread for writing, for whatever reason, do the
     // main thread write after making some noise:
     MOZ_ASSERT(false,"failed to get the target thread for OMT pref write");
   }