| 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/scheduler_worker_pool_params.h" |
| 20 #include "base/task_scheduler/task_traits.h" | 20 #include "base/task_scheduler/task_traits.h" |
| 21 #include "base/task_scheduler/test_task_factory.h" | 21 #include "base/task_scheduler/test_task_factory.h" |
| 22 #include "base/threading/platform_thread.h" | 22 #include "base/threading/platform_thread.h" |
| 23 #include "base/threading/simple_thread.h" | 23 #include "base/threading/simple_thread.h" |
| 24 #include "base/threading/thread.h" | 24 #include "base/threading/thread.h" |
| 25 #include "base/threading/thread_restrictions.h" | 25 #include "base/threading/thread_restrictions.h" |
| 26 #include "base/time/time.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| 27 | 28 |
| 28 namespace base { | 29 namespace base { |
| 29 namespace internal { | 30 namespace internal { |
| 30 | 31 |
| 31 namespace { | 32 namespace { |
| 32 | 33 |
| 33 struct TraitsExecutionModePair { | 34 struct TraitsExecutionModePair { |
| 34 TraitsExecutionModePair(const TaskTraits& traits, | 35 TraitsExecutionModePair(const TaskTraits& traits, |
| 35 ExecutionMode execution_mode) | 36 ExecutionMode execution_mode) |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 TaskSchedulerImplTest() = default; | 160 TaskSchedulerImplTest() = default; |
| 160 | 161 |
| 161 void SetUp() override { | 162 void SetUp() override { |
| 162 using IORestriction = SchedulerWorkerPoolParams::IORestriction; | 163 using IORestriction = SchedulerWorkerPoolParams::IORestriction; |
| 163 | 164 |
| 164 std::vector<SchedulerWorkerPoolParams> params_vector; | 165 std::vector<SchedulerWorkerPoolParams> params_vector; |
| 165 | 166 |
| 166 ASSERT_EQ(BACKGROUND_WORKER_POOL, params_vector.size()); | 167 ASSERT_EQ(BACKGROUND_WORKER_POOL, params_vector.size()); |
| 167 params_vector.emplace_back("TaskSchedulerBackground", | 168 params_vector.emplace_back("TaskSchedulerBackground", |
| 168 ThreadPriority::BACKGROUND, | 169 ThreadPriority::BACKGROUND, |
| 169 IORestriction::DISALLOWED, 1U); | 170 IORestriction::DISALLOWED, 1U, TimeDelta::Max()); |
| 170 | 171 |
| 171 ASSERT_EQ(BACKGROUND_FILE_IO_WORKER_POOL, params_vector.size()); | 172 ASSERT_EQ(BACKGROUND_FILE_IO_WORKER_POOL, params_vector.size()); |
| 172 params_vector.emplace_back("TaskSchedulerBackgroundFileIO", | 173 params_vector.emplace_back("TaskSchedulerBackgroundFileIO", |
| 173 ThreadPriority::BACKGROUND, | 174 ThreadPriority::BACKGROUND, |
| 174 IORestriction::ALLOWED, 3U); | 175 IORestriction::ALLOWED, 3U, TimeDelta::Max()); |
| 175 | 176 |
| 176 ASSERT_EQ(FOREGROUND_WORKER_POOL, params_vector.size()); | 177 ASSERT_EQ(FOREGROUND_WORKER_POOL, params_vector.size()); |
| 177 params_vector.emplace_back("TaskSchedulerForeground", | 178 params_vector.emplace_back("TaskSchedulerForeground", |
| 178 ThreadPriority::NORMAL, | 179 ThreadPriority::NORMAL, |
| 179 IORestriction::DISALLOWED, 4U); | 180 IORestriction::DISALLOWED, 4U, TimeDelta::Max()); |
| 180 | 181 |
| 181 ASSERT_EQ(FOREGROUND_FILE_IO_WORKER_POOL, params_vector.size()); | 182 ASSERT_EQ(FOREGROUND_FILE_IO_WORKER_POOL, params_vector.size()); |
| 182 params_vector.emplace_back("TaskSchedulerForegroundFileIO", | 183 params_vector.emplace_back("TaskSchedulerForegroundFileIO", |
| 183 ThreadPriority::NORMAL, IORestriction::ALLOWED, | 184 ThreadPriority::NORMAL, IORestriction::ALLOWED, |
| 184 12U); | 185 12U, TimeDelta::Max()); |
| 185 | 186 |
| 186 scheduler_ = TaskSchedulerImpl::Create(params_vector, | 187 scheduler_ = TaskSchedulerImpl::Create(params_vector, |
| 187 Bind(&GetThreadPoolIndexForTraits)); | 188 Bind(&GetThreadPoolIndexForTraits)); |
| 188 ASSERT_TRUE(scheduler_); | 189 ASSERT_TRUE(scheduler_); |
| 189 } | 190 } |
| 190 | 191 |
| 191 void TearDown() override { scheduler_->JoinForTesting(); } | 192 void TearDown() override { scheduler_->JoinForTesting(); } |
| 192 | 193 |
| 193 std::unique_ptr<TaskSchedulerImpl> scheduler_; | 194 std::unique_ptr<TaskSchedulerImpl> scheduler_; |
| 194 | 195 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 thread->WaitForAllTasksToRun(); | 252 thread->WaitForAllTasksToRun(); |
| 252 thread->Join(); | 253 thread->Join(); |
| 253 } | 254 } |
| 254 } | 255 } |
| 255 | 256 |
| 256 // TODO(fdoray): Add tests with Sequences that move around worker pools once | 257 // TODO(fdoray): Add tests with Sequences that move around worker pools once |
| 257 // child TaskRunners are supported. | 258 // child TaskRunners are supported. |
| 258 | 259 |
| 259 } // namespace internal | 260 } // namespace internal |
| 260 } // namespace base | 261 } // namespace base |
| OLD | NEW |