Chromium Code Reviews| Index: cc/resources/one_copy_raster_worker_pool.cc |
| diff --git a/cc/resources/one_copy_raster_worker_pool.cc b/cc/resources/one_copy_raster_worker_pool.cc |
| index cdef6bad2efcde54e2a21ec2247d790786f8257b..a6f189afb86b188936c337d38a1085445915da86 100644 |
| --- a/cc/resources/one_copy_raster_worker_pool.cc |
| +++ b/cc/resources/one_copy_raster_worker_pool.cc |
| @@ -87,6 +87,10 @@ const int kMaxCopyOperations = 16; |
| // Delay been checking for copy operations to complete. |
| const int kCheckForCompletedCopyOperationsTickRateMs = 1; |
| +// Number of failed attempts to allow before we perform a check that will |
| +// wait for copy operations to complete if needed. |
| +const int kFailedAttemptsBeforeWaitIfNeeded = 256; |
|
vmpstr
2014/10/29 17:36:25
Is there any way we can eliminate some of these co
reveman
2014/10/29 18:42:48
Not sure. This last constant is just to detect dri
|
| + |
| } // namespace |
| OneCopyRasterWorkerPool::CopyOperation::CopyOperation( |
| @@ -195,7 +199,7 @@ void OneCopyRasterWorkerPool::ScheduleTasks(RasterTaskQueue* queue) { |
| task_set)); |
| } |
| - resource_pool_->CheckBusyResources(); |
| + resource_pool_->CheckBusyResources(false); |
| for (RasterTaskQueue::Item::Vector::const_iterator it = queue->items.begin(); |
| it != queue->items.end(); |
| @@ -283,15 +287,22 @@ OneCopyRasterWorkerPool::PlaybackAndScheduleCopyOnWorkerThread( |
| { |
| base::AutoLock lock(lock_); |
| + int failed_attempts = 0; |
| while ((scheduled_copy_operation_count_ + issued_copy_operation_count_) >= |
| kMaxCopyOperations) { |
| // Ignore limit when shutdown is set. |
| if (shutdown_) |
| break; |
| + ++failed_attempts; |
| + |
| + // Schedule a check that will also wait for operations to complete |
| + // after too many failed attempts. |
| + bool wait_if_needed = failed_attempts > kFailedAttemptsBeforeWaitIfNeeded; |
| + |
| // Schedule a check for completed copy operations if too many operations |
| // are currently in-flight. |
| - ScheduleCheckForCompletedCopyOperationsWithLockAcquired(); |
| + ScheduleCheckForCompletedCopyOperationsWithLockAcquired(wait_if_needed); |
| { |
| TRACE_EVENT0("cc", "WaitingForCopyOperationsToComplete"); |
| @@ -389,7 +400,7 @@ void OneCopyRasterWorkerPool::IssueCopyOperations(int64 count) { |
| // This is a good time to check for completed copy operations as |
| // |issued_copy_operation_count_| need to be updated below. |
| - resource_pool_->CheckBusyResources(); |
| + resource_pool_->CheckBusyResources(false); |
| { |
| base::AutoLock lock(lock_); |
| @@ -426,7 +437,8 @@ void OneCopyRasterWorkerPool::IssueCopyOperations(int64 count) { |
| } |
| void OneCopyRasterWorkerPool:: |
| - ScheduleCheckForCompletedCopyOperationsWithLockAcquired() { |
| + ScheduleCheckForCompletedCopyOperationsWithLockAcquired( |
| + bool wait_if_needed) { |
| lock_.AssertAcquired(); |
| if (check_for_completed_copy_operations_pending_) |
| @@ -446,7 +458,8 @@ void OneCopyRasterWorkerPool:: |
| task_runner_->PostDelayedTask( |
| FROM_HERE, |
| base::Bind(&OneCopyRasterWorkerPool::CheckForCompletedCopyOperations, |
| - weak_ptr_factory_.GetWeakPtr()), |
| + weak_ptr_factory_.GetWeakPtr(), |
| + wait_if_needed), |
| next_check_for_completed_copy_operations_time - now); |
| last_check_for_completed_copy_operations_time_ = |
| @@ -454,11 +467,14 @@ void OneCopyRasterWorkerPool:: |
| check_for_completed_copy_operations_pending_ = true; |
| } |
| -void OneCopyRasterWorkerPool::CheckForCompletedCopyOperations() { |
| - TRACE_EVENT0("cc", |
| - "OneCopyRasterWorkerPool::CheckForCompletedCopyOperations"); |
| +void OneCopyRasterWorkerPool::CheckForCompletedCopyOperations( |
| + bool wait_if_needed) { |
| + TRACE_EVENT1("cc", |
| + "OneCopyRasterWorkerPool::CheckForCompletedCopyOperations", |
| + "wait_if_needed", |
| + wait_if_needed); |
| - resource_pool_->CheckBusyResources(); |
| + resource_pool_->CheckBusyResources(wait_if_needed); |
| { |
| base::AutoLock lock(lock_); |