diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-15 18:30:30 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-15 18:30:30 +0000 |
commit | 94f9a0f686619656ca4ff2b6511179dc2132cc5d (patch) | |
tree | 26051806295528d68b4e5e65a0f39eaac18f7a24 /chrome/worker | |
parent | 1b5d23dfa22d8858dc9ab35d373fcf328aadbcba (diff) | |
download | chromium_src-94f9a0f686619656ca4ff2b6511179dc2132cc5d.zip chromium_src-94f9a0f686619656ca4ff2b6511179dc2132cc5d.tar.gz chromium_src-94f9a0f686619656ca4ff2b6511179dc2132cc5d.tar.bz2 |
Switch child threads so that current() only works on the correct thread and the correct process.
Review URL: http://codereview.chromium.org/126086
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18409 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/worker')
-rw-r--r-- | chrome/worker/worker_thread.cc | 12 | ||||
-rw-r--r-- | chrome/worker/worker_thread.h | 4 |
2 files changed, 13 insertions, 3 deletions
diff --git a/chrome/worker/worker_thread.cc b/chrome/worker/worker_thread.cc index 8f3aebf..a6db89d 100644 --- a/chrome/worker/worker_thread.cc +++ b/chrome/worker/worker_thread.cc @@ -4,11 +4,17 @@ #include "chrome/worker/worker_thread.h" +#include "base/lazy_instance.h" +#include "base/thread_local.h" #include "chrome/common/worker_messages.h" #include "chrome/worker/webworkerclient_proxy.h" #include "chrome/worker/worker_webkitclient_impl.h" #include "webkit/api/public/WebKit.h" +static base::LazyInstance<base::ThreadLocalPointer<WorkerThread> > lazy_tls( + base::LINKER_INITIALIZED); + + WorkerThread::WorkerThread() : ChildThread(base::Thread::Options(MessageLoop::TYPE_DEFAULT, kV8StackSize)) { @@ -17,7 +23,12 @@ WorkerThread::WorkerThread() WorkerThread::~WorkerThread() { } +WorkerThread* WorkerThread::current() { + return lazy_tls.Pointer()->Get(); +} + void WorkerThread::Init() { + lazy_tls.Pointer()->Set(this); ChildThread::Init(); webkit_client_.reset(new WorkerWebKitClientImpl); WebKit::initialize(webkit_client_.get()); @@ -35,6 +46,7 @@ void WorkerThread::CleanUp() { } ChildThread::CleanUp(); + lazy_tls.Pointer()->Set(NULL); } void WorkerThread::OnControlMessageReceived(const IPC::Message& msg) { diff --git a/chrome/worker/worker_thread.h b/chrome/worker/worker_thread.h index c7f9a09..6bea33c 100644 --- a/chrome/worker/worker_thread.h +++ b/chrome/worker/worker_thread.h @@ -17,9 +17,7 @@ class WorkerThread : public ChildThread { ~WorkerThread(); // Returns the one worker thread. - static WorkerThread* current() { - return static_cast<WorkerThread*>(ChildThread::current()); - } + static WorkerThread* current(); private: virtual void OnControlMessageReceived(const IPC::Message& msg); |