summaryrefslogtreecommitdiffstats
path: root/base/threading
diff options
context:
space:
mode:
Diffstat (limited to 'base/threading')
-rw-r--r--base/threading/sequenced_worker_pool.cc15
-rw-r--r--base/threading/sequenced_worker_pool.h6
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);