Bug 771765 - Support template content process, part 8: process initialization flow changes. r=khuey

Changes initialization code for the template process:
* Let the process run for NUWA_PREPARATION_TIME ms and then start freezing the threads.
* Delay android binder thread pool creation after the content process is forked from the template and other thread recreation has finished.
* Poke the app shell after the content process is forked from the template.
This commit is contained in:
Thinker Lee ext:(%2C%20Cervantes%20Yu%20%3Ccyu%40mozilla.com%3E) 2013-06-03 18:14:46 +08:00
parent e1fe721d99
commit cee2c827a4
3 changed files with 83 additions and 8 deletions

View File

@ -41,15 +41,14 @@
#endif
int
main(int argc, char* argv[])
{
#ifdef MOZ_WIDGET_GONK
// This creates a ThreadPool for binder ipc. A ThreadPool is necessary to
// receive binder calls, though not necessary to send binder calls.
// ProcessState::Self() also needs to be called once on the main thread to
// register the main thread with the binder driver.
#ifdef MOZ_NUWA_PROCESS
#include <binder/ProcessState.h>
#include "ipc/Nuwa.h"
#endif
#ifdef MOZ_WIDGET_GONK
static void
InitializeBinder(void *aDummy) {
// Change thread priority to 0 only during calling ProcessState::self().
// The priority is registered to binder driver and used for default Binder
// Thread's priority.
@ -60,6 +59,38 @@ main(int argc, char* argv[])
LOGE_IF(err, "setpriority failed. Current process needs root permission.");
android::ProcessState::self()->startThreadPool();
setpriority(PRIO_PROCESS, 0, curPrio);
}
#endif
int
main(int argc, char* argv[])
{
#ifdef MOZ_NUWA_PROCESS
bool isNuwa = false;
for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], "-nuwa") == 0) {
PrepareNuwaProcess();
isNuwa = true;
break;
}
}
#endif
#ifdef MOZ_WIDGET_GONK
// This creates a ThreadPool for binder ipc. A ThreadPool is necessary to
// receive binder calls, though not necessary to send binder calls.
// ProcessState::Self() also needs to be called once on the main thread to
// register the main thread with the binder driver.
#ifdef MOZ_NUWA_PROCESS
if (!isNuwa) {
InitializeBinder(nullptr);
} else {
NuwaAddFinalConstructor(&InitializeBinder, nullptr);
}
#else
InitializeBinder(nullptr);
#endif
#endif
#if defined(XP_WIN) && defined(DEBUG_bent)

View File

@ -77,6 +77,11 @@
using mozilla::_ipdltest::IPDLUnitTestProcessChild;
#endif // ifdef MOZ_IPDL_TESTS
#ifdef MOZ_NUWA_PROCESS
#include "nsITimer.h"
#define NUWA_PREPARATION_TIME 1000
#endif
using namespace mozilla;
using mozilla::ipc::BrowserProcessSubThread;
@ -102,6 +107,13 @@ static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);
static const PRUnichar kShellLibraryName[] = L"shell32.dll";
#endif
#ifdef MOZ_NUWA_PROCESS
extern "C" {
void PrepareNuwaProcess() __attribute__((weak));
void MakeNuwaProcess() __attribute__((weak));
};
#endif
nsresult
XRE_LockProfileDirectory(nsIFile* aDirectory,
nsISupports* *aLockObject)
@ -265,6 +277,16 @@ SetTaskbarGroupId(const nsString& aId)
}
#endif
#ifdef MOZ_NUWA_PROCESS
void
OnFinishNuwaPreparation(nsITimer *aTimer, void *aClosure)
{
NS_ASSERTION(MakeNuwaProcess != nullptr,
"MakeNuwaProcess() is not available!");
MakeNuwaProcess();
}
#endif
nsresult
XRE_InitChildProcess(int aArgc,
char* aArgv[],
@ -512,6 +534,19 @@ XRE_InitChildProcess(int aArgc,
return NS_ERROR_FAILURE;
}
#ifdef MOZ_NUWA_PROCESS
nsCOMPtr<nsITimer> timer;
if (aProcess == GeckoProcessType_Content &&
CommandLine::ForCurrentProcess()->HasSwitch(L"nuwa")) {
// Wait the Nuwa process for NUWA_PREPARATION_TIME ms.
timer = do_CreateInstance(NS_TIMER_CONTRACTID);
rv = timer->InitWithFuncCallback(OnFinishNuwaPreparation,
nullptr,
NUWA_PREPARATION_TIME,
nsITimer::TYPE_ONE_SHOT);
}
#endif
// Run the UI event loop on the main thread.
uiMessageLoop.MessageLoop::Run();

View File

@ -57,6 +57,10 @@
#include "libui/InputDispatcher.h"
#include "cutils/properties.h"
#ifdef MOZ_NUWA_PROCESS
#include "ipc/Nuwa.h"
#endif
#include "GeckoProfiler.h"
// Defines kKeyMapping and GetKeyNameIndex()
@ -733,6 +737,11 @@ nsAppShell::Init()
obsServ->AddObserver(this, "browser-ui-startup-complete", false);
}
#ifdef MOZ_NUWA_PROCESS
// Make sure main thread was woken up after Nuwa fork.
NuwaAddConstructor((void (*)(void *))&NotifyEvent, nullptr);
#endif
// Delay initializing input devices until the screen has been
// initialized (and we know the resolution).
return rv;