diff options
author | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-17 03:27:53 +0000 |
---|---|---|
committer | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-17 03:27:53 +0000 |
commit | caaf3ccabb7c80184ad37c92db43ff79580e067d (patch) | |
tree | 5ca32588f181a709fa2e18494eb58ebf9a40f3ac /base/threading | |
parent | 72974cf561e13dd23fd9a3a83a702b545b5b390a (diff) | |
download | chromium_src-caaf3ccabb7c80184ad37c92db43ff79580e067d.zip chromium_src-caaf3ccabb7c80184ad37c92db43ff79580e067d.tar.gz chromium_src-caaf3ccabb7c80184ad37c92db43ff79580e067d.tar.bz2 |
Relax check for message loop in SequencedWorkerPool
Assert that the constructor message loop is non-NULL only when
the SequencedWorkerPool is about to be destroyed.
Revert now-unneccessary test changes that adds MessagePools for
SequenedWorkerPool.
BUG=117940
TEST=
Review URL: http://codereview.chromium.org/9699115
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@127335 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/threading')
-rw-r--r-- | base/threading/sequenced_worker_pool.cc | 15 | ||||
-rw-r--r-- | base/threading/sequenced_worker_pool.h | 6 |
2 files changed, 12 insertions, 9 deletions
diff --git a/base/threading/sequenced_worker_pool.cc b/base/threading/sequenced_worker_pool.cc index d517d21..d994d97 100644 --- a/base/threading/sequenced_worker_pool.cc +++ b/base/threading/sequenced_worker_pool.cc @@ -692,7 +692,6 @@ SequencedWorkerPool::SequencedWorkerPool( : constructor_message_loop_(MessageLoopProxy::current()), inner_(new Inner(ALLOW_THIS_IN_INITIALIZER_LIST(this), max_threads, thread_name_prefix, NULL)) { - DCHECK(constructor_message_loop_.get()); } SequencedWorkerPool::SequencedWorkerPool( @@ -702,19 +701,19 @@ SequencedWorkerPool::SequencedWorkerPool( : constructor_message_loop_(MessageLoopProxy::current()), inner_(new Inner(ALLOW_THIS_IN_INITIALIZER_LIST(this), max_threads, thread_name_prefix, observer)) { - DCHECK(constructor_message_loop_.get()); } SequencedWorkerPool::~SequencedWorkerPool() {} void SequencedWorkerPool::OnDestruct() const { - // TODO(akalin): Once we can easily check if we're on a worker - // thread or not, use that instead of restricting destruction to - // only the constructor message loop. - if (constructor_message_loop_->BelongsToCurrentThread()) - delete this; - else + DCHECK(constructor_message_loop_.get()); + // Avoid deleting ourselves on a worker thread (which would + // deadlock). + if (RunsTasksOnCurrentThread()) { constructor_message_loop_->DeleteSoon(FROM_HERE, this); + } else { + delete this; + } } SequencedWorkerPool::SequenceToken SequencedWorkerPool::GetSequenceToken() { diff --git a/base/threading/sequenced_worker_pool.h b/base/threading/sequenced_worker_pool.h index ded2b0a..83d677a 100644 --- a/base/threading/sequenced_worker_pool.h +++ b/base/threading/sequenced_worker_pool.h @@ -127,8 +127,12 @@ class BASE_EXPORT SequencedWorkerPool : public TaskRunner { virtual void OnDestruct() = 0; }; + // When constructing a SequencedWorkerPool, there must be a + // MessageLoop on the current thread unless you plan to deliberately + // leak it. + // Pass the maximum number of threads (they will be lazily created as needed) - // and a prefix for the thread name to ad in debugging. + // and a prefix for the thread name to aid in debugging. SequencedWorkerPool(size_t max_threads, const std::string& thread_name_prefix); |