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

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

Issue 2531663003: TaskScheduler: Add TaskTraits::WithWait(). (Closed)
Patch Set: CR danakj #14 (no TEST_P) Created 4 years 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 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 const bool can_run_task = BeforeRunTask(shutdown_behavior); 218 const bool can_run_task = BeforeRunTask(shutdown_behavior);
219 const bool is_delayed = !task->delayed_run_time.is_null(); 219 const bool is_delayed = !task->delayed_run_time.is_null();
220 220
221 if (can_run_task) { 221 if (can_run_task) {
222 const bool previous_singleton_allowed = 222 const bool previous_singleton_allowed =
223 ThreadRestrictions::SetSingletonAllowed( 223 ThreadRestrictions::SetSingletonAllowed(
224 task->traits.shutdown_behavior() != 224 task->traits.shutdown_behavior() !=
225 TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN); 225 TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN);
226 const bool previous_io_allowed = 226 const bool previous_io_allowed =
227 ThreadRestrictions::SetIOAllowed(task->traits.with_file_io()); 227 ThreadRestrictions::SetIOAllowed(task->traits.with_file_io());
228 const bool previous_wait_allowed =
229 ThreadRestrictions::SetWaitAllowed(task->traits.with_wait());
228 230
229 { 231 {
230 // Set up SequenceToken as expected for the scope of the task. 232 // Set up SequenceToken as expected for the scope of the task.
231 ScopedSetSequenceTokenForCurrentThread 233 ScopedSetSequenceTokenForCurrentThread
232 scoped_set_sequence_token_for_current_thread(sequence_token); 234 scoped_set_sequence_token_for_current_thread(sequence_token);
233 235
234 // Set up TaskRunnerHandle as expected for the scope of the task. 236 // Set up TaskRunnerHandle as expected for the scope of the task.
235 std::unique_ptr<SequencedTaskRunnerHandle> sequenced_task_runner_handle; 237 std::unique_ptr<SequencedTaskRunnerHandle> sequenced_task_runner_handle;
236 std::unique_ptr<ThreadTaskRunnerHandle> single_thread_task_runner_handle; 238 std::unique_ptr<ThreadTaskRunnerHandle> single_thread_task_runner_handle;
237 DCHECK(!task->sequenced_task_runner_ref || 239 DCHECK(!task->sequenced_task_runner_ref ||
(...skipping 16 matching lines...) Expand all
254 // TODO(gab): In a better world this would be tacked on as an extra arg 256 // TODO(gab): In a better world this would be tacked on as an extra arg
255 // to the trace event generated above. This is not possible however until 257 // to the trace event generated above. This is not possible however until
256 // http://crbug.com/652692 is resolved. 258 // http://crbug.com/652692 is resolved.
257 TRACE_EVENT1("task_scheduler", "TaskTracker::RunTask", "task_info", 259 TRACE_EVENT1("task_scheduler", "TaskTracker::RunTask", "task_info",
258 MakeUnique<TaskTracingInfo>(task->traits, execution_mode, 260 MakeUnique<TaskTracingInfo>(task->traits, execution_mode,
259 sequence_token)); 261 sequence_token));
260 262
261 PerformRunTask(std::move(task)); 263 PerformRunTask(std::move(task));
262 } 264 }
263 265
266 ThreadRestrictions::SetWaitAllowed(previous_wait_allowed);
267 ThreadRestrictions::SetIOAllowed(previous_io_allowed);
264 ThreadRestrictions::SetSingletonAllowed(previous_singleton_allowed); 268 ThreadRestrictions::SetSingletonAllowed(previous_singleton_allowed);
265 ThreadRestrictions::SetIOAllowed(previous_io_allowed);
266 269
267 AfterRunTask(shutdown_behavior); 270 AfterRunTask(shutdown_behavior);
268 } 271 }
269 272
270 if (!is_delayed) 273 if (!is_delayed)
271 DecrementNumPendingUndelayedTasks(); 274 DecrementNumPendingUndelayedTasks();
272 275
273 return can_run_task; 276 return can_run_task;
274 } 277 }
275 278
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 subtle::NoBarrier_AtomicIncrement(&num_pending_undelayed_tasks_, -1); 448 subtle::NoBarrier_AtomicIncrement(&num_pending_undelayed_tasks_, -1);
446 DCHECK_GE(new_num_pending_undelayed_tasks, 0); 449 DCHECK_GE(new_num_pending_undelayed_tasks, 0);
447 if (new_num_pending_undelayed_tasks == 0) { 450 if (new_num_pending_undelayed_tasks == 0) {
448 AutoSchedulerLock auto_lock(flush_lock_); 451 AutoSchedulerLock auto_lock(flush_lock_);
449 flush_cv_->Signal(); 452 flush_cv_->Signal();
450 } 453 }
451 } 454 }
452 455
453 } // namespace internal 456 } // namespace internal
454 } // namespace base 457 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698