Commit 0895c057 authored by Alex Clarke's avatar Alex Clarke Committed by Commit Bot

Remove SequenceManager from base::Thread

We are no longer considering having anything other than a FIFO
scheduler on the IO thread (which is why it was added in the
first place).

Split off from https://crrev.com/c/1320329.

TBR=gab@chromium.org

Bug: 863341, 891670
Change-Id: I6e7c4fdd2772ec85dfffcf4bad051b0785b0a050
Reviewed-on: https://chromium-review.googlesource.com/c/1335930
Commit-Queue: Alex Clarke <alexclarke@chromium.org>
Reviewed-by: default avatarGabriel Charette <gab@chromium.org>
Reviewed-by: default avatarAlex Clarke <alexclarke@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608008}
parent b3c1d9dd
...@@ -3398,71 +3398,6 @@ TEST_P(SequenceManagerTest, DestructorPostChainDuringShutdown) { ...@@ -3398,71 +3398,6 @@ TEST_P(SequenceManagerTest, DestructorPostChainDuringShutdown) {
EXPECT_TRUE(run); EXPECT_TRUE(run);
} }
class ThreadForOffThreadInitializationTest : public Thread {
public:
ThreadForOffThreadInitializationTest()
: base::Thread("ThreadForOffThreadInitializationTest") {}
void SequenceManagerCreated(
base::sequence_manager::SequenceManager* sequence_manager) {
// This executes on the creating thread.
DCHECK_CALLED_ON_VALID_SEQUENCE(creating_sequence_checker_);
queue_ = sequence_manager->CreateTaskQueue<TestTaskQueue>(
TaskQueue::Spec("default"));
// TaskQueue should not run tasks on the creating thread.
EXPECT_FALSE(queue_->RunsTasksInCurrentSequence());
// Override the default task runner before the thread is started.
sequence_manager->SetDefaultTaskRunner(queue_->task_runner());
EXPECT_EQ(queue_->task_runner(), message_loop()->task_runner());
// Post a task to the queue.
message_loop()->task_runner()->PostTask(
FROM_HERE,
Bind([](bool* did_run_task) { *did_run_task = true; }, &did_run_task_));
}
private:
void Init() override {
// Queue should already be bound to this thread.
EXPECT_TRUE(queue_->RunsTasksInCurrentSequence());
EXPECT_EQ(queue_->task_runner(), ThreadTaskRunnerHandle::Get());
}
void Run(base::RunLoop* run_loop) override {
// Run the posted task.
Thread::Run(run_loop);
EXPECT_TRUE(did_run_task_);
// The |queue_| should be destructed on the creating thread.
queue_ = nullptr;
}
scoped_refptr<SingleThreadTaskRunner> original_task_runner_;
scoped_refptr<TestTaskQueue> queue_;
bool did_run_task_ = false;
SEQUENCE_CHECKER(creating_sequence_checker_);
};
// Verifies the integration of off-thread SequenceManager and MessageLoop
// initialization when starting a base::Thread.
TEST_P(SequenceManagerTestWithCustomInitialization, OffThreadInitialization) {
ThreadForOffThreadInitializationTest thread;
base::Thread::Options options;
options.message_loop_type = base::MessageLoop::TYPE_DEFAULT;
options.on_sequence_manager_created = base::BindRepeating(
&ThreadForOffThreadInitializationTest::SequenceManagerCreated,
base::Unretained(&thread));
ASSERT_TRUE(thread.StartWithOptions(options));
// Waits for the thread to complete execution.
thread.Stop();
}
TEST_P(SequenceManagerTestWithCustomInitialization, TEST_P(SequenceManagerTestWithCustomInitialization,
SequenceManagerCreatedBeforeMessageLoop) { SequenceManagerCreatedBeforeMessageLoop) {
std::unique_ptr<SequenceManager> manager = std::unique_ptr<SequenceManager> manager =
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/synchronization/waitable_event.h" #include "base/synchronization/waitable_event.h"
#include "base/task/sequence_manager/sequence_manager.h"
#include "base/third_party/dynamic_annotations/dynamic_annotations.h" #include "base/third_party/dynamic_annotations/dynamic_annotations.h"
#include "base/threading/thread_id_name_manager.h" #include "base/threading/thread_id_name_manager.h"
#include "base/threading/thread_local.h" #include "base/threading/thread_local.h"
...@@ -103,12 +102,6 @@ bool Thread::StartWithOptions(const Options& options) { ...@@ -103,12 +102,6 @@ bool Thread::StartWithOptions(const Options& options) {
message_loop_ = message_loop_owned.get(); message_loop_ = message_loop_owned.get();
start_event_.Reset(); start_event_.Reset();
if (options.on_sequence_manager_created) {
sequence_manager_ =
sequence_manager::CreateUnboundSequenceManager(message_loop_);
options.on_sequence_manager_created.Run(sequence_manager_.get());
}
// Hold |thread_lock_| while starting the new thread to synchronize with // Hold |thread_lock_| while starting the new thread to synchronize with
// Stop() while it's not guaranteed to be sequenced (until crbug/629139 is // Stop() while it's not guaranteed to be sequenced (until crbug/629139 is
// fixed). // fixed).
...@@ -300,26 +293,12 @@ void Thread::ThreadMain() { ...@@ -300,26 +293,12 @@ void Thread::ThreadMain() {
PlatformThread::SetName(name_.c_str()); PlatformThread::SetName(name_.c_str());
ANNOTATE_THREAD_NAME(name_.c_str()); // Tell the name to race detector. ANNOTATE_THREAD_NAME(name_.c_str()); // Tell the name to race detector.
if (sequence_manager_) {
// Bind the SequenceManager before binding the MessageLoop, so that the
// TaskQueues are bound before the MessageLoop. This is required as one of
// the TaskQueues may have already replaced the MessageLoop's TaskRunner,
// and the MessageLoop's TaskRunner needs to be associated with this thread
// when we call MessageLoop::BindToCurrentThread().
sequence_manager_->BindToCurrentThread();
}
// Lazily initialize the |message_loop| so that it can run on this thread. // Lazily initialize the |message_loop| so that it can run on this thread.
DCHECK(message_loop_); DCHECK(message_loop_);
std::unique_ptr<MessageLoop> message_loop(message_loop_); std::unique_ptr<MessageLoop> message_loop(message_loop_);
message_loop_->BindToCurrentThread(); message_loop_->BindToCurrentThread();
message_loop_->SetTimerSlack(timer_slack_); message_loop_->SetTimerSlack(timer_slack_);
if (sequence_manager_) {
sequence_manager_->SetTimerSlack(timer_slack_);
sequence_manager_->CompleteInitializationOnBoundThread();
}
#if defined(OS_POSIX) && !defined(OS_NACL) #if defined(OS_POSIX) && !defined(OS_NACL)
// Allow threads running a MessageLoopForIO to use FileDescriptorWatcher API. // Allow threads running a MessageLoopForIO to use FileDescriptorWatcher API.
std::unique_ptr<FileDescriptorWatcher> file_descriptor_watcher; std::unique_ptr<FileDescriptorWatcher> file_descriptor_watcher;
...@@ -364,8 +343,6 @@ void Thread::ThreadMain() { ...@@ -364,8 +343,6 @@ void Thread::ThreadMain() {
com_initializer.reset(); com_initializer.reset();
#endif #endif
sequence_manager_.reset();
if (message_loop->type() != MessageLoop::TYPE_CUSTOM) { if (message_loop->type() != MessageLoop::TYPE_CUSTOM) {
// Assert that RunLoop::QuitWhenIdle was called by ThreadQuitHelper. Don't // Assert that RunLoop::QuitWhenIdle was called by ThreadQuitHelper. Don't
// check for custom message pumps, because their shutdown might not allow // check for custom message pumps, because their shutdown might not allow
......
...@@ -29,10 +29,6 @@ namespace base { ...@@ -29,10 +29,6 @@ namespace base {
class MessagePump; class MessagePump;
class RunLoop; class RunLoop;
namespace sequence_manager {
class SequenceManager;
} // namespace sequence_manager
// IMPORTANT: Instead of creating a base::Thread, consider using // IMPORTANT: Instead of creating a base::Thread, consider using
// base::Create(Sequenced|SingleThread)TaskRunnerWithTraits(). // base::Create(Sequenced|SingleThread)TaskRunnerWithTraits().
// //
...@@ -65,8 +61,6 @@ class BASE_EXPORT Thread : PlatformThread::Delegate { ...@@ -65,8 +61,6 @@ class BASE_EXPORT Thread : PlatformThread::Delegate {
public: public:
struct BASE_EXPORT Options { struct BASE_EXPORT Options {
typedef Callback<std::unique_ptr<MessagePump>()> MessagePumpFactory; typedef Callback<std::unique_ptr<MessagePump>()> MessagePumpFactory;
using SequenceManagerCreatedCallback =
RepeatingCallback<void(sequence_manager::SequenceManager*)>;
Options(); Options();
Options(MessageLoop::Type type, size_t size); Options(MessageLoop::Type type, size_t size);
...@@ -86,12 +80,6 @@ class BASE_EXPORT Thread : PlatformThread::Delegate { ...@@ -86,12 +80,6 @@ class BASE_EXPORT Thread : PlatformThread::Delegate {
// MessageLoop::Type to TYPE_CUSTOM. // MessageLoop::Type to TYPE_CUSTOM.
MessagePumpFactory message_pump_factory; MessagePumpFactory message_pump_factory;
// If set, the Thread will create a SequenceManager on the MessageLoop and
// execute the provided callback right after it was created. The callback
// will be executed on the creator thread before the new Thread is started.
// It is typically used to create TaskQueues for the SequenceManager.
SequenceManagerCreatedCallback on_sequence_manager_created;
// Specifies the maximum stack size that the thread is allowed to use. // Specifies the maximum stack size that the thread is allowed to use.
// This does not necessarily correspond to the thread's initial stack size. // This does not necessarily correspond to the thread's initial stack size.
// A value of 0 indicates that the default maximum should be used. // A value of 0 indicates that the default maximum should be used.
...@@ -341,9 +329,6 @@ class BASE_EXPORT Thread : PlatformThread::Delegate { ...@@ -341,9 +329,6 @@ class BASE_EXPORT Thread : PlatformThread::Delegate {
// cleanup logic as required. // cleanup logic as required.
bool using_external_message_loop_ = false; bool using_external_message_loop_ = false;
// Optionally stores a SequenceManager that manages Tasks on the MessageLoop.
std::unique_ptr<sequence_manager::SequenceManager> sequence_manager_;
// Stores Options::timer_slack_ until the sequence manager has been bound to // Stores Options::timer_slack_ until the sequence manager has been bound to
// a thread. // a thread.
TimerSlack timer_slack_ = TIMER_SLACK_NONE; TimerSlack timer_slack_ = TIMER_SLACK_NONE;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment