Bug 1637433 - P2. Replace ShutdownBackgroundThreadRunnable with simple task for clarity. r=nika

Differential Revision: https://phabricator.services.mozilla.com/D74993
This commit is contained in:
Jean-Yves Avenard 2020-05-14 02:01:16 +00:00
Родитель 1885d1e5ea
Коммит d73d4e516d
1 изменённых файлов: 12 добавлений и 31 удалений

Просмотреть файл

@ -98,7 +98,6 @@ class ParentImpl final : public BackgroundParentImpl {
private:
class ShutdownObserver;
class ShutdownBackgroundThreadRunnable;
class ForceCloseBackgroundActorsRunnable;
class ConnectActorRunnable;
class CreateActorHelper;
@ -551,20 +550,6 @@ class ParentImpl::ShutdownObserver final : public nsIObserver {
~ShutdownObserver() { AssertIsOnMainThread(); }
};
class ParentImpl::ShutdownBackgroundThreadRunnable final : public Runnable {
public:
ShutdownBackgroundThreadRunnable()
: Runnable("Background::ParentImpl::ShutdownBackgroundThreadRunnable") {
AssertIsInMainOrSocketProcess();
AssertIsOnMainThread();
}
private:
~ShutdownBackgroundThreadRunnable() = default;
NS_DECL_NSIRUNNABLE
};
class ParentImpl::ForceCloseBackgroundActorsRunnable final : public Runnable {
nsTArray<ParentImpl*>* mActorArray;
@ -1367,10 +1352,18 @@ void ParentImpl::ShutdownBackgroundThread() {
MOZ_ALWAYS_SUCCEEDS(shutdownTimer->Cancel());
}
// Dispatch this runnable to unregister the thread from the profiler.
nsCOMPtr<nsIRunnable> shutdownRunnable =
new ShutdownBackgroundThreadRunnable();
MOZ_ALWAYS_SUCCEEDS(thread->Dispatch(shutdownRunnable, NS_DISPATCH_NORMAL));
// Dispatch this runnable to unregister the PR thread from the profiler.
MOZ_ALWAYS_SUCCEEDS(thread->Dispatch(
NS_NewRunnableFunction(
"Background::ParentImpl::ShutdownBackgroundThreadRunnable",
[]() {
// It is possible that another background thread was created while
// this thread was shutting down. In that case we can't assert
// anything about sBackgroundPRThread and we should not modify it
// here.
sBackgroundPRThread.compareExchange(PR_GetCurrentThread(),
nullptr);
})));
MOZ_ALWAYS_SUCCEEDS(thread->Shutdown());
}
@ -1468,18 +1461,6 @@ ParentImpl::ShutdownObserver::Observe(nsISupports* aSubject, const char* aTopic,
return NS_OK;
}
NS_IMETHODIMP
ParentImpl::ShutdownBackgroundThreadRunnable::Run() {
AssertIsInMainOrSocketProcess();
// It is possible that another background thread was created while this thread
// was shutting down. In that case we can't assert anything about
// sBackgroundPRThread and we should not modify it here.
sBackgroundPRThread.compareExchange(PR_GetCurrentThread(), nullptr);
return NS_OK;
}
NS_IMETHODIMP
ParentImpl::ForceCloseBackgroundActorsRunnable::Run() {
AssertIsInMainOrSocketProcess();