Bug 712363, Part 1: Make SyncRunnableBase work without deadlocking when run on the main thread, r=honzab,a=Standard8 for checkin to comm specific relbranch COMM110_2012030905_RELBRANCH
authorHonza Bambas <honzab.moz@firemni.cz>
Tue, 31 Jan 2012 08:04:53 -0800
branchCOMM110_2012030905_RELBRANCH
changeset 85560 62eb597357c950d2b429d155415c0b3f6c84e287
parent 85555 ff0935d61662c03c01e5e543bd299782aa3ff46a
child 85561 e830af29b2b6ac3fe1df5def4c50cd218d55f129
push id1
push usersledru@mozilla.com
push dateThu, 04 Dec 2014 17:57:20 +0000
reviewershonzab, Standard8
bugs712363
milestone11.0
Bug 712363, Part 1: Make SyncRunnableBase work without deadlocking when run on the main thread, r=honzab,a=Standard8 for checkin to comm specific relbranch
security/manager/ssl/src/PSMRunnable.cpp
security/manager/ssl/src/nsNSSCallbacks.cpp
security/manager/ssl/src/nsNSSIOLayer.cpp
--- a/security/manager/ssl/src/PSMRunnable.cpp
+++ b/security/manager/ssl/src/PSMRunnable.cpp
@@ -41,24 +41,28 @@ namespace mozilla { namespace psm {
 SyncRunnableBase::SyncRunnableBase()
   : monitor("SyncRunnableBase::monitor")
 {
 }
 
 nsresult
 SyncRunnableBase::DispatchToMainThreadAndWait()
 {
-  NS_ASSERTION(!NS_IsMainThread(),
-               "DispatchToMainThreadAndWait called on the main thread.");
+  nsresult rv;
+  if (NS_IsMainThread()) {
+    RunOnTargetThread();
+    rv = NS_OK;
+  } else {
+    mozilla::MonitorAutoLock lock(monitor);
+    rv = NS_DispatchToMainThread(this);
+    if (NS_SUCCEEDED(rv)) {
+      lock.Wait();
+    }
+  }
 
-  mozilla::MonitorAutoLock lock(monitor);
-  nsresult rv = NS_DispatchToMainThread(this);
-  if (NS_SUCCEEDED(rv)) {
-    lock.Wait();
-  }
   return rv;
 }
 
 NS_IMETHODIMP
 SyncRunnableBase::Run()
 {
   RunOnTargetThread();
   mozilla::MonitorAutoLock(monitor).Notify();
--- a/security/manager/ssl/src/nsNSSCallbacks.cpp
+++ b/security/manager/ssl/src/nsNSSCallbacks.cpp
@@ -810,21 +810,17 @@ void PK11PasswordPromptRunnable::RunOnTa
 }
 
 char* PR_CALLBACK
 PK11PasswordPrompt(PK11SlotInfo* slot, PRBool retry, void* arg)
 {
   nsRefPtr<PK11PasswordPromptRunnable> runnable = 
     new PK11PasswordPromptRunnable(slot,
                                    static_cast<nsIInterfaceRequestor*>(arg));
-  if (NS_IsMainThread()) {
-    runnable->RunOnTargetThread();
-  } else {
-    runnable->DispatchToMainThreadAndWait();
-  }
+  runnable->DispatchToMainThreadAndWait();
   return runnable->mResult;
 }
 
 void PR_CALLBACK HandshakeCallback(PRFileDesc* fd, void* client_data) {
   nsNSSShutDownPreventionLock locker;
   PRInt32 sslStatus;
   char* signer = nsnull;
   char* cipherName = nsnull;
--- a/security/manager/ssl/src/nsNSSIOLayer.cpp
+++ b/security/manager/ssl/src/nsNSSIOLayer.cpp
@@ -939,21 +939,16 @@ private:
   nsCOMPtr<nsIInterfaceRequestor> mCallbacks; // in
 };
 
 void nsNSSSocketInfo::GetPreviousCert(nsIX509Cert** _result)
 {
   NS_ASSERTION(_result, "_result parameter to GetPreviousCert is null");
   *_result = nsnull;
 
-  if (NS_IsMainThread()) {
-    NS_ERROR("nsNSSSocketInfo::GetPreviousCert called on the main thread");
-    return;
-  }
-
   nsRefPtr<PreviousCertRunnable> runnable = new PreviousCertRunnable(mCallbacks);
   nsresult rv = runnable->DispatchToMainThreadAndWait();
   NS_ASSERTION(NS_SUCCEEDED(rv), "runnable->DispatchToMainThreadAndWait() failed");
   runnable->mPreviousCert.forget(_result);
 }
 
 void
 nsNSSSocketInfo::SetCertVerificationWaiting()