Bug 1313200 - Init AbstractThread properly and early. r=froydnj

Separate AbstractThread::InitTLS and
AbstractThread::InitMainThread. Init AbstractThread main thread when
init nsThreadManager. Init AbstractThread TLS for all content process
types because for plugin and gmp processes we are doing IPC even
without init XPCOM and for content process init XPCOM requires IPC.

MozReview-Commit-ID: DhLub23oZz8
This commit is contained in:
Kan-Ru Chen
2017-04-19 13:24:09 +08:00
parent e6d010d8bf
commit fec6124d1c
5 changed files with 22 additions and 7 deletions

View File

@@ -57,6 +57,8 @@
#include "mozilla/jni/Utils.h"
#endif // defined(MOZ_WIDGET_ANDROID)
#include "mozilla/AbstractThread.h"
#include "mozilla/ipc/BrowserProcessSubThread.h"
#include "mozilla/ipc/GeckoChildProcessHost.h"
#include "mozilla/ipc/IOThreadChild.h"
@@ -419,6 +421,10 @@ XRE_InitChildProcess(int aArgc,
PROFILER_LABEL("Startup", "XRE_InitChildProcess",
js::ProfileEntry::Category::OTHER);
// Ensure AbstractThread is minimally setup, so async IPC messages
// work properly.
AbstractThread::InitTLS();
// Complete 'task_t' exchange for Mac OS X. This structure has the same size
// regardless of architecture so we don't have any cross-arch issues here.
#ifdef XP_MACOSX

View File

@@ -6,7 +6,6 @@
#include "base/basictypes.h"
#include "mozilla/AbstractThread.h"
#include "mozilla/Atomics.h"
#include "mozilla/Poison.h"
#include "mozilla/SharedThreadPool.h"
@@ -681,9 +680,6 @@ NS_InitXPCOM2(nsIServiceManager** aResult,
}
sInitializedJS = true;
// Init AbstractThread.
AbstractThread::InitStatics();
rv = nsComponentManagerImpl::gComponentManager->Init();
if (NS_FAILED(rv)) {
NS_RELEASE(nsComponentManagerImpl::gComponentManager);
@@ -791,7 +787,6 @@ NS_InitMinimalXPCOM()
return NS_ERROR_UNEXPECTED;
}
AbstractThread::InitStatics();
SharedThreadPool::InitStatics();
mozilla::Telemetry::Init();
mozilla::HangMonitor::Startup();

View File

@@ -251,7 +251,15 @@ AbstractThread::MainThread()
}
void
AbstractThread::InitStatics()
AbstractThread::InitTLS()
{
if (!sCurrentThreadTLS.init()) {
MOZ_CRASH();
}
}
void
AbstractThread::InitMainThread()
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(!sMainThread);

View File

@@ -95,7 +95,8 @@ public:
static AbstractThread* MainThread();
// Must be called exactly once during startup.
static void InitStatics();
static void InitTLS();
static void InitMainThread();
void DispatchStateChange(already_AddRefed<nsIRunnable> aRunnable);

View File

@@ -10,6 +10,7 @@
#include "nsIClassInfoImpl.h"
#include "nsTArray.h"
#include "nsAutoPtr.h"
#include "mozilla/AbstractThread.h"
#include "mozilla/ThreadLocal.h"
#ifdef MOZ_CANARY
#include <fcntl.h>
@@ -110,6 +111,10 @@ nsThreadManager::Init()
// GetIsMainThread calls that occur post-Shutdown.
mMainThread->GetPRThread(&mMainPRThread);
// Init AbstractThread.
AbstractThread::InitTLS();
AbstractThread::InitMainThread();
mInitialized = true;
return NS_OK;
}