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_scheduler_impl.h" | 5 #include "base/task_scheduler/task_scheduler_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/bind_helpers.h" | 14 #include "base/bind_helpers.h" |
15 #include "base/callback.h" | 15 #include "base/callback.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
18 #include "base/synchronization/waitable_event.h" | 18 #include "base/synchronization/waitable_event.h" |
| 19 #include "base/task_scheduler/scheduler_worker_pool_params.h" |
19 #include "base/task_scheduler/task_traits.h" | 20 #include "base/task_scheduler/task_traits.h" |
20 #include "base/task_scheduler/test_task_factory.h" | 21 #include "base/task_scheduler/test_task_factory.h" |
21 #include "base/threading/platform_thread.h" | 22 #include "base/threading/platform_thread.h" |
22 #include "base/threading/simple_thread.h" | 23 #include "base/threading/simple_thread.h" |
23 #include "base/threading/thread.h" | 24 #include "base/threading/thread.h" |
24 #include "base/threading/thread_restrictions.h" | 25 #include "base/threading/thread_restrictions.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
26 | 27 |
27 namespace base { | 28 namespace base { |
28 namespace internal { | 29 namespace internal { |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 return traits.priority() == TaskPriority::BACKGROUND ? BACKGROUND_WORKER_POOL | 152 return traits.priority() == TaskPriority::BACKGROUND ? BACKGROUND_WORKER_POOL |
152 : FOREGROUND_WORKER_POOL; | 153 : FOREGROUND_WORKER_POOL; |
153 } | 154 } |
154 | 155 |
155 class TaskSchedulerImplTest | 156 class TaskSchedulerImplTest |
156 : public testing::TestWithParam<TraitsExecutionModePair> { | 157 : public testing::TestWithParam<TraitsExecutionModePair> { |
157 protected: | 158 protected: |
158 TaskSchedulerImplTest() = default; | 159 TaskSchedulerImplTest() = default; |
159 | 160 |
160 void SetUp() override { | 161 void SetUp() override { |
161 using IORestriction = SchedulerWorkerPoolImpl::IORestriction; | 162 using IORestriction = SchedulerWorkerPoolParams::IORestriction; |
162 | 163 |
163 std::vector<TaskSchedulerImpl::WorkerPoolCreationArgs> worker_pools; | 164 std::vector<SchedulerWorkerPoolParams> params_vector; |
164 | 165 |
165 ASSERT_EQ(BACKGROUND_WORKER_POOL, worker_pools.size()); | 166 ASSERT_EQ(BACKGROUND_WORKER_POOL, params_vector.size()); |
166 worker_pools.push_back({"TaskSchedulerBackground", | 167 params_vector.emplace_back("TaskSchedulerBackground", |
167 ThreadPriority::BACKGROUND, | 168 ThreadPriority::BACKGROUND, |
168 IORestriction::DISALLOWED, 1U}); | 169 IORestriction::DISALLOWED, 1U); |
169 | 170 |
170 ASSERT_EQ(BACKGROUND_FILE_IO_WORKER_POOL, worker_pools.size()); | 171 ASSERT_EQ(BACKGROUND_FILE_IO_WORKER_POOL, params_vector.size()); |
171 worker_pools.push_back({"TaskSchedulerBackgroundFileIO", | 172 params_vector.emplace_back("TaskSchedulerBackgroundFileIO", |
172 ThreadPriority::BACKGROUND, IORestriction::ALLOWED, | 173 ThreadPriority::BACKGROUND, |
173 3U}); | 174 IORestriction::ALLOWED, 3U); |
174 | 175 |
175 ASSERT_EQ(FOREGROUND_WORKER_POOL, worker_pools.size()); | 176 ASSERT_EQ(FOREGROUND_WORKER_POOL, params_vector.size()); |
176 worker_pools.push_back({"TaskSchedulerForeground", ThreadPriority::NORMAL, | 177 params_vector.emplace_back("TaskSchedulerForeground", |
177 IORestriction::DISALLOWED, 4U}); | 178 ThreadPriority::NORMAL, |
| 179 IORestriction::DISALLOWED, 4U); |
178 | 180 |
179 ASSERT_EQ(FOREGROUND_FILE_IO_WORKER_POOL, worker_pools.size()); | 181 ASSERT_EQ(FOREGROUND_FILE_IO_WORKER_POOL, params_vector.size()); |
180 worker_pools.push_back({"TaskSchedulerForegroundFileIO", | 182 params_vector.emplace_back("TaskSchedulerForegroundFileIO", |
181 ThreadPriority::NORMAL, IORestriction::ALLOWED, | 183 ThreadPriority::NORMAL, IORestriction::ALLOWED, |
182 12U}); | 184 12U); |
183 | 185 |
184 scheduler_ = TaskSchedulerImpl::Create(worker_pools, | 186 scheduler_ = TaskSchedulerImpl::Create(params_vector, |
185 Bind(&GetThreadPoolIndexForTraits)); | 187 Bind(&GetThreadPoolIndexForTraits)); |
186 ASSERT_TRUE(scheduler_); | 188 ASSERT_TRUE(scheduler_); |
187 } | 189 } |
188 | 190 |
189 void TearDown() override { scheduler_->JoinForTesting(); } | 191 void TearDown() override { scheduler_->JoinForTesting(); } |
190 | 192 |
191 std::unique_ptr<TaskSchedulerImpl> scheduler_; | 193 std::unique_ptr<TaskSchedulerImpl> scheduler_; |
192 | 194 |
193 private: | 195 private: |
194 DISALLOW_COPY_AND_ASSIGN(TaskSchedulerImplTest); | 196 DISALLOW_COPY_AND_ASSIGN(TaskSchedulerImplTest); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 thread->WaitForAllTasksToRun(); | 251 thread->WaitForAllTasksToRun(); |
250 thread->Join(); | 252 thread->Join(); |
251 } | 253 } |
252 } | 254 } |
253 | 255 |
254 // TODO(fdoray): Add tests with Sequences that move around worker pools once | 256 // TODO(fdoray): Add tests with Sequences that move around worker pools once |
255 // child TaskRunners are supported. | 257 // child TaskRunners are supported. |
256 | 258 |
257 } // namespace internal | 259 } // namespace internal |
258 } // namespace base | 260 } // namespace base |
OLD | NEW |