diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-02 22:38:31 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-02 22:38:31 +0000 |
commit | 90a253bf27e88f424afde35b561270fe52163763 (patch) | |
tree | 01f15e8333af8d564aab3de2231d4476ff801347 /content | |
parent | d2b1b7e5fcd3e73d5a5ae927c3c6a2eda70a4673 (diff) | |
download | chromium_src-90a253bf27e88f424afde35b561270fe52163763.zip chromium_src-90a253bf27e88f424afde35b561270fe52163763.tar.gz chromium_src-90a253bf27e88f424afde35b561270fe52163763.tar.bz2 |
Allow multiple ChildProcess objects in one process for the --single-process case, when we have both renderer and gpu.
Review URL: http://codereview.chromium.org/6966030
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@87712 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r-- | content/common/child_process.cc | 25 | ||||
-rw-r--r-- | content/common/child_process.h | 5 |
2 files changed, 17 insertions, 13 deletions
diff --git a/content/common/child_process.cc b/content/common/child_process.cc index 5e5d5fa..3a31a96 100644 --- a/content/common/child_process.cc +++ b/content/common/child_process.cc @@ -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,11 +45,15 @@ ChildProcess::~ChildProcess() { // 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() { @@ -65,7 +74,6 @@ void ChildProcess::ReleaseProcess() { 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 @@ void ChildProcess::ReleaseProcess() { } 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) { diff --git a/content/common/child_process.h b/content/common/child_process.h index e3786ae..f37d528 100644 --- a/content/common/child_process.h +++ b/content/common/child_process.h @@ -53,7 +53,7 @@ class ChildProcess { void ReleaseProcess(); // Getter for the one ChildProcess object for this process. - static ChildProcess* current() { return child_process_; } + static ChildProcess* current(); static void WaitForDebugger(const std::string& label); private: @@ -70,9 +70,6 @@ class ChildProcess { // io_thread_. scoped_ptr<ChildThread> main_thread_; - // The singleton instance for this process. - static ChildProcess* child_process_; - DISALLOW_COPY_AND_ASSIGN(ChildProcess); }; |