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
--- 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");
}