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

Unified Diff: base/threading/sequenced_worker_pool.cc

Issue 9558007: Ensure that SequencedWorkerPools in tests don't outlive their tests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix test failures 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
« no previous file with comments | « base/threading/sequenced_worker_pool.h ('k') | base/threading/sequenced_worker_pool_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/threading/sequenced_worker_pool.cc
diff --git a/base/threading/sequenced_worker_pool.cc b/base/threading/sequenced_worker_pool.cc
index 85bdbeafc8ad6eac335502b5e1c237ccc276e668..b206ae00f1108cea001fa0f5f238aafe7f5042c5 100644
--- a/base/threading/sequenced_worker_pool.cc
+++ b/base/threading/sequenced_worker_pool.cc
@@ -14,6 +14,7 @@
#include "base/compiler_specific.h"
#include "base/logging.h"
#include "base/memory/linked_ptr.h"
+#include "base/message_loop_proxy.h"
#include "base/metrics/histogram.h"
#include "base/stringprintf.h"
#include "base/synchronization/condition_variable.h"
@@ -258,6 +259,9 @@ SequencedWorkerPool::Inner::~Inner() {
for (size_t i = 0; i < threads_.size(); i++)
threads_[i]->Join();
threads_.clear();
+
+ if (testing_observer_)
+ testing_observer_->OnDestruct();
}
SequencedWorkerPool::SequenceToken
@@ -635,11 +639,27 @@ bool SequencedWorkerPool::Inner::CanShutdown() const {
SequencedWorkerPool::SequencedWorkerPool(
size_t max_threads,
const std::string& thread_name_prefix)
- : inner_(new Inner(ALLOW_THIS_IN_INITIALIZER_LIST(this),
- max_threads, thread_name_prefix)) {}
+ : constructor_message_loop_(MessageLoopProxy::current()),
+ inner_(new Inner(ALLOW_THIS_IN_INITIALIZER_LIST(this),
+ max_threads, thread_name_prefix)) {
+ 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()) {
+ LOG(INFO) << "Deleting on this thread";
+ delete this;
+ } else {
+ LOG(INFO) << "Deleting soon";
+ constructor_message_loop_->DeleteSoon(FROM_HERE, this);
+ }
+}
+
SequencedWorkerPool::SequenceToken SequencedWorkerPool::GetSequenceToken() {
return inner_->GetSequenceToken();
}
« no previous file with comments | « base/threading/sequenced_worker_pool.h ('k') | base/threading/sequenced_worker_pool_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698