| 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/lock.h" |
| 18 #include "base/synchronization/waitable_event.h" | 19 #include "base/synchronization/waitable_event.h" |
| 19 #include "base/task_scheduler/scheduler_worker_pool_params.h" | 20 #include "base/task_scheduler/scheduler_worker_pool_params.h" |
| 20 #include "base/task_scheduler/task_traits.h" | 21 #include "base/task_scheduler/task_traits.h" |
| 21 #include "base/task_scheduler/test_task_factory.h" | 22 #include "base/task_scheduler/test_task_factory.h" |
| 22 #include "base/threading/platform_thread.h" | 23 #include "base/threading/platform_thread.h" |
| 23 #include "base/threading/simple_thread.h" | 24 #include "base/threading/simple_thread.h" |
| 24 #include "base/threading/thread.h" | 25 #include "base/threading/thread.h" |
| 25 #include "base/threading/thread_restrictions.h" | 26 #include "base/threading/thread_restrictions.h" |
| 26 #include "base/time/time.h" | 27 #include "base/time/time.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 46 const bool previous_value = ThreadRestrictions::SetIOAllowed(true); | 47 const bool previous_value = ThreadRestrictions::SetIOAllowed(true); |
| 47 ThreadRestrictions::SetIOAllowed(previous_value); | 48 ThreadRestrictions::SetIOAllowed(previous_value); |
| 48 return previous_value; | 49 return previous_value; |
| 49 } | 50 } |
| 50 #endif | 51 #endif |
| 51 | 52 |
| 52 // Verify that the current thread priority and I/O restrictions are appropriate | 53 // Verify that the current thread priority and I/O restrictions are appropriate |
| 53 // to run a Task with |traits|. | 54 // to run a Task with |traits|. |
| 54 // Note: ExecutionMode is verified inside TestTaskFactory. | 55 // Note: ExecutionMode is verified inside TestTaskFactory. |
| 55 void VerifyTaskEnvironement(const TaskTraits& traits) { | 56 void VerifyTaskEnvironement(const TaskTraits& traits) { |
| 56 EXPECT_EQ(traits.priority() == TaskPriority::BACKGROUND | 57 const bool supports_background_priority = |
| 58 Lock::HandlesMultipleThreadPriorities() && |
| 59 PlatformThread::CanIncreaseCurrentThreadPriority(); |
| 60 |
| 61 EXPECT_EQ(supports_background_priority && |
| 62 traits.priority() == TaskPriority::BACKGROUND |
| 57 ? ThreadPriority::BACKGROUND | 63 ? ThreadPriority::BACKGROUND |
| 58 : ThreadPriority::NORMAL, | 64 : ThreadPriority::NORMAL, |
| 59 PlatformThread::GetCurrentThreadPriority()); | 65 PlatformThread::GetCurrentThreadPriority()); |
| 60 | 66 |
| 61 #if DCHECK_IS_ON() | 67 #if DCHECK_IS_ON() |
| 62 // The #if above is required because GetIOAllowed() always returns true when | 68 // The #if above is required because GetIOAllowed() always returns true when |
| 63 // !DCHECK_IS_ON(), even when |traits| don't allow file I/O. | 69 // !DCHECK_IS_ON(), even when |traits| don't allow file I/O. |
| 64 EXPECT_EQ(traits.with_file_io(), GetIOAllowed()); | 70 EXPECT_EQ(traits.with_file_io(), GetIOAllowed()); |
| 65 #endif | 71 #endif |
| 66 | 72 |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 thread->WaitForAllTasksToRun(); | 258 thread->WaitForAllTasksToRun(); |
| 253 thread->Join(); | 259 thread->Join(); |
| 254 } | 260 } |
| 255 } | 261 } |
| 256 | 262 |
| 257 // TODO(fdoray): Add tests with Sequences that move around worker pools once | 263 // TODO(fdoray): Add tests with Sequences that move around worker pools once |
| 258 // child TaskRunners are supported. | 264 // child TaskRunners are supported. |
| 259 | 265 |
| 260 } // namespace internal | 266 } // namespace internal |
| 261 } // namespace base | 267 } // namespace base |
| OLD | NEW |