$OpenBSD$ index 7cfce72..e8b0b2d 100644 --- netwerk/base/src/nsPACMan.cpp.orig Fri Feb 20 15:40:37 2015 +++ netwerk/base/src/nsPACMan.cpp Fri Feb 20 15:40:37 2015 @@ -113,6 +113,30 @@ private: nsCOMPtr mThread; }; +// Dispatch this to wait until the PAC thread shuts down. + +class WaitForThreadShutdown MOZ_FINAL : public nsRunnable +{ +public: + explicit WaitForThreadShutdown(nsPACMan *aPACMan) + : mPACMan(aPACMan) + { + } + + NS_IMETHODIMP Run() + { + NS_ABORT_IF_FALSE(NS_IsMainThread(), "wrong thread"); + if (mPACMan->mPACThread) { + mPACMan->mPACThread->Shutdown(); + mPACMan->mPACThread = nullptr; + } + return NS_OK; + } + +private: + nsRefPtr mPACMan; +}; + //----------------------------------------------------------------------------- // PACLoadComplete allows the PAC thread to tell the main thread that @@ -284,14 +308,20 @@ void nsPACMan::Shutdown() { NS_ABORT_IF_FALSE(NS_IsMainThread(), "pacman must be shutdown on main thread"); - CancelExistingLoad(); + if (mShutdown) { + return; + } mShutdown = true; + CancelExistingLoad(); PostCancelPendingQ(NS_ERROR_ABORT); + + nsRefPtr runnable = new WaitForThreadShutdown(this); + NS_DispatchToMainThread(runnable); } nsresult -nsPACMan::AsyncGetProxyForURI(nsIURI *uri, nsPACManCallback *callback, - bool mainThreadResponse) +nsPACMan::AsyncGetProxyForChannel(nsIChannel *channel, nsPACManCallback *callback, + bool mainThreadResponse) { NS_ABORT_IF_FALSE(NS_IsMainThread(), "wrong thread"); if (mShutdown) @@ -302,6 +332,11 @@ nsPACMan::AsyncGetProxyForURI(nsIURI *uri, nsPACManCallback *callback, TimeStamp::Now() > mScheduledReload) LoadPACFromURI(EmptyCString()); + nsCOMPtr uri; + nsresult rv = channel->GetURI(getter_AddRefs(uri)); + if (NS_FAILED(rv)) + return rv; + nsRefPtr query = new PendingPACQuery(this, uri, callback, mainThreadResponse); @@ -494,11 +529,12 @@ nsPACMan::ProcessPendingQ() NS_ABORT_IF_FALSE(!NS_IsMainThread(), "wrong thread"); while (ProcessPending()); - // do GC while the thread has nothing pending - mPAC.GC(); - - if (mShutdown) + if (mShutdown) { mPAC.Shutdown(); + } else { + // do GC while the thread has nothing pending + mPAC.GC(); + } } // returns true if progress was made by shortening the queue