summaryrefslogtreecommitdiffstats
path: root/base/threading
diff options
context:
space:
mode:
authorstevenjb <stevenjb@chromium.org>2015-04-29 14:43:03 -0700
committerCommit bot <commit-bot@chromium.org>2015-04-29 21:44:18 +0000
commit7669182866d8605d98a5141f7b82be3b516799ca (patch)
treeab4b166fa5b19181751469bfff84be8c0f00aaad /base/threading
parentfd2d6d70942f4a64845022066098622809c189e9 (diff)
downloadchromium_src-7669182866d8605d98a5141f7b82be3b516799ca.zip
chromium_src-7669182866d8605d98a5141f7b82be3b516799ca.tar.gz
chromium_src-7669182866d8605d98a5141f7b82be3b516799ca.tar.bz2
Revert of base: Remove use of MessageLoopProxy (patchset #6 id:100001 of https://codereview.chromium.org/1100773004/)
Reason for revert: This CL caused this failure: http://build.chromium.org/p/chromium.chromiumos/builders/Linux%20ChromiumOS%20Tests%20%281%29/builds/2126 I would strongly recommend doing this in smaller pieces since it combines mechanical changes with more subtle ones (base/prefs, base/task). Original issue's description: > base: Remove use of MessageLoopProxy > > Replace usage of MessageLoopProxy under base/ with SingleThreadTaskRunner > and ThreadTaskRunnerHandle (excluding the implementation of MessageLoopProxy > itself which will removed later). > > This patch was mostly autogenerated with > https://codereview.chromium.org/1010073002. > > Depends on https://codereview.chromium.org/1086733002/. > > BUG=465354 > TBR=nkostylev@chromium.org,pkasting@chromium.org,pauljensen@chromium.org > > Committed: https://crrev.com/62aa5ca413e15738ebebbb9acd271138ec808739 > Cr-Commit-Position: refs/heads/master@{#327512} TBR=danakj@chromium.org,skyostil@chromium.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=465354 Review URL: https://codereview.chromium.org/1113953002 Cr-Commit-Position: refs/heads/master@{#327573}
Diffstat (limited to 'base/threading')
-rw-r--r--base/threading/post_task_and_reply_impl.cc18
-rw-r--r--base/threading/post_task_and_reply_impl.h6
-rw-r--r--base/threading/sequenced_worker_pool.cc24
-rw-r--r--base/threading/sequenced_worker_pool.h6
-rw-r--r--base/threading/sequenced_worker_pool_unittest.cc1
-rw-r--r--base/threading/thread.cc3
-rw-r--r--base/threading/thread.h4
-rw-r--r--base/threading/thread_perftest.cc26
-rw-r--r--base/threading/thread_unittest.cc21
-rw-r--r--base/threading/worker_pool.h2
10 files changed, 58 insertions, 53 deletions
diff --git a/base/threading/post_task_and_reply_impl.cc b/base/threading/post_task_and_reply_impl.cc
index f3e88ab..a82a4fd 100644
--- a/base/threading/post_task_and_reply_impl.cc
+++ b/base/threading/post_task_and_reply_impl.cc
@@ -25,30 +25,30 @@ namespace {
class PostTaskAndReplyRelay {
public:
PostTaskAndReplyRelay(const tracked_objects::Location& from_here,
- const Closure& task,
- const Closure& reply)
+ const Closure& task, const Closure& reply)
: from_here_(from_here),
- origin_task_runner_(ThreadTaskRunnerHandle::Get()) {
+ origin_loop_(ThreadTaskRunnerHandle::Get()) {
task_ = task;
reply_ = reply;
}
~PostTaskAndReplyRelay() {
- DCHECK(origin_task_runner_->BelongsToCurrentThread());
+ DCHECK(origin_loop_->BelongsToCurrentThread());
task_.Reset();
reply_.Reset();
}
void Run() {
task_.Run();
- origin_task_runner_->PostTask(
- from_here_, Bind(&PostTaskAndReplyRelay::RunReplyAndSelfDestruct,
- base::Unretained(this)));
+ origin_loop_->PostTask(
+ from_here_,
+ Bind(&PostTaskAndReplyRelay::RunReplyAndSelfDestruct,
+ base::Unretained(this)));
}
private:
void RunReplyAndSelfDestruct() {
- DCHECK(origin_task_runner_->BelongsToCurrentThread());
+ DCHECK(origin_loop_->BelongsToCurrentThread());
// Force |task_| to be released before |reply_| is to ensure that no one
// accidentally depends on |task_| keeping one of its arguments alive while
@@ -62,7 +62,7 @@ class PostTaskAndReplyRelay {
}
tracked_objects::Location from_here_;
- scoped_refptr<SingleThreadTaskRunner> origin_task_runner_;
+ scoped_refptr<SingleThreadTaskRunner> origin_loop_;
Closure reply_;
Closure task_;
};
diff --git a/base/threading/post_task_and_reply_impl.h b/base/threading/post_task_and_reply_impl.h
index a5b9580..076a46d 100644
--- a/base/threading/post_task_and_reply_impl.h
+++ b/base/threading/post_task_and_reply_impl.h
@@ -3,7 +3,7 @@
// found in the LICENSE file.
// This file contains the implementation shared by
-// TaskRunner::PostTaskAndReply and WorkerPool::PostTaskAndReply.
+// MessageLoopProxy::PostTaskAndReply and WorkerPool::PostTaskAndReply.
#ifndef BASE_THREADING_POST_TASK_AND_REPLY_IMPL_H_
#define BASE_THREADING_POST_TASK_AND_REPLY_IMPL_H_
@@ -21,11 +21,11 @@ namespace internal {
// MessageLoop.
//
// If you're looking for a concrete implementation of
-// PostTaskAndReply, you probably want base::SingleThreadTaskRunner, or you
+// PostTaskAndReply, you probably want base::MessageLoopProxy, or you
// may want base::WorkerPool.
class PostTaskAndReplyImpl {
public:
- // Implementation for TaskRunner::PostTaskAndReply and
+ // Implementation for MessageLoopProxy::PostTaskAndReply and
// WorkerPool::PostTaskAndReply.
bool PostTaskAndReply(const tracked_objects::Location& from_here,
const Closure& task,
diff --git a/base/threading/sequenced_worker_pool.cc b/base/threading/sequenced_worker_pool.cc
index 459c31b..6f4a248 100644
--- a/base/threading/sequenced_worker_pool.cc
+++ b/base/threading/sequenced_worker_pool.cc
@@ -17,11 +17,11 @@
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/memory/linked_ptr.h"
+#include "base/message_loop/message_loop_proxy.h"
#include "base/stl_util.h"
#include "base/strings/stringprintf.h"
#include "base/synchronization/condition_variable.h"
#include "base/synchronization/lock.h"
-#include "base/thread_task_runner_handle.h"
#include "base/threading/platform_thread.h"
#include "base/threading/simple_thread.h"
#include "base/threading/thread_local.h"
@@ -1158,27 +1158,29 @@ SequencedWorkerPool::GetSequenceTokenForCurrentThread() {
return *token;
}
-SequencedWorkerPool::SequencedWorkerPool(size_t max_threads,
- const std::string& thread_name_prefix)
- : constructor_task_runner_(ThreadTaskRunnerHandle::Get()),
+SequencedWorkerPool::SequencedWorkerPool(
+ size_t max_threads,
+ const std::string& thread_name_prefix)
+ : constructor_message_loop_(MessageLoopProxy::current()),
inner_(new Inner(this, max_threads, thread_name_prefix, NULL)) {
}
-SequencedWorkerPool::SequencedWorkerPool(size_t max_threads,
- const std::string& thread_name_prefix,
- TestingObserver* observer)
- : constructor_task_runner_(ThreadTaskRunnerHandle::Get()),
+SequencedWorkerPool::SequencedWorkerPool(
+ size_t max_threads,
+ const std::string& thread_name_prefix,
+ TestingObserver* observer)
+ : constructor_message_loop_(MessageLoopProxy::current()),
inner_(new Inner(this, max_threads, thread_name_prefix, observer)) {
}
SequencedWorkerPool::~SequencedWorkerPool() {}
void SequencedWorkerPool::OnDestruct() const {
- DCHECK(constructor_task_runner_);
+ DCHECK(constructor_message_loop_.get());
// Avoid deleting ourselves on a worker thread (which would
// deadlock).
if (RunsTasksOnCurrentThread()) {
- constructor_task_runner_->DeleteSoon(FROM_HERE, this);
+ constructor_message_loop_->DeleteSoon(FROM_HERE, this);
} else {
delete this;
}
@@ -1298,7 +1300,7 @@ void SequencedWorkerPool::SignalHasWorkForTesting() {
}
void SequencedWorkerPool::Shutdown(int max_new_blocking_tasks_after_shutdown) {
- DCHECK(constructor_task_runner_->BelongsToCurrentThread());
+ DCHECK(constructor_message_loop_->BelongsToCurrentThread());
inner_->Shutdown(max_new_blocking_tasks_after_shutdown);
}
diff --git a/base/threading/sequenced_worker_pool.h b/base/threading/sequenced_worker_pool.h
index 2126b0d..0b6c5f9 100644
--- a/base/threading/sequenced_worker_pool.h
+++ b/base/threading/sequenced_worker_pool.h
@@ -11,10 +11,8 @@
#include "base/base_export.h"
#include "base/basictypes.h"
#include "base/callback_forward.h"
-#include "base/location.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
-#include "base/single_thread_task_runner.h"
#include "base/task_runner.h"
namespace tracked_objects {
@@ -23,7 +21,7 @@ class Location;
namespace base {
-class SingleThreadTaskRunner;
+class MessageLoopProxy;
template <class T> class DeleteHelper;
@@ -347,7 +345,7 @@ class BASE_EXPORT SequencedWorkerPool : public TaskRunner {
class Inner;
class Worker;
- const scoped_refptr<SingleThreadTaskRunner> constructor_task_runner_;
+ const scoped_refptr<MessageLoopProxy> constructor_message_loop_;
// Avoid pulling in too many headers by putting (almost) everything
// into |inner_|.
diff --git a/base/threading/sequenced_worker_pool_unittest.cc b/base/threading/sequenced_worker_pool_unittest.cc
index 05989a5..c12156e 100644
--- a/base/threading/sequenced_worker_pool_unittest.cc
+++ b/base/threading/sequenced_worker_pool_unittest.cc
@@ -11,6 +11,7 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
+#include "base/message_loop/message_loop_proxy.h"
#include "base/synchronization/condition_variable.h"
#include "base/synchronization/lock.h"
#include "base/test/sequenced_task_runner_test_template.h"
diff --git a/base/threading/thread.cc b/base/threading/thread.cc
index bab3991..d42ba4d 100644
--- a/base/threading/thread.cc
+++ b/base/threading/thread.cc
@@ -6,7 +6,6 @@
#include "base/bind.h"
#include "base/lazy_instance.h"
-#include "base/location.h"
#include "base/profiler/scoped_tracker.h"
#include "base/synchronization/waitable_event.h"
#include "base/third_party/dynamic_annotations/dynamic_annotations.h"
@@ -163,7 +162,7 @@ void Thread::StopSoon() {
return;
stopping_ = true;
- task_runner()->PostTask(FROM_HERE, base::Bind(&ThreadQuitHelper));
+ message_loop_->PostTask(FROM_HERE, base::Bind(&ThreadQuitHelper));
}
bool Thread::IsRunning() const {
diff --git a/base/threading/thread.h b/base/threading/thread.h
index 4915606..5010f0e 100644
--- a/base/threading/thread.h
+++ b/base/threading/thread.h
@@ -11,8 +11,8 @@
#include "base/callback.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
+#include "base/message_loop/message_loop_proxy.h"
#include "base/message_loop/timer_slack.h"
-#include "base/single_thread_task_runner.h"
#include "base/threading/platform_thread.h"
namespace base {
@@ -156,7 +156,7 @@ class BASE_EXPORT Thread : PlatformThread::Delegate {
// hold on to this even after the thread is gone; in this situation, attempts
// to PostTask() will fail.
scoped_refptr<SingleThreadTaskRunner> task_runner() const {
- return message_loop_->task_runner();
+ return message_loop_proxy();
}
// Returns the name of this thread (for display in debugger too).
diff --git a/base/threading/thread_perftest.cc b/base/threading/thread_perftest.cc
index 3bc9fb4..a08cc5b 100644
--- a/base/threading/thread_perftest.cc
+++ b/base/threading/thread_perftest.cc
@@ -5,9 +5,7 @@
#include "base/base_switches.h"
#include "base/bind.h"
#include "base/command_line.h"
-#include "base/location.h"
#include "base/memory/scoped_vector.h"
-#include "base/single_thread_task_runner.h"
#include "base/strings/stringprintf.h"
#include "base/synchronization/condition_variable.h"
#include "base/synchronization/lock.h"
@@ -56,9 +54,12 @@ class ThreadPerfTest : public testing::Test {
base::TimeTicks ThreadNow(base::Thread* thread) {
base::WaitableEvent done(false, false);
base::TimeTicks ticks;
- thread->task_runner()->PostTask(
- FROM_HERE, base::Bind(&ThreadPerfTest::TimeOnThread,
- base::Unretained(this), &ticks, &done));
+ thread->message_loop_proxy()->PostTask(
+ FROM_HERE,
+ base::Bind(&ThreadPerfTest::TimeOnThread,
+ base::Unretained(this),
+ &ticks,
+ &done));
done.Wait();
return ticks;
}
@@ -127,9 +128,10 @@ class TaskPerfTest : public ThreadPerfTest {
FinishMeasurement();
return;
}
- NextThread(hops)->task_runner()->PostTask(
- FROM_HERE, base::Bind(&ThreadPerfTest::PingPong, base::Unretained(this),
- hops - 1));
+ NextThread(hops)->message_loop_proxy()->PostTask(
+ FROM_HERE,
+ base::Bind(
+ &ThreadPerfTest::PingPong, base::Unretained(this), hops - 1));
}
};
@@ -196,9 +198,11 @@ class EventPerfTest : public ThreadPerfTest {
void PingPong(int hops) override {
remaining_hops_ = hops;
for (size_t i = 0; i < threads_.size(); i++) {
- threads_[i]->task_runner()->PostTask(
- FROM_HERE, base::Bind(&EventPerfTest::WaitAndSignalOnThread,
- base::Unretained(this), i));
+ threads_[i]->message_loop_proxy()->PostTask(
+ FROM_HERE,
+ base::Bind(&EventPerfTest::WaitAndSignalOnThread,
+ base::Unretained(this),
+ i));
}
// Kick off the Signal ping-ponging.
diff --git a/base/threading/thread_unittest.cc b/base/threading/thread_unittest.cc
index a89768e..f4d024f 100644
--- a/base/threading/thread_unittest.cc
+++ b/base/threading/thread_unittest.cc
@@ -7,8 +7,7 @@
#include <vector>
#include "base/bind.h"
-#include "base/location.h"
-#include "base/single_thread_task_runner.h"
+#include "base/message_loop/message_loop.h"
#include "base/third_party/dynamic_annotations/dynamic_annotations.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
@@ -145,7 +144,7 @@ TEST_F(ThreadTest, StartWithOptions_StackSize) {
EXPECT_TRUE(a.IsRunning());
bool was_invoked = false;
- a.task_runner()->PostTask(FROM_HERE, base::Bind(&ToggleValue, &was_invoked));
+ a.message_loop()->PostTask(FROM_HERE, base::Bind(&ToggleValue, &was_invoked));
// wait for the task to run (we could use a kernel event here
// instead to avoid busy waiting, but this is sufficient for
@@ -166,12 +165,14 @@ TEST_F(ThreadTest, TwoTasks) {
// Test that all events are dispatched before the Thread object is
// destroyed. We do this by dispatching a sleep event before the
// event that will toggle our sentinel value.
- a.task_runner()->PostTask(
- FROM_HERE, base::Bind(static_cast<void (*)(base::TimeDelta)>(
- &base::PlatformThread::Sleep),
- base::TimeDelta::FromMilliseconds(20)));
- a.task_runner()->PostTask(FROM_HERE,
- base::Bind(&ToggleValue, &was_invoked));
+ a.message_loop()->PostTask(
+ FROM_HERE,
+ base::Bind(
+ static_cast<void (*)(base::TimeDelta)>(
+ &base::PlatformThread::Sleep),
+ base::TimeDelta::FromMilliseconds(20)));
+ a.message_loop()->PostTask(FROM_HERE, base::Bind(&ToggleValue,
+ &was_invoked));
}
EXPECT_TRUE(was_invoked);
}
@@ -220,7 +221,7 @@ TEST_F(ThreadTest, CleanUp) {
// Register an observer that writes into |captured_events| once the
// thread's message loop is destroyed.
- t.task_runner()->PostTask(
+ t.message_loop()->PostTask(
FROM_HERE, base::Bind(&RegisterDestructionObserver,
base::Unretained(&loop_destruction_observer)));
diff --git a/base/threading/worker_pool.h b/base/threading/worker_pool.h
index a52a414..333b495 100644
--- a/base/threading/worker_pool.h
+++ b/base/threading/worker_pool.h
@@ -36,7 +36,7 @@ class BASE_EXPORT WorkerPool {
static bool PostTask(const tracked_objects::Location& from_here,
const base::Closure& task, bool task_is_slow);
- // Just like TaskRunner::PostTaskAndReply, except the destination
+ // Just like MessageLoopProxy::PostTaskAndReply, except the destination
// for |task| is a worker thread and you can specify |task_is_slow| just
// like you can for PostTask above.
static bool PostTaskAndReply(const tracked_objects::Location& from_here,