Bug 1851045 - Part 5: Eliminate nsThreadManager's static destructor, r=emilio

This both reduces the number of registered static destructors, and avoids the
assertion in the LinkedList destructor without depending on a StaticAutoPointer
(which requires an allocation & additional indirection) by using the new
NeverDestroyed type from part 4.

Differential Revision: https://phabricator.services.mozilla.com/D189249
This commit is contained in:
Nika Layzell 2023-09-27 19:14:17 +00:00
parent 9411a9ed15
commit f6b6fca22f
2 changed files with 8 additions and 2 deletions

View File

@ -20,6 +20,7 @@
#include "mozilla/EventQueue.h"
#include "mozilla/InputTaskManager.h"
#include "mozilla/Mutex.h"
#include "mozilla/NeverDestroyed.h"
#include "mozilla/Preferences.h"
#include "mozilla/ProfilerMarkers.h"
#include "mozilla/SpinEventLoopUntil.h"
@ -257,8 +258,8 @@ NS_IMPL_CI_INTERFACE_GETTER(nsThreadManager, nsIThreadManager)
//-----------------------------------------------------------------------------
/*static*/ nsThreadManager& nsThreadManager::get() {
static nsThreadManager sInstance;
return sInstance;
static NeverDestroyed<nsThreadManager> sInstance;
return *sInstance;
}
nsThreadManager::nsThreadManager()

View File

@ -18,6 +18,9 @@ namespace mozilla {
class IdleTaskManager;
class SynchronizedEventQueue;
class TaskQueue;
template <typename T>
class NeverDestroyed;
} // namespace mozilla
class BackgroundEventTarget;
@ -103,6 +106,8 @@ class nsThreadManager : public nsIThreadManager {
}
private:
friend class mozilla::NeverDestroyed<nsThreadManager>;
nsThreadManager();
nsresult SpinEventLoopUntilInternal(