Chromium Code Reviews| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 traits.priority() == base::TaskPriority::BACKGROUND; | 55 traits.priority() == base::TaskPriority::BACKGROUND; |
| 56 if (traits.may_block() || traits.with_base_sync_primitives()) | 56 if (traits.may_block() || traits.with_base_sync_primitives()) |
| 57 return is_background ? BACKGROUND_BLOCKING : FOREGROUND_BLOCKING; | 57 return is_background ? BACKGROUND_BLOCKING : FOREGROUND_BLOCKING; |
| 58 return is_background ? BACKGROUND : FOREGROUND; | 58 return is_background ? BACKGROUND : FOREGROUND; |
| 59 } | 59 } |
| 60 | 60 |
| 61 } // namespace | 61 } // namespace |
| 62 | 62 |
| 63 // static | 63 // static |
| 64 std::unique_ptr<TaskSchedulerImpl> TaskSchedulerImpl::Create( | 64 std::unique_ptr<TaskSchedulerImpl> TaskSchedulerImpl::Create( |
| 65 const std::string& name, | 65 StringPiece name, |
| 66 const TaskScheduler::InitParams& init_params) { | 66 const TaskScheduler::InitParams& init_params) { |
| 67 auto task_scheduler = WrapUnique(new TaskSchedulerImpl(name)); | 67 auto task_scheduler = WrapUnique(new TaskSchedulerImpl(name)); |
| 68 task_scheduler->Initialize(init_params); | 68 task_scheduler->Initialize(init_params); |
| 69 return task_scheduler; | 69 return task_scheduler; |
| 70 } | 70 } |
| 71 | 71 |
| 72 TaskSchedulerImpl::~TaskSchedulerImpl() { | 72 TaskSchedulerImpl::~TaskSchedulerImpl() { |
| 73 #if DCHECK_IS_ON() | 73 #if DCHECK_IS_ON() |
| 74 DCHECK(join_for_testing_returned_.IsSet()); | 74 DCHECK(join_for_testing_returned_.IsSet()); |
| 75 #endif | 75 #endif |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 for (const auto& worker_pool : worker_pools_) | 151 for (const auto& worker_pool : worker_pools_) |
| 152 worker_pool->DisallowWorkerDetachmentForTesting(); | 152 worker_pool->DisallowWorkerDetachmentForTesting(); |
| 153 for (const auto& worker_pool : worker_pools_) | 153 for (const auto& worker_pool : worker_pools_) |
| 154 worker_pool->JoinForTesting(); | 154 worker_pool->JoinForTesting(); |
| 155 service_thread_.Stop(); | 155 service_thread_.Stop(); |
| 156 #if DCHECK_IS_ON() | 156 #if DCHECK_IS_ON() |
| 157 join_for_testing_returned_.Set(); | 157 join_for_testing_returned_.Set(); |
| 158 #endif | 158 #endif |
| 159 } | 159 } |
| 160 | 160 |
| 161 TaskSchedulerImpl::TaskSchedulerImpl(const std::string& name) | 161 TaskSchedulerImpl::TaskSchedulerImpl(StringPiece name) |
| 162 : name_(name), service_thread_("TaskSchedulerServiceThread") {} | 162 : name_(name), service_thread_("TaskSchedulerServiceThread") {} |
|
gab
2017/04/13 15:34:52
Would expect you'd need name.as_string() for this
fdoray
2017/04/19 12:48:38
No, thanks to https://cs.chromium.org/chromium/src
| |
| 163 | 163 |
| 164 void TaskSchedulerImpl::Initialize( | 164 void TaskSchedulerImpl::Initialize( |
| 165 const TaskScheduler::InitParams& init_params) { | 165 const TaskScheduler::InitParams& init_params) { |
| 166 // Start the service thread. On platforms that support it (POSIX except NaCL | 166 // Start the service thread. On platforms that support it (POSIX except NaCL |
| 167 // SFI), the service thread runs a MessageLoopForIO which is used to support | 167 // SFI), the service thread runs a MessageLoopForIO which is used to support |
| 168 // FileDescriptorWatcher in the scope in which tasks run. | 168 // FileDescriptorWatcher in the scope in which tasks run. |
| 169 Thread::Options service_thread_options; | 169 Thread::Options service_thread_options; |
| 170 service_thread_options.message_loop_type = | 170 service_thread_options.message_loop_type = |
| 171 #if defined(OS_POSIX) && !defined(OS_NACL_SFI) | 171 #if defined(OS_POSIX) && !defined(OS_NACL_SFI) |
| 172 MessageLoop::TYPE_IO; | 172 MessageLoop::TYPE_IO; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 250 // in |sequence|. | 250 // in |sequence|. |
| 251 const TaskTraits traits = | 251 const TaskTraits traits = |
| 252 sequence->PeekTaskTraits().WithPriority(sort_key.priority()); | 252 sequence->PeekTaskTraits().WithPriority(sort_key.priority()); |
| 253 | 253 |
| 254 GetWorkerPoolForTraits(traits)->ReEnqueueSequence(std::move(sequence), | 254 GetWorkerPoolForTraits(traits)->ReEnqueueSequence(std::move(sequence), |
| 255 sort_key); | 255 sort_key); |
| 256 } | 256 } |
| 257 | 257 |
| 258 } // namespace internal | 258 } // namespace internal |
| 259 } // namespace base | 259 } // namespace base |
| OLD | NEW |