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 "base/task_scheduler/task_tracker.h" | 5 #include "base/task_scheduler/task_tracker.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <vector> | 10 #include <vector> |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 TaskTraits().WithShutdownBehavior(shutdown_behavior), TimeDelta())); | 125 TaskTraits().WithShutdownBehavior(shutdown_behavior), TimeDelta())); |
126 } | 126 } |
127 | 127 |
128 // Calls tracker_->Shutdown() on a new thread. When this returns, Shutdown() | 128 // Calls tracker_->Shutdown() on a new thread. When this returns, Shutdown() |
129 // method has been entered on the new thread, but it hasn't necessarily | 129 // method has been entered on the new thread, but it hasn't necessarily |
130 // returned. | 130 // returned. |
131 void CallShutdownAsync() { | 131 void CallShutdownAsync() { |
132 ASSERT_FALSE(thread_calling_shutdown_); | 132 ASSERT_FALSE(thread_calling_shutdown_); |
133 thread_calling_shutdown_.reset(new ThreadCallingShutdown(&tracker_)); | 133 thread_calling_shutdown_.reset(new ThreadCallingShutdown(&tracker_)); |
134 thread_calling_shutdown_->Start(); | 134 thread_calling_shutdown_->Start(); |
135 while (!tracker_.IsShuttingDownForTesting() && | 135 while (!tracker_.IsShutdownInProgress() && !tracker_.IsShutdownComplete()) { |
136 !tracker_.IsShutdownComplete()) { | |
137 PlatformThread::YieldCurrentThread(); | 136 PlatformThread::YieldCurrentThread(); |
138 } | 137 } |
139 } | 138 } |
140 | 139 |
141 void WaitForAsyncIsShutdownComplete() { | 140 void WaitForAsyncIsShutdownComplete() { |
142 ASSERT_TRUE(thread_calling_shutdown_); | 141 ASSERT_TRUE(thread_calling_shutdown_); |
143 thread_calling_shutdown_->Join(); | 142 thread_calling_shutdown_->Join(); |
144 EXPECT_TRUE(thread_calling_shutdown_->has_returned()); | 143 EXPECT_TRUE(thread_calling_shutdown_->has_returned()); |
145 EXPECT_TRUE(tracker_.IsShutdownComplete()); | 144 EXPECT_TRUE(tracker_.IsShutdownComplete()); |
146 } | 145 } |
147 | 146 |
148 void VerifyAsyncShutdownInProgress() { | 147 void VerifyAsyncShutdownInProgress() { |
149 ASSERT_TRUE(thread_calling_shutdown_); | 148 ASSERT_TRUE(thread_calling_shutdown_); |
150 EXPECT_FALSE(thread_calling_shutdown_->has_returned()); | 149 EXPECT_FALSE(thread_calling_shutdown_->has_returned()); |
151 EXPECT_FALSE(tracker_.IsShutdownComplete()); | 150 EXPECT_FALSE(tracker_.IsShutdownComplete()); |
152 EXPECT_TRUE(tracker_.IsShuttingDownForTesting()); | 151 EXPECT_TRUE(tracker_.IsShutdownInProgress()); |
153 } | 152 } |
154 | 153 |
155 size_t NumTasksExecuted() { | 154 size_t NumTasksExecuted() { |
156 AutoSchedulerLock auto_lock(lock_); | 155 AutoSchedulerLock auto_lock(lock_); |
157 return num_tasks_executed_; | 156 return num_tasks_executed_; |
158 } | 157 } |
159 | 158 |
160 TaskTracker tracker_; | 159 TaskTracker tracker_; |
161 | 160 |
162 private: | 161 private: |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
596 VERIFY_ASYNC_SHUTDOWN_IN_PROGRESS(); | 595 VERIFY_ASYNC_SHUTDOWN_IN_PROGRESS(); |
597 | 596 |
598 // Unblock shutdown by running |block_shutdown_task|. | 597 // Unblock shutdown by running |block_shutdown_task|. |
599 tracker_.RunTask(block_shutdown_task.get()); | 598 tracker_.RunTask(block_shutdown_task.get()); |
600 EXPECT_EQ(kLoadTestNumIterations + 1, NumTasksExecuted()); | 599 EXPECT_EQ(kLoadTestNumIterations + 1, NumTasksExecuted()); |
601 WAIT_FOR_ASYNC_SHUTDOWN_COMPLETED(); | 600 WAIT_FOR_ASYNC_SHUTDOWN_COMPLETED(); |
602 } | 601 } |
603 | 602 |
604 } // namespace internal | 603 } // namespace internal |
605 } // namespace base | 604 } // namespace base |
OLD | NEW |