OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "content/renderer/categorized_worker_pool.h" | 5 #include "content/renderer/categorized_worker_pool.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "base/threading/thread_restrictions.h" | 12 #include "base/threading/thread_restrictions.h" |
13 #include "base/trace_event/trace_event.h" | 13 #include "base/trace_event/trace_event.h" |
14 #include "cc/base/math_util.h" | 14 #include "cc/base/math_util.h" |
15 #include "cc/raster/task_category.h" | 15 #include "cc/raster/task_category.h" |
16 | 16 |
17 namespace content { | 17 namespace content { |
18 namespace { | 18 namespace { |
19 | 19 |
20 const int kHeartbeatIntervalInSeconds = 60; // 1 minute | |
robliao
2016/06/07 15:40:30
constexpr
| |
21 | |
20 // A thread which forwards to CategorizedWorkerPool::Run with the runnable | 22 // A thread which forwards to CategorizedWorkerPool::Run with the runnable |
21 // categories. | 23 // categories. |
22 class CategorizedWorkerPoolThread : public base::SimpleThread { | 24 class CategorizedWorkerPoolThread : public base::SimpleThread { |
23 public: | 25 public: |
24 CategorizedWorkerPoolThread( | 26 CategorizedWorkerPoolThread( |
25 const std::string& name_prefix, | 27 const std::string& name_prefix, |
26 const Options& options, | 28 const Options& options, |
27 CategorizedWorkerPool* pool, | 29 CategorizedWorkerPool* pool, |
28 std::vector<cc::TaskCategory> categories, | 30 std::vector<cc::TaskCategory> categories, |
29 base::ConditionVariable* has_ready_to_run_tasks_cv) | 31 base::ConditionVariable* has_ready_to_run_tasks_cv) |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
232 if (!RunTaskWithLockAcquired(categories)) { | 234 if (!RunTaskWithLockAcquired(categories)) { |
233 // We are no longer running tasks, which may allow another category to | 235 // We are no longer running tasks, which may allow another category to |
234 // start running. Signal other worker threads. | 236 // start running. Signal other worker threads. |
235 SignalHasReadyToRunTasksWithLockAcquired(); | 237 SignalHasReadyToRunTasksWithLockAcquired(); |
236 | 238 |
237 // Exit when shutdown is set and no more tasks are pending. | 239 // Exit when shutdown is set and no more tasks are pending. |
238 if (shutdown_) | 240 if (shutdown_) |
239 break; | 241 break; |
240 | 242 |
241 // Wait for more tasks. | 243 // Wait for more tasks. |
242 has_ready_to_run_tasks_cv->Wait(); | 244 WaitForMoreTasksWithLockAcquired(has_ready_to_run_tasks_cv); |
243 continue; | 245 continue; |
244 } | 246 } |
245 } | 247 } |
246 } | 248 } |
247 | 249 |
250 void CategorizedWorkerPool::WaitForMoreTasksWithLockAcquired( | |
251 base::ConditionVariable* has_ready_to_run_tasks_cv) { | |
252 const base::TimeDelta timeout = | |
253 base::TimeDelta::FromSeconds(kHeartbeatIntervalInSeconds); | |
254 while (true) { | |
robliao
2016/06/07 15:40:30
while (has_ready_to_run_tasks_cv->TimedWait(timeou
| |
255 if (!has_ready_to_run_tasks_cv->TimedWait(timeout)) | |
256 break; | |
257 | |
258 TRACE_EVENT_INSTANT0( | |
259 "heartbeat", "CategorizedWorkerPool::HeartbeatDuringWaitForMoreTasks", | |
260 TRACE_EVENT_SCOPE_THREAD); | |
261 } | |
262 } | |
263 | |
248 void CategorizedWorkerPool::FlushForTesting() { | 264 void CategorizedWorkerPool::FlushForTesting() { |
249 base::AutoLock lock(lock_); | 265 base::AutoLock lock(lock_); |
250 | 266 |
251 while (!work_queue_.HasFinishedRunningTasksInAllNamespaces()) { | 267 while (!work_queue_.HasFinishedRunningTasksInAllNamespaces()) { |
252 has_namespaces_with_finished_running_tasks_cv_.Wait(); | 268 has_namespaces_with_finished_running_tasks_cv_.Wait(); |
253 } | 269 } |
254 } | 270 } |
255 | 271 |
256 scoped_refptr<base::SequencedTaskRunner> | 272 scoped_refptr<base::SequencedTaskRunner> |
257 CategorizedWorkerPool::CreateSequencedTaskRunner() { | 273 CategorizedWorkerPool::CreateSequencedTaskRunner() { |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
422 | 438 |
423 // Overridden from cc::Task: | 439 // Overridden from cc::Task: |
424 void CategorizedWorkerPool::ClosureTask::RunOnWorkerThread() { | 440 void CategorizedWorkerPool::ClosureTask::RunOnWorkerThread() { |
425 closure_.Run(); | 441 closure_.Run(); |
426 closure_.Reset(); | 442 closure_.Reset(); |
427 } | 443 } |
428 | 444 |
429 CategorizedWorkerPool::ClosureTask::~ClosureTask() {} | 445 CategorizedWorkerPool::ClosureTask::~ClosureTask() {} |
430 | 446 |
431 } // namespace content | 447 } // namespace content |
OLD | NEW |