| 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> |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 struct TraitsExecutionModePair { | 34 struct TraitsExecutionModePair { |
| 35 TraitsExecutionModePair(const TaskTraits& traits, | 35 TraitsExecutionModePair(const TaskTraits& traits, |
| 36 ExecutionMode execution_mode) | 36 ExecutionMode execution_mode) |
| 37 : traits(traits), execution_mode(execution_mode) {} | 37 : traits(traits), execution_mode(execution_mode) {} |
| 38 | 38 |
| 39 TaskTraits traits; | 39 TaskTraits traits; |
| 40 ExecutionMode execution_mode; | 40 ExecutionMode execution_mode; |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 #if ENABLE_THREAD_RESTRICTIONS | 43 #if DCHECK_IS_ON() |
| 44 // Returns whether I/O calls are allowed on the current thread. | 44 // Returns whether I/O calls are allowed on the current thread. |
| 45 bool GetIOAllowed() { | 45 bool GetIOAllowed() { |
| 46 const bool previous_value = ThreadRestrictions::SetIOAllowed(true); | 46 const bool previous_value = ThreadRestrictions::SetIOAllowed(true); |
| 47 ThreadRestrictions::SetIOAllowed(previous_value); | 47 ThreadRestrictions::SetIOAllowed(previous_value); |
| 48 return previous_value; | 48 return previous_value; |
| 49 } | 49 } |
| 50 #endif | 50 #endif |
| 51 | 51 |
| 52 // Verify that the current thread priority and I/O restrictions are appropriate | 52 // Verify that the current thread priority and I/O restrictions are appropriate |
| 53 // to run a Task with |traits|. | 53 // to run a Task with |traits|. |
| 54 // Note: ExecutionMode is verified inside TestTaskFactory. | 54 // Note: ExecutionMode is verified inside TestTaskFactory. |
| 55 void VerifyTaskEnvironement(const TaskTraits& traits) { | 55 void VerifyTaskEnvironement(const TaskTraits& traits) { |
| 56 EXPECT_EQ(traits.priority() == TaskPriority::BACKGROUND | 56 EXPECT_EQ(traits.priority() == TaskPriority::BACKGROUND |
| 57 ? ThreadPriority::BACKGROUND | 57 ? ThreadPriority::BACKGROUND |
| 58 : ThreadPriority::NORMAL, | 58 : ThreadPriority::NORMAL, |
| 59 PlatformThread::GetCurrentThreadPriority()); | 59 PlatformThread::GetCurrentThreadPriority()); |
| 60 | 60 |
| 61 #if ENABLE_THREAD_RESTRICTIONS | 61 #if DCHECK_IS_ON() |
| 62 // The #if above is required because GetIOAllowed() always returns true when | 62 // The #if above is required because GetIOAllowed() always returns true when |
| 63 // !ENABLE_THREAD_RESTRICTIONS, even when |traits| don't allow file I/O. | 63 // !DCHECK_IS_ON(), even when |traits| don't allow file I/O. |
| 64 EXPECT_EQ(traits.with_file_io(), GetIOAllowed()); | 64 EXPECT_EQ(traits.with_file_io(), GetIOAllowed()); |
| 65 #endif | 65 #endif |
| 66 | 66 |
| 67 // Verify that the thread the task is running on is named as expected. | 67 // Verify that the thread the task is running on is named as expected. |
| 68 const std::string current_thread_name(PlatformThread::GetName()); | 68 const std::string current_thread_name(PlatformThread::GetName()); |
| 69 EXPECT_NE(std::string::npos, current_thread_name.find("TaskScheduler")); | 69 EXPECT_NE(std::string::npos, current_thread_name.find("TaskScheduler")); |
| 70 EXPECT_NE(std::string::npos, | 70 EXPECT_NE(std::string::npos, |
| 71 current_thread_name.find( | 71 current_thread_name.find( |
| 72 traits.priority() == TaskPriority::BACKGROUND ? "Background" | 72 traits.priority() == TaskPriority::BACKGROUND ? "Background" |
| 73 : "Foreground")); | 73 : "Foreground")); |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 thread->WaitForAllTasksToRun(); | 252 thread->WaitForAllTasksToRun(); |
| 253 thread->Join(); | 253 thread->Join(); |
| 254 } | 254 } |
| 255 } | 255 } |
| 256 | 256 |
| 257 // 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 |
| 258 // child TaskRunners are supported. | 258 // child TaskRunners are supported. |
| 259 | 259 |
| 260 } // namespace internal | 260 } // namespace internal |
| 261 } // namespace base | 261 } // namespace base |
| OLD | NEW |