| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <utility> | 5 #include <utility> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 } | 47 } |
| 48 task_ready_.Signal(); | 48 task_ready_.Signal(); |
| 49 return true; | 49 return true; |
| 50 } | 50 } |
| 51 bool RunsTasksInCurrentSequence() const override { | 51 bool RunsTasksInCurrentSequence() const override { |
| 52 return base::PlatformThread::CurrentRef() == thread_id_; | 52 return base::PlatformThread::CurrentRef() == thread_id_; |
| 53 } | 53 } |
| 54 | 54 |
| 55 // Only quits when Quit() is called. | 55 // Only quits when Quit() is called. |
| 56 void Run() { | 56 void Run() { |
| 57 DCHECK(RunsTasksOnCurrentThread()); | 57 DCHECK(RunsTasksInCurrentSequence()); |
| 58 quit_called_ = false; | 58 quit_called_ = false; |
| 59 | 59 |
| 60 while (true) { | 60 while (true) { |
| 61 { | 61 { |
| 62 base::AutoLock locker(lock_); | 62 base::AutoLock locker(lock_); |
| 63 while (!tasks_.empty()) { | 63 while (!tasks_.empty()) { |
| 64 auto task = std::move(tasks_.front()); | 64 auto task = std::move(tasks_.front()); |
| 65 tasks_.pop(); | 65 tasks_.pop(); |
| 66 | 66 |
| 67 { | 67 { |
| 68 base::AutoUnlock unlocker(lock_); | 68 base::AutoUnlock unlocker(lock_); |
| 69 std::move(task).Run(); | 69 std::move(task).Run(); |
| 70 if (quit_called_) | 70 if (quit_called_) |
| 71 return; | 71 return; |
| 72 } | 72 } |
| 73 } | 73 } |
| 74 } | 74 } |
| 75 task_ready_.Wait(); | 75 task_ready_.Wait(); |
| 76 } | 76 } |
| 77 } | 77 } |
| 78 | 78 |
| 79 void Quit() { | 79 void Quit() { |
| 80 DCHECK(RunsTasksOnCurrentThread()); | 80 DCHECK(RunsTasksInCurrentSequence()); |
| 81 quit_called_ = true; | 81 quit_called_ = true; |
| 82 } | 82 } |
| 83 | 83 |
| 84 // Waits until one task is ready and runs it. | 84 // Waits until one task is ready and runs it. |
| 85 void RunOneTask() { | 85 void RunOneTask() { |
| 86 DCHECK(RunsTasksOnCurrentThread()); | 86 DCHECK(RunsTasksInCurrentSequence()); |
| 87 | 87 |
| 88 while (true) { | 88 while (true) { |
| 89 { | 89 { |
| 90 base::AutoLock locker(lock_); | 90 base::AutoLock locker(lock_); |
| 91 if (!tasks_.empty()) { | 91 if (!tasks_.empty()) { |
| 92 auto task = std::move(tasks_.front()); | 92 auto task = std::move(tasks_.front()); |
| 93 tasks_.pop(); | 93 tasks_.pop(); |
| 94 | 94 |
| 95 { | 95 { |
| 96 base::AutoUnlock unlocker(lock_); | 96 base::AutoUnlock unlocker(lock_); |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 EXPECT_TRUE(sender_impl_error); | 386 EXPECT_TRUE(sender_impl_error); |
| 387 connection_ptr_task_runner_->Run(); | 387 connection_ptr_task_runner_->Run(); |
| 388 EXPECT_TRUE(connection_ptr_error); | 388 EXPECT_TRUE(connection_ptr_error); |
| 389 sender_ptr_task_runner_->Run(); | 389 sender_ptr_task_runner_->Run(); |
| 390 EXPECT_TRUE(sender_ptr_error); | 390 EXPECT_TRUE(sender_ptr_error); |
| 391 } | 391 } |
| 392 | 392 |
| 393 } // namespace | 393 } // namespace |
| 394 } // namespace test | 394 } // namespace test |
| 395 } // namespace mojo | 395 } // namespace mojo |
| OLD | NEW |