Skip to content

Instantly share code, notes, and snippets.

@allstarschh
Created January 8, 2021 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save allstarschh/17eeab8c6f37a979e6eef649fab6c11d to your computer and use it in GitHub Desktop.
Save allstarschh/17eeab8c6f37a979e6eef649fab6c11d to your computer and use it in GitHub Desktop.
commit aa4ab75f13ad4882c25ab77997c907d2b374c39b
Author: Yoshi Cheng-Hao Huang <allstars.chh@gmail.com>
Date: Fri Jan 8 15:50:42 2021 +0100
submit a task to TaskController during XPCOMShutdown.
diff --git a/xpcom/build/XPCOMInit.cpp b/xpcom/build/XPCOMInit.cpp
index 9fd9fb255e41..baaa97753681 100644
--- a/xpcom/build/XPCOMInit.cpp
+++ b/xpcom/build/XPCOMInit.cpp
@@ -572,16 +572,24 @@ void SetICUMemoryFunctions() {
if (!JS_SetICUMemoryFunctions(ICUReporter::Alloc, ICUReporter::Realloc,
ICUReporter::Free)) {
MOZ_CRASH("JS_SetICUMemoryFunctions failed.");
}
sICUReporterInitialized = true;
}
}
+class DummyTask : public Task {
+ public:
+ explicit DummyTask() : Task(false, EventQueuePriority::Normal) {}
+ bool Run() override {
+ return true;
+ }
+};
+
nsresult ShutdownXPCOM(nsIServiceManager* aServMgr) {
// Make sure the hang monitor is enabled for shutdown.
BackgroundHangMonitor().NotifyActivity();
if (!NS_IsMainThread()) {
MOZ_CRASH("Shutdown on wrong thread");
}
@@ -733,16 +741,18 @@ nsresult ShutdownXPCOM(nsIServiceManager* aServMgr) {
} else {
NS_WARNING("Component Manager was never created ...");
}
if (sInitializedJS) {
// Shut down the JS engine.
JS_ShutDown();
sInitializedJS = false;
+
+ TaskController::Get()->AddTask(MakeAndAddRef<DummyTask>());
}
// After all threads have been joined and the component manager has been shut
// down, any remaining objects that could be holding NSS resources (should)
// have been released, so we can safely shut down NSS.
if (NSS_IsInitialized()) {
nsNSSComponent::DoClearSSLExternalAndInternalSessionCache();
if (NSS_Shutdown() != SECSuccess) {
diff --git a/xpcom/threads/TaskController.cpp b/xpcom/threads/TaskController.cpp
index da41135c32d4..7409bdee7f3d 100644
--- a/xpcom/threads/TaskController.cpp
+++ b/xpcom/threads/TaskController.cpp
@@ -206,16 +206,17 @@ void TaskController::RunPoolThread() {
threadName.AppendLiteral("TaskController Thread #");
threadName.AppendInt(static_cast<int64_t>(mThreadPoolIndex));
PROFILER_REGISTER_THREAD(threadName.BeginReading());
MutexAutoLock lock(mGraphMutex);
while (true) {
if (mShuttingDown) {
IOInterposer::UnregisterCurrentThread();
+ MOZ_ASSERT(mThreadableTasks.empty());
return;
}
bool ranTask = false;
if (!mThreadableTasks.empty()) {
for (auto iter = mThreadableTasks.begin(); iter != mThreadableTasks.end();
++iter) {
// Search for the highest priority dependency of the highest priority
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment