Commit d130dcdd authored by reveman's avatar reveman Committed by Commit bot

cc: Fix WeakPtrFactory::GetWeakPtr() race when using multiple raster worker threads.

This prevents multiple threads from being able to call GetWeakPtr()
at the same time by making sure the lock is acquired when this is
called.

R=vmpstr@chromium.org
BUG=

Review URL: https://codereview.chromium.org/700843004

Cr-Commit-Position: refs/heads/master@{#302717}
parent 2610ea15
...@@ -275,61 +275,60 @@ OneCopyRasterWorkerPool::PlaybackAndScheduleCopyOnWorkerThread( ...@@ -275,61 +275,60 @@ OneCopyRasterWorkerPool::PlaybackAndScheduleCopyOnWorkerThread(
const RasterSource* raster_source, const RasterSource* raster_source,
const gfx::Rect& rect, const gfx::Rect& rect,
float scale) { float scale) {
CopySequenceNumber sequence; base::AutoLock lock(lock_);
{ int failed_attempts = 0;
base::AutoLock lock(lock_); while ((scheduled_copy_operation_count_ + issued_copy_operation_count_) >=
kMaxCopyOperations) {
int failed_attempts = 0; // Ignore limit when shutdown is set.
while ((scheduled_copy_operation_count_ + issued_copy_operation_count_) >= if (shutdown_)
kMaxCopyOperations) { break;
// Ignore limit when shutdown is set.
if (shutdown_)
break;
++failed_attempts; ++failed_attempts;
// Schedule a check that will also wait for operations to complete // Schedule a check that will also wait for operations to complete
// after too many failed attempts. // after too many failed attempts.
bool wait_if_needed = failed_attempts > kFailedAttemptsBeforeWaitIfNeeded; bool wait_if_needed = failed_attempts > kFailedAttemptsBeforeWaitIfNeeded;
// Schedule a check for completed copy operations if too many operations // Schedule a check for completed copy operations if too many operations
// are currently in-flight. // are currently in-flight.
ScheduleCheckForCompletedCopyOperationsWithLockAcquired(wait_if_needed); ScheduleCheckForCompletedCopyOperationsWithLockAcquired(wait_if_needed);
{ {
TRACE_EVENT0("cc", "WaitingForCopyOperationsToComplete"); TRACE_EVENT0("cc", "WaitingForCopyOperationsToComplete");
// Wait for in-flight copy operations to drop below limit. // Wait for in-flight copy operations to drop below limit.
copy_operation_count_cv_.Wait(); copy_operation_count_cv_.Wait();
}
} }
}
// Increment |scheduled_copy_operation_count_| before releasing |lock_|. // Increment |scheduled_copy_operation_count_| before releasing |lock_|.
++scheduled_copy_operation_count_; ++scheduled_copy_operation_count_;
// There may be more work available, so wake up another worker thread. // There may be more work available, so wake up another worker thread.
copy_operation_count_cv_.Signal(); copy_operation_count_cv_.Signal();
{ {
base::AutoUnlock unlock(lock_); base::AutoUnlock unlock(lock_);
gfx::GpuMemoryBuffer* gpu_memory_buffer = gfx::GpuMemoryBuffer* gpu_memory_buffer = write_lock->GetGpuMemoryBuffer();
write_lock->GetGpuMemoryBuffer(); if (gpu_memory_buffer) {
if (gpu_memory_buffer) { RasterWorkerPool::PlaybackToMemory(gpu_memory_buffer->Map(),
RasterWorkerPool::PlaybackToMemory( src->format(),
gpu_memory_buffer->Map(), src->format(), src->size(), src->size(),
gpu_memory_buffer->GetStride(), raster_source, rect, scale); gpu_memory_buffer->GetStride(),
gpu_memory_buffer->Unmap(); raster_source,
} rect,
scale);
gpu_memory_buffer->Unmap();
} }
}
// Acquire a sequence number for this copy operation. pending_copy_operations_.push_back(
sequence = next_copy_operation_sequence_++; make_scoped_ptr(new CopyOperation(write_lock.Pass(), src.Pass(), dst)));
pending_copy_operations_.push_back( // Acquire a sequence number for this copy operation.
make_scoped_ptr(new CopyOperation(write_lock.Pass(), src.Pass(), dst))); CopySequenceNumber sequence = next_copy_operation_sequence_++;
}
// Post task that will advance last flushed copy operation to |sequence| // Post task that will advance last flushed copy operation to |sequence|
// if we have reached the flush period. // if we have reached the flush period.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment