Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(114)

Side by Side Diff: cc/raster_worker_pool.cc

Issue 12079028: cc: Fix RasterWorkerPool shutdown crash. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/raster_worker_pool.h ('k') | cc/tile_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 "cc/raster_worker_pool.h" 5 #include "cc/raster_worker_pool.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 rendering_stats_.totalDeferredImageDecodeTime; 68 rendering_stats_.totalDeferredImageDecodeTime;
69 thread_->rendering_stats_.totalDeferredImageDecodeCount += 69 thread_->rendering_stats_.totalDeferredImageDecodeCount +=
70 rendering_stats_.totalDeferredImageDecodeCount; 70 rendering_stats_.totalDeferredImageDecodeCount;
71 71
72 thread_->num_pending_tasks_--; 72 thread_->num_pending_tasks_--;
73 } 73 }
74 74
75 RasterWorkerPool::Thread::Thread(const std::string name) 75 RasterWorkerPool::Thread::Thread(const std::string name)
76 : base::Thread(name.c_str()), 76 : base::Thread(name.c_str()),
77 num_pending_tasks_(0) { 77 num_pending_tasks_(0) {
78 Start();
79 } 78 }
80 79
81 RasterWorkerPool::Thread::~Thread() { 80 RasterWorkerPool::Thread::~Thread() {
82 Stop(); 81 Stop();
82 DCHECK_EQ(num_pending_tasks_, 0);
83 } 83 }
84 84
85 void RasterWorkerPool::Thread::Init() { 85 void RasterWorkerPool::Thread::Init() {
86 #if defined(OS_ANDROID) 86 #if defined(OS_ANDROID)
87 // TODO(epenner): Move thread priorities to base. (crbug.com/170549) 87 // TODO(epenner): Move thread priorities to base. (crbug.com/170549)
88 int nice_value = 10; // Idle priority. 88 int nice_value = 10; // Idle priority.
89 setpriority(PRIO_PROCESS, base::PlatformThread::CurrentId(), nice_value); 89 setpriority(PRIO_PROCESS, base::PlatformThread::CurrentId(), nice_value);
90 #endif 90 #endif
91 } 91 }
92 92
93 RasterWorkerPool::RasterWorkerPool(size_t num_raster_threads) { 93 RasterWorkerPool::RasterWorkerPool(size_t num_raster_threads)
94 : is_running_(false),
95 raster_threads_need_sorting_(false) {
94 const std::string thread_name_prefix = kRasterThreadNamePrefix; 96 const std::string thread_name_prefix = kRasterThreadNamePrefix;
95 while (raster_threads_.size() < num_raster_threads) { 97 while (raster_threads_.size() < num_raster_threads) {
96 int thread_number = raster_threads_.size() + 1; 98 int thread_number = raster_threads_.size() + 1;
97 raster_threads_.push_back( 99 raster_threads_.push_back(
98 new Thread(thread_name_prefix + 100 new Thread(thread_name_prefix +
99 StringPrintf("Worker%d", thread_number).c_str())); 101 StringPrintf("Worker%d", thread_number).c_str()));
100 } 102 }
101 } 103 }
102 104
103 RasterWorkerPool::~RasterWorkerPool() { 105 RasterWorkerPool::~RasterWorkerPool() {
106 Stop();
104 STLDeleteElements(&raster_threads_); 107 STLDeleteElements(&raster_threads_);
105 } 108 }
106 109
110 bool RasterWorkerPool::Start() {
111 for (ThreadVector::iterator it = raster_threads_.begin();
112 it != raster_threads_.end(); it++) {
113 Thread* thread = *it;
114 if (!thread->Start())
115 return false;
116 }
117
118 is_running_ = true;
119 return true;
120 }
121
122 void RasterWorkerPool::Stop() {
123 if (!is_running_)
124 return;
125
126 for (ThreadVector::iterator it = raster_threads_.begin();
127 it != raster_threads_.end(); it++) {
128 Thread* thread = *it;
129 thread->Stop();
130 }
131
132 is_running_ = false;
133 }
134
107 bool RasterWorkerPool::IsBusy() { 135 bool RasterWorkerPool::IsBusy() {
136 DCHECK(is_running_);
137 SortRasterThreadsIfNeeded();
138
108 Thread* thread = raster_threads_.front(); 139 Thread* thread = raster_threads_.front();
109 return thread->num_pending_tasks() >= kNumPendingRasterTasksPerThread; 140 return thread->num_pending_tasks() >= kNumPendingRasterTasksPerThread;
110 } 141 }
111 142
112 void RasterWorkerPool::PostRasterTaskAndReply(PicturePileImpl* picture_pile, 143 void RasterWorkerPool::PostRasterTaskAndReply(PicturePileImpl* picture_pile,
113 uint8* buffer, 144 uint8* buffer,
114 const gfx::Rect& rect, 145 const gfx::Rect& rect,
115 float contents_scale, 146 float contents_scale,
116 const base::Closure& reply) { 147 const base::Closure& reply) {
148 CHECK(is_running_);
117 Thread::Task* task = CreateTask(); 149 Thread::Task* task = CreateTask();
118 150
119 scoped_refptr<PicturePileImpl> picture_pile_clone = 151 scoped_refptr<PicturePileImpl> picture_pile_clone =
120 picture_pile->GetCloneForDrawingOnThread(task->thread_); 152 picture_pile->GetCloneForDrawingOnThread(task->thread_);
121 153
122 task->thread_->message_loop_proxy()->PostTaskAndReply( 154 task->thread_->message_loop_proxy()->PostTaskAndReply(
123 FROM_HERE, 155 FROM_HERE,
124 base::Bind(&RunRasterTask, 156 base::Bind(&RunRasterTask,
125 base::Unretained(picture_pile_clone.get()), 157 base::Unretained(picture_pile_clone.get()),
126 buffer, 158 buffer,
127 rect, 159 rect,
128 contents_scale, 160 contents_scale,
129 &task->rendering_stats_), 161 &task->rendering_stats_),
130 base::Bind(&RasterWorkerPool::OnRasterTaskCompleted, 162 base::Bind(&RasterWorkerPool::OnRasterTaskCompleted,
131 base::Unretained(this), 163 base::Unretained(this),
132 base::Unretained(task), 164 base::Unretained(task),
133 picture_pile_clone, 165 picture_pile_clone,
134 reply)); 166 reply));
135 } 167 }
136 168
137 void RasterWorkerPool::PostImageDecodeTaskAndReply( 169 void RasterWorkerPool::PostImageDecodeTaskAndReply(
138 skia::LazyPixelRef* pixel_ref, 170 skia::LazyPixelRef* pixel_ref,
139 const base::Closure& reply) { 171 const base::Closure& reply) {
172 CHECK(is_running_);
140 Thread::Task* task = CreateTask(); 173 Thread::Task* task = CreateTask();
141 174
142 task->thread_->message_loop_proxy()->PostTaskAndReply( 175 task->thread_->message_loop_proxy()->PostTaskAndReply(
143 FROM_HERE, 176 FROM_HERE,
144 base::Bind(&RunImageDecodeTask, pixel_ref, &task->rendering_stats_), 177 base::Bind(&RunImageDecodeTask, pixel_ref, &task->rendering_stats_),
145 base::Bind(&RasterWorkerPool::OnTaskCompleted, 178 base::Bind(&RasterWorkerPool::OnTaskCompleted,
146 base::Unretained(this), 179 base::Unretained(this),
147 base::Unretained(task), 180 base::Unretained(task),
148 reply)); 181 reply));
149 } 182 }
(...skipping 15 matching lines...) Expand all
165 stats->totalDeferredImageDecodeTime += 198 stats->totalDeferredImageDecodeTime +=
166 thread->rendering_stats().totalDeferredImageDecodeTime; 199 thread->rendering_stats().totalDeferredImageDecodeTime;
167 } 200 }
168 } 201 }
169 202
170 RasterWorkerPool::Thread::Task* RasterWorkerPool::CreateTask() { 203 RasterWorkerPool::Thread::Task* RasterWorkerPool::CreateTask() {
171 Thread* thread = raster_threads_.front(); 204 Thread* thread = raster_threads_.front();
172 DCHECK(thread->num_pending_tasks() < kNumPendingRasterTasksPerThread); 205 DCHECK(thread->num_pending_tasks() < kNumPendingRasterTasksPerThread);
173 206
174 scoped_ptr<Thread::Task> task(new Thread::Task(thread)); 207 scoped_ptr<Thread::Task> task(new Thread::Task(thread));
175 std::sort(raster_threads_.begin(), raster_threads_.end(), 208 raster_threads_need_sorting_ = true;
176 PendingTaskComparator());
177 return task.release(); 209 return task.release();
178 } 210 }
179 211
180 void RasterWorkerPool::DestroyTask(Thread::Task* task) { 212 void RasterWorkerPool::DestroyTask(Thread::Task* task) {
181 delete task; 213 delete task;
182 std::sort(raster_threads_.begin(), raster_threads_.end(), 214 raster_threads_need_sorting_ = true;
183 PendingTaskComparator());
184 } 215 }
185 216
186 void RasterWorkerPool::OnTaskCompleted( 217 void RasterWorkerPool::OnTaskCompleted(
187 Thread::Task* task, const base::Closure& reply) { 218 Thread::Task* task, const base::Closure& reply) {
188 DestroyTask(task); 219 DestroyTask(task);
189 reply.Run(); 220 reply.Run();
190 } 221 }
191 222
192 void RasterWorkerPool::OnRasterTaskCompleted( 223 void RasterWorkerPool::OnRasterTaskCompleted(
193 Thread::Task* task, 224 Thread::Task* task,
194 scoped_refptr<PicturePileImpl> picture_pile, 225 scoped_refptr<PicturePileImpl> picture_pile,
195 const base::Closure& reply) { 226 const base::Closure& reply) {
196 OnTaskCompleted(task, reply); 227 OnTaskCompleted(task, reply);
197 } 228 }
198 229
230 void RasterWorkerPool::SortRasterThreadsIfNeeded() {
231 if (!raster_threads_need_sorting_)
nduca 2013/01/29 00:13:08 Out of curiosity, what does this do?
reveman 2013/01/29 02:49:54 Rather than having iterate over all threads both w
232 return;
233
234 std::sort(raster_threads_.begin(), raster_threads_.end(),
235 PendingTaskComparator());
236 raster_threads_need_sorting_ = false;
237 }
238
199 } // namespace cc 239 } // namespace cc
OLDNEW
« no previous file with comments | « cc/raster_worker_pool.h ('k') | cc/tile_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698