Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(172)

Unified Diff: base/threading/sequenced_worker_pool.cc

Issue 9699115: Relax check for message loop in SequencedWorkerPool (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/threading/sequenced_worker_pool.cc
diff --git a/base/threading/sequenced_worker_pool.cc b/base/threading/sequenced_worker_pool.cc
index d517d21e89eeec994c5f9e9063b38619c26ccc8d..d994d977d308c6e57ea55a60520204ef4b022852 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() {

Powered by Google App Engine
This is Rietveld 408576698