diff options
author | alexeypa@google.com <alexeypa@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-22 20:06:56 +0000 |
---|---|---|
committer | alexeypa@google.com <alexeypa@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-22 20:06:56 +0000 |
commit | c9904b429860b83606492d4fe8f1b232c04753b5 (patch) | |
tree | 4540d02ffe16677475ae55d0b19bc2d339b961d4 /base/message_loop/message_loop_proxy_impl.cc | |
parent | 7552e6b65ac0a972036bef093ed48b5c85827f44 (diff) | |
download | chromium_src-c9904b429860b83606492d4fe8f1b232c04753b5.zip chromium_src-c9904b429860b83606492d4fe8f1b232c04753b5.tar.gz chromium_src-c9904b429860b83606492d4fe8f1b232c04753b5.tar.bz2 |
Revert 212948 "Made MessagePump a non-thread safe class."
r212948 broke Mac Builder: http://build.chromium.org/p/chromium.memory/builders/Mac%20ASAN%20Builder/builds/25623
> Made MessagePump a non-thread safe class.
>
> This CL makes MessagePump a non-thread safe class to make sure thread-bound resources (such as the UI window used for pumping messages on Windows) are freed on the correct thread.
>
> Handling of incoming tasks and synchronization between different threads was moved out to a separate class - IncomingTaskQueue reducing the number of locks to be taken while posting a task to one. Posting tasks via both MessageLoop and MessageLoopProxyImpl is now routed via IncomingTaskQueue.
>
> BUG=241939
>
> Review URL: https://chromiumcodereview.appspot.com/17567007
TBR=alexeypa@chromium.org
Review URL: https://codereview.chromium.org/19737005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@212952 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/message_loop/message_loop_proxy_impl.cc')
-rw-r--r-- | base/message_loop/message_loop_proxy_impl.cc | 68 |
1 files changed, 53 insertions, 15 deletions
diff --git a/base/message_loop/message_loop_proxy_impl.cc b/base/message_loop/message_loop_proxy_impl.cc index b7abca3..7dc8caa 100644 --- a/base/message_loop/message_loop_proxy_impl.cc +++ b/base/message_loop/message_loop_proxy_impl.cc @@ -5,43 +5,81 @@ #include "base/message_loop/message_loop_proxy_impl.h" #include "base/location.h" -#include "base/logging.h" -#include "base/message_loop/incoming_task_queue.h" -#include "base/message_loop/message_loop.h" +#include "base/threading/thread_restrictions.h" namespace base { -namespace internal { -MessageLoopProxyImpl::MessageLoopProxyImpl( - scoped_refptr<IncomingTaskQueue> incoming_queue) - : incoming_queue_(incoming_queue), - valid_thread_id_(PlatformThread::CurrentId()) { +MessageLoopProxyImpl::~MessageLoopProxyImpl() { } bool MessageLoopProxyImpl::PostDelayedTask( const tracked_objects::Location& from_here, const base::Closure& task, base::TimeDelta delay) { - DCHECK(!task.is_null()) << from_here.ToString(); - return incoming_queue_->AddToIncomingQueue(from_here, task, delay, true); + return PostTaskHelper(from_here, task, delay, true); } bool MessageLoopProxyImpl::PostNonNestableDelayedTask( const tracked_objects::Location& from_here, const base::Closure& task, base::TimeDelta delay) { - DCHECK(!task.is_null()) << from_here.ToString(); - return incoming_queue_->AddToIncomingQueue(from_here, task, delay, false); + return PostTaskHelper(from_here, task, delay, false); } bool MessageLoopProxyImpl::RunsTasksOnCurrentThread() const { - return valid_thread_id_ == PlatformThread::CurrentId(); + // We shouldn't use MessageLoop::current() since it uses LazyInstance which + // may be deleted by ~AtExitManager when a WorkerPool thread calls this + // function. + // http://crbug.com/63678 + base::ThreadRestrictions::ScopedAllowSingleton allow_singleton; + AutoLock lock(message_loop_lock_); + return (target_message_loop_ && + (MessageLoop::current() == target_message_loop_)); } -MessageLoopProxyImpl::~MessageLoopProxyImpl() { +// MessageLoop::DestructionObserver implementation +void MessageLoopProxyImpl::WillDestroyCurrentMessageLoop() { + AutoLock lock(message_loop_lock_); + target_message_loop_ = NULL; +} + +void MessageLoopProxyImpl::OnDestruct() const { + // We shouldn't use MessageLoop::current() since it uses LazyInstance which + // may be deleted by ~AtExitManager when a WorkerPool thread calls this + // function. + // http://crbug.com/63678 + base::ThreadRestrictions::ScopedAllowSingleton allow_singleton; + bool delete_later = false; + { + AutoLock lock(message_loop_lock_); + if (target_message_loop_ && + (MessageLoop::current() != target_message_loop_)) { + target_message_loop_->DeleteSoon(FROM_HERE, this); + delete_later = true; + } + } + if (!delete_later) + delete this; } -} // namespace internal +MessageLoopProxyImpl::MessageLoopProxyImpl() + : target_message_loop_(MessageLoop::current()) { +} + +bool MessageLoopProxyImpl::PostTaskHelper( + const tracked_objects::Location& from_here, const base::Closure& task, + base::TimeDelta delay, bool nestable) { + AutoLock lock(message_loop_lock_); + if (target_message_loop_) { + if (nestable) { + target_message_loop_->PostDelayedTask(from_here, task, delay); + } else { + target_message_loop_->PostNonNestableDelayedTask(from_here, task, delay); + } + return true; + } + return false; +} scoped_refptr<MessageLoopProxy> MessageLoopProxy::current() { |