| Index: content/common/child_process.cc
|
| ===================================================================
|
| --- content/common/child_process.cc (revision 86367)
|
| +++ content/common/child_process.cc (working copy)
|
| @@ -8,10 +8,12 @@
|
| #include <signal.h> // For SigUSR1Handler below.
|
| #endif
|
|
|
| +#include "base/lazy_instance.h"
|
| #include "base/message_loop.h"
|
| #include "base/process_util.h"
|
| #include "base/string_number_conversions.h"
|
| #include "base/threading/thread.h"
|
| +#include "base/threading/thread_local.h"
|
| #include "base/utf_string_conversions.h"
|
| #include "content/common/child_thread.h"
|
|
|
| @@ -19,20 +21,23 @@
|
| static void SigUSR1Handler(int signal) { }
|
| #endif
|
|
|
| -ChildProcess* ChildProcess::child_process_;
|
| +namespace {
|
| +static base::LazyInstance<base::ThreadLocalPointer<ChildProcess> > lazy_tls(
|
| + base::LINKER_INITIALIZED);
|
| +}
|
|
|
| ChildProcess::ChildProcess()
|
| : ref_count_(0),
|
| shutdown_event_(true, false),
|
| io_thread_("Chrome_ChildIOThread") {
|
| - DCHECK(!child_process_);
|
| - child_process_ = this;
|
| + DCHECK(!lazy_tls.Pointer()->Get());
|
| + lazy_tls.Pointer()->Set(this);
|
|
|
| io_thread_.StartWithOptions(base::Thread::Options(MessageLoop::TYPE_IO, 0));
|
| }
|
|
|
| ChildProcess::~ChildProcess() {
|
| - DCHECK(child_process_ == this);
|
| + DCHECK(lazy_tls.Pointer()->Get() == this);
|
|
|
| // Signal this event before destroying the child process. That way all
|
| // background threads can cleanup.
|
| @@ -40,13 +45,17 @@
|
| // notice shutdown before the render process begins waiting for them to exit.
|
| shutdown_event_.Signal();
|
|
|
| - // Kill the main thread object before nulling child_process_, since
|
| + // Kill the main thread object before nulling lazy_tls, since
|
| // destruction code might depend on it.
|
| main_thread_.reset();
|
|
|
| - child_process_ = NULL;
|
| + lazy_tls.Pointer()->Set(NULL);
|
| }
|
|
|
| +ChildProcess* ChildProcess::current() {
|
| + return lazy_tls.Pointer()->Get();
|
| +}
|
| +
|
| ChildThread* ChildProcess::main_thread() {
|
| return main_thread_.get();
|
| }
|
| @@ -65,7 +74,6 @@
|
| DCHECK(!main_thread_.get() || // null in unittests.
|
| MessageLoop::current() == main_thread_->message_loop());
|
| DCHECK(ref_count_);
|
| - DCHECK(child_process_);
|
| if (--ref_count_)
|
| return;
|
|
|
| @@ -74,8 +82,7 @@
|
| }
|
|
|
| base::WaitableEvent* ChildProcess::GetShutDownEvent() {
|
| - DCHECK(child_process_);
|
| - return &child_process_->shutdown_event_;
|
| + return &lazy_tls.Pointer()->Get()->shutdown_event_;
|
| }
|
|
|
| void ChildProcess::WaitForDebugger(const std::string& label) {
|
|
|