summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorreveman <reveman@chromium.org>2014-11-04 16:23:56 -0800
committerCommit bot <commit-bot@chromium.org>2014-11-05 00:24:11 +0000
commitd130dcddb4bced6c4058d8d2fd6560b41fc5103a (patch)
treedcc00d8f6f5cb6905374c0bddadf02f9b53ecc7a
parent2610ea15b9d6f97ab6fd399d67b2e13fb79fce56 (diff)
downloadchromium_src-d130dcddb4bced6c4058d8d2fd6560b41fc5103a.zip
chromium_src-d130dcddb4bced6c4058d8d2fd6560b41fc5103a.tar.gz
chromium_src-d130dcddb4bced6c4058d8d2fd6560b41fc5103a.tar.bz2
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}
-rw-r--r--cc/resources/one_copy_raster_worker_pool.cc83
1 files changed, 41 insertions, 42 deletions
diff --git a/cc/resources/one_copy_raster_worker_pool.cc b/cc/resources/one_copy_raster_worker_pool.cc
index a558bbd..a8b838e 100644
--- a/cc/resources/one_copy_raster_worker_pool.cc
+++ b/cc/resources/one_copy_raster_worker_pool.cc
@@ -275,61 +275,60 @@ OneCopyRasterWorkerPool::PlaybackAndScheduleCopyOnWorkerThread(
const RasterSource* raster_source,
const gfx::Rect& rect,
float scale) {
- CopySequenceNumber sequence;
+ base::AutoLock lock(lock_);
- {
- 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;
+ 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;
+ ++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 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(wait_if_needed);
+ // Schedule a check for completed copy operations if too many operations
+ // are currently in-flight.
+ ScheduleCheckForCompletedCopyOperationsWithLockAcquired(wait_if_needed);
- {
- TRACE_EVENT0("cc", "WaitingForCopyOperationsToComplete");
+ {
+ TRACE_EVENT0("cc", "WaitingForCopyOperationsToComplete");
- // Wait for in-flight copy operations to drop below limit.
- copy_operation_count_cv_.Wait();
- }
+ // Wait for in-flight copy operations to drop below limit.
+ copy_operation_count_cv_.Wait();
}
+ }
- // Increment |scheduled_copy_operation_count_| before releasing |lock_|.
- ++scheduled_copy_operation_count_;
+ // Increment |scheduled_copy_operation_count_| before releasing |lock_|.
+ ++scheduled_copy_operation_count_;
- // There may be more work available, so wake up another worker thread.
- copy_operation_count_cv_.Signal();
+ // There may be more work available, so wake up another worker thread.
+ copy_operation_count_cv_.Signal();
- {
- base::AutoUnlock unlock(lock_);
-
- gfx::GpuMemoryBuffer* gpu_memory_buffer =
- write_lock->GetGpuMemoryBuffer();
- if (gpu_memory_buffer) {
- RasterWorkerPool::PlaybackToMemory(
- gpu_memory_buffer->Map(), src->format(), src->size(),
- gpu_memory_buffer->GetStride(), raster_source, rect, scale);
- gpu_memory_buffer->Unmap();
- }
+ {
+ base::AutoUnlock unlock(lock_);
+
+ gfx::GpuMemoryBuffer* gpu_memory_buffer = write_lock->GetGpuMemoryBuffer();
+ if (gpu_memory_buffer) {
+ RasterWorkerPool::PlaybackToMemory(gpu_memory_buffer->Map(),
+ src->format(),
+ src->size(),
+ gpu_memory_buffer->GetStride(),
+ raster_source,
+ rect,
+ scale);
+ gpu_memory_buffer->Unmap();
}
+ }
- // Acquire a sequence number for this copy operation.
- sequence = next_copy_operation_sequence_++;
+ pending_copy_operations_.push_back(
+ make_scoped_ptr(new CopyOperation(write_lock.Pass(), src.Pass(), dst)));
- pending_copy_operations_.push_back(
- make_scoped_ptr(new CopyOperation(write_lock.Pass(), src.Pass(), dst)));
- }
+ // Acquire a sequence number for this copy operation.
+ CopySequenceNumber sequence = next_copy_operation_sequence_++;
// Post task that will advance last flushed copy operation to |sequence|
// if we have reached the flush period.