mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-09 22:48:27 +00:00
Bug 1035075 - Dispatch a runnable to wait for the PAC thread to shutdown. r=mcmanus
This commit is contained in:
parent
625adb8d57
commit
81e4019cf2
@ -113,6 +113,30 @@ private:
|
||||
nsCOMPtr<nsIThread> 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<nsPACMan> mPACMan;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// PACLoadComplete allows the PAC thread to tell the main thread that
|
||||
@ -292,9 +316,15 @@ 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<WaitForThreadShutdown> runnable = new WaitForThreadShutdown(this);
|
||||
NS_DispatchToMainThread(runnable);
|
||||
}
|
||||
|
||||
nsresult
|
||||
@ -502,11 +532,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
|
||||
|
@ -24,6 +24,7 @@
|
||||
class nsPACMan;
|
||||
class nsISystemProxySettings;
|
||||
class nsIThread;
|
||||
class WaitForThreadShutdown;
|
||||
|
||||
/**
|
||||
* This class defines a callback interface used by AsyncGetProxyForURI.
|
||||
@ -164,6 +165,7 @@ private:
|
||||
friend class PendingPACQuery;
|
||||
friend class PACLoadComplete;
|
||||
friend class ExecutePACThreadAction;
|
||||
friend class WaitForThreadShutdown;
|
||||
|
||||
~nsPACMan();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user