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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 re_enqueue_sequence_callback = | 83 re_enqueue_sequence_callback = |
84 Bind(&TaskSchedulerImpl::ReEnqueueSequenceCallback, Unretained(this)); | 84 Bind(&TaskSchedulerImpl::ReEnqueueSequenceCallback, Unretained(this)); |
85 | 85 |
86 // TODO(fdoray): Derive the number of threads per pool from hardware | 86 // TODO(fdoray): Derive the number of threads per pool from hardware |
87 // characteristics rather than using hard-coded constants. | 87 // characteristics rather than using hard-coded constants. |
88 | 88 |
89 // Passing pointers to objects owned by |this| to | 89 // Passing pointers to objects owned by |this| to |
90 // SchedulerThreadPoolImpl::Create() is safe because a TaskSchedulerImpl can't | 90 // SchedulerThreadPoolImpl::Create() is safe because a TaskSchedulerImpl can't |
91 // be deleted before all its thread pools have been joined. | 91 // be deleted before all its thread pools have been joined. |
92 background_thread_pool_ = SchedulerThreadPoolImpl::Create( | 92 background_thread_pool_ = SchedulerThreadPoolImpl::Create( |
93 ThreadPriority::BACKGROUND, 1u, IORestriction::DISALLOWED, | 93 "TaskSchedulerBackground", ThreadPriority::BACKGROUND, 1u, |
94 re_enqueue_sequence_callback, &task_tracker_, &delayed_task_manager_); | 94 IORestriction::DISALLOWED, re_enqueue_sequence_callback, &task_tracker_, |
95 &delayed_task_manager_); | |
95 CHECK(background_thread_pool_); | 96 CHECK(background_thread_pool_); |
96 | 97 |
97 background_file_io_thread_pool_ = SchedulerThreadPoolImpl::Create( | 98 background_file_io_thread_pool_ = SchedulerThreadPoolImpl::Create( |
98 ThreadPriority::BACKGROUND, 1u, IORestriction::ALLOWED, | 99 "TaskSchedulerBackgroundFileIO", ThreadPriority::BACKGROUND, 1u, |
99 re_enqueue_sequence_callback, &task_tracker_, &delayed_task_manager_); | 100 IORestriction::ALLOWED, re_enqueue_sequence_callback, &task_tracker_, |
101 &delayed_task_manager_); | |
100 CHECK(background_file_io_thread_pool_); | 102 CHECK(background_file_io_thread_pool_); |
101 | 103 |
102 normal_thread_pool_ = SchedulerThreadPoolImpl::Create( | 104 normal_thread_pool_ = SchedulerThreadPoolImpl::Create( |
103 ThreadPriority::NORMAL, 4u, IORestriction::DISALLOWED, | 105 "TaskSchedulerForeground", ThreadPriority::NORMAL, 4u, |
104 re_enqueue_sequence_callback, &task_tracker_, &delayed_task_manager_); | 106 IORestriction::DISALLOWED, re_enqueue_sequence_callback, &task_tracker_, |
107 &delayed_task_manager_); | |
105 CHECK(normal_thread_pool_); | 108 CHECK(normal_thread_pool_); |
106 | 109 |
107 normal_file_io_thread_pool_ = SchedulerThreadPoolImpl::Create( | 110 normal_file_io_thread_pool_ = SchedulerThreadPoolImpl::Create( |
108 ThreadPriority::NORMAL, 12u, IORestriction::ALLOWED, | 111 "TaskSchedulerForegroundFileIO", ThreadPriority::NORMAL, 12u, |
fdoray
2016/05/03 19:01:50
Add a verification in VerifyTaskEnvironment in tas
gab
2016/05/04 18:11:37
Done though I'm afraid it's a bit too much of a wh
| |
109 re_enqueue_sequence_callback, &task_tracker_, &delayed_task_manager_); | 112 IORestriction::ALLOWED, re_enqueue_sequence_callback, &task_tracker_, |
113 &delayed_task_manager_); | |
110 CHECK(normal_file_io_thread_pool_); | 114 CHECK(normal_file_io_thread_pool_); |
111 } | 115 } |
112 | 116 |
113 SchedulerThreadPool* TaskSchedulerImpl::GetThreadPoolForTraits( | 117 SchedulerThreadPool* TaskSchedulerImpl::GetThreadPoolForTraits( |
114 const TaskTraits& traits) { | 118 const TaskTraits& traits) { |
115 if (traits.with_file_io()) { | 119 if (traits.with_file_io()) { |
116 if (traits.priority() == TaskPriority::BACKGROUND) | 120 if (traits.priority() == TaskPriority::BACKGROUND) |
117 return background_file_io_thread_pool_.get(); | 121 return background_file_io_thread_pool_.get(); |
118 return normal_file_io_thread_pool_.get(); | 122 return normal_file_io_thread_pool_.get(); |
119 } | 123 } |
(...skipping 14 matching lines...) Expand all Loading... | |
134 // with the highest priority in |sequence| as opposed to the next task's | 138 // with the highest priority in |sequence| as opposed to the next task's |
135 // specific priority. | 139 // specific priority. |
136 traits.WithPriority(sort_key.priority()); | 140 traits.WithPriority(sort_key.priority()); |
137 | 141 |
138 GetThreadPoolForTraits(traits)->ReEnqueueSequence(std::move(sequence), | 142 GetThreadPoolForTraits(traits)->ReEnqueueSequence(std::move(sequence), |
139 sort_key); | 143 sort_key); |
140 } | 144 } |
141 | 145 |
142 } // namespace internal | 146 } // namespace internal |
143 } // namespace base | 147 } // namespace base |
OLD | NEW |