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

Side by Side Diff: base/task_scheduler/task_tracker.cc

Issue 2427963002: Support FileDescriptorWatcher in TaskScheduler. (Closed)
Patch Set: CR robliao #23 Created 4 years, 2 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "base/task_scheduler/task_tracker.h" 5 #include "base/task_scheduler/task_tracker.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/debug/task_annotator.h" 10 #include "base/debug/task_annotator.h"
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 } 206 }
207 207
208 bool TaskTracker::RunTask(std::unique_ptr<Task> task, 208 bool TaskTracker::RunTask(std::unique_ptr<Task> task,
209 const SequenceToken& sequence_token) { 209 const SequenceToken& sequence_token) {
210 DCHECK(task); 210 DCHECK(task);
211 DCHECK(sequence_token.IsValid()); 211 DCHECK(sequence_token.IsValid());
212 212
213 const TaskShutdownBehavior shutdown_behavior = 213 const TaskShutdownBehavior shutdown_behavior =
214 task->traits.shutdown_behavior(); 214 task->traits.shutdown_behavior();
215 const bool can_run_task = BeforeRunTask(shutdown_behavior); 215 const bool can_run_task = BeforeRunTask(shutdown_behavior);
216 const bool is_delayed = !task->delayed_run_time.is_null();
216 217
217 if (can_run_task) { 218 if (can_run_task) {
218 // All tasks run through here and the scheduler itself doesn't use 219 // All tasks run through here and the scheduler itself doesn't use
219 // singletons. Therefore, it isn't necessary to reset the singleton allowed 220 // singletons. Therefore, it isn't necessary to reset the singleton allowed
220 // bit after running the task. 221 // bit after running the task.
221 ThreadRestrictions::SetSingletonAllowed( 222 ThreadRestrictions::SetSingletonAllowed(
222 task->traits.shutdown_behavior() != 223 task->traits.shutdown_behavior() !=
223 TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN); 224 TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN);
224 225
225 { 226 {
(...skipping 21 matching lines...) Expand all
247 ? ExecutionMode::SINGLE_THREADED 248 ? ExecutionMode::SINGLE_THREADED
248 : (task->sequenced_task_runner_ref ? ExecutionMode::SEQUENCED 249 : (task->sequenced_task_runner_ref ? ExecutionMode::SEQUENCED
249 : ExecutionMode::PARALLEL); 250 : ExecutionMode::PARALLEL);
250 // TODO(gab): In a better world this would be tacked on as an extra arg 251 // TODO(gab): In a better world this would be tacked on as an extra arg
251 // to the trace event generated above. This is not possible however until 252 // to the trace event generated above. This is not possible however until
252 // http://crbug.com/652692 is resolved. 253 // http://crbug.com/652692 is resolved.
253 TRACE_EVENT1("task_scheduler", "TaskTracker::RunTask", "task_info", 254 TRACE_EVENT1("task_scheduler", "TaskTracker::RunTask", "task_info",
254 MakeUnique<TaskTracingInfo>(task->traits, execution_mode, 255 MakeUnique<TaskTracingInfo>(task->traits, execution_mode,
255 sequence_token)); 256 sequence_token));
256 257
257 debug::TaskAnnotator task_annotator; 258 PerformRunTask(std::move(task));
258 task_annotator.RunTask(kQueueFunctionName, task.get());
259 } 259 }
260 260
261 AfterRunTask(shutdown_behavior); 261 AfterRunTask(shutdown_behavior);
262 } 262 }
263 263
264 if (task->delayed_run_time.is_null()) 264 if (!is_delayed)
265 DecrementNumPendingUndelayedTasks(); 265 DecrementNumPendingUndelayedTasks();
266 266
267 return can_run_task; 267 return can_run_task;
268 } 268 }
269 269
270 bool TaskTracker::HasShutdownStarted() const { 270 bool TaskTracker::HasShutdownStarted() const {
271 return state_->HasShutdownStarted(); 271 return state_->HasShutdownStarted();
272 } 272 }
273 273
274 bool TaskTracker::IsShutdownComplete() const { 274 bool TaskTracker::IsShutdownComplete() const {
275 AutoSchedulerLock auto_lock(shutdown_lock_); 275 AutoSchedulerLock auto_lock(shutdown_lock_);
276 return shutdown_event_ && shutdown_event_->IsSignaled(); 276 return shutdown_event_ && shutdown_event_->IsSignaled();
277 } 277 }
278 278
279 void TaskTracker::SetHasShutdownStartedForTesting() { 279 void TaskTracker::SetHasShutdownStartedForTesting() {
280 state_->StartShutdown(); 280 state_->StartShutdown();
281 } 281 }
282 282
283 void TaskTracker::PerformRunTask(std::unique_ptr<Task> task) {
284 debug::TaskAnnotator().RunTask(kQueueFunctionName, task.get());
gab 2016/10/21 16:10:48 Actually this makes me realize that I'm not sure i
fdoray 2016/10/27 13:06:50 Yes, it's wrong to initialize a TaskAnnotator ever
285 }
286
283 void TaskTracker::PerformShutdown() { 287 void TaskTracker::PerformShutdown() {
284 { 288 {
285 AutoSchedulerLock auto_lock(shutdown_lock_); 289 AutoSchedulerLock auto_lock(shutdown_lock_);
286 290
287 // This method can only be called once. 291 // This method can only be called once.
288 DCHECK(!shutdown_event_); 292 DCHECK(!shutdown_event_);
289 DCHECK(!num_block_shutdown_tasks_posted_during_shutdown_); 293 DCHECK(!num_block_shutdown_tasks_posted_during_shutdown_);
290 DCHECK(!state_->HasShutdownStarted()); 294 DCHECK(!state_->HasShutdownStarted());
291 295
292 shutdown_event_.reset( 296 shutdown_event_.reset(
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 subtle::NoBarrier_AtomicIncrement(&num_pending_undelayed_tasks_, -1); 439 subtle::NoBarrier_AtomicIncrement(&num_pending_undelayed_tasks_, -1);
436 DCHECK_GE(new_num_pending_undelayed_tasks, 0); 440 DCHECK_GE(new_num_pending_undelayed_tasks, 0);
437 if (new_num_pending_undelayed_tasks == 0) { 441 if (new_num_pending_undelayed_tasks == 0) {
438 AutoSchedulerLock auto_lock(flush_lock_); 442 AutoSchedulerLock auto_lock(flush_lock_);
439 flush_cv_->Signal(); 443 flush_cv_->Signal();
440 } 444 }
441 } 445 }
442 446
443 } // namespace internal 447 } // namespace internal
444 } // namespace base 448 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698