| 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/task_traits.h" | 19 #include "base/task_scheduler/task_traits.h" |
| 20 #include "base/task_scheduler/test_task_factory.h" | 20 #include "base/task_scheduler/test_task_factory.h" |
| 21 #include "base/task_scheduler/worker_pool_params.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 { |
| 29 | 30 |
| 30 namespace { | 31 namespace { |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 = SchedulerWorkerPoolImpl::IORestriction; |
| 162 | 163 |
| 163 std::vector<TaskSchedulerImpl::WorkerPoolCreationArgs> worker_pools; | 164 std::vector<WorkerPoolParams> worker_pools; |
| 164 | 165 |
| 165 ASSERT_EQ(BACKGROUND_WORKER_POOL, worker_pools.size()); | 166 ASSERT_EQ(BACKGROUND_WORKER_POOL, worker_pools.size()); |
| 166 worker_pools.push_back({"TaskSchedulerBackground", | 167 worker_pools.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, worker_pools.size()); |
| 171 worker_pools.push_back({"TaskSchedulerBackgroundFileIO", | 172 worker_pools.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, worker_pools.size()); |
| 176 worker_pools.push_back({"TaskSchedulerForeground", ThreadPriority::NORMAL, | 177 worker_pools.emplace_back("TaskSchedulerForeground", ThreadPriority::NORMAL, |
| 177 IORestriction::DISALLOWED, 4U}); | 178 IORestriction::DISALLOWED, 4U); |
| 178 | 179 |
| 179 ASSERT_EQ(FOREGROUND_FILE_IO_WORKER_POOL, worker_pools.size()); | 180 ASSERT_EQ(FOREGROUND_FILE_IO_WORKER_POOL, worker_pools.size()); |
| 180 worker_pools.push_back({"TaskSchedulerForegroundFileIO", | 181 worker_pools.emplace_back("TaskSchedulerForegroundFileIO", |
| 181 ThreadPriority::NORMAL, IORestriction::ALLOWED, | 182 ThreadPriority::NORMAL, IORestriction::ALLOWED, |
| 182 12U}); | 183 12U); |
| 183 | 184 |
| 184 scheduler_ = TaskSchedulerImpl::Create(worker_pools, | 185 scheduler_ = TaskSchedulerImpl::Create(worker_pools, |
| 185 Bind(&GetThreadPoolIndexForTraits)); | 186 Bind(&GetThreadPoolIndexForTraits)); |
| 186 ASSERT_TRUE(scheduler_); | 187 ASSERT_TRUE(scheduler_); |
| 187 } | 188 } |
| 188 | 189 |
| 189 void TearDown() override { scheduler_->JoinForTesting(); } | 190 void TearDown() override { scheduler_->JoinForTesting(); } |
| 190 | 191 |
| 191 std::unique_ptr<TaskSchedulerImpl> scheduler_; | 192 std::unique_ptr<TaskSchedulerImpl> scheduler_; |
| 192 | 193 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 thread->WaitForAllTasksToRun(); | 250 thread->WaitForAllTasksToRun(); |
| 250 thread->Join(); | 251 thread->Join(); |
| 251 } | 252 } |
| 252 } | 253 } |
| 253 | 254 |
| 254 // TODO(fdoray): Add tests with Sequences that move around worker pools once | 255 // TODO(fdoray): Add tests with Sequences that move around worker pools once |
| 255 // child TaskRunners are supported. | 256 // child TaskRunners are supported. |
| 256 | 257 |
| 257 } // namespace internal | 258 } // namespace internal |
| 258 } // namespace base | 259 } // namespace base |
| OLD | NEW |