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

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

Issue 2531883002: TaskScheduler: Set the IO allowed bit in TaskTracker::RunTask(). (Closed)
Patch Set: CR robliao #22 (reorder reset) 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 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 const SequenceToken& sequence_token) { 212 const SequenceToken& sequence_token) {
213 DCHECK(task); 213 DCHECK(task);
214 DCHECK(sequence_token.IsValid()); 214 DCHECK(sequence_token.IsValid());
215 215
216 const TaskShutdownBehavior shutdown_behavior = 216 const TaskShutdownBehavior shutdown_behavior =
217 task->traits.shutdown_behavior(); 217 task->traits.shutdown_behavior();
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 // All tasks run through here and the scheduler itself doesn't use 222 const bool previous_singleton_allowed =
danakj 2016/11/28 22:55:56 This comment is no less true now is it? So IOAllow
fdoray 2016/11/29 15:41:20 I decided to reset ThreadRestrictions in RunTask()
223 // singletons. Therefore, it isn't necessary to reset the singleton allowed 223 ThreadRestrictions::SetSingletonAllowed(
224 // bit after running the task. 224 task->traits.shutdown_behavior() !=
225 ThreadRestrictions::SetSingletonAllowed( 225 TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN);
226 task->traits.shutdown_behavior() != 226 const bool previous_io_allowed =
227 TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN); 227 ThreadRestrictions::SetIOAllowed(task->traits.with_file_io());
danakj 2016/11/28 22:55:56 Is reading and writing thread-local storage before
fdoray 2016/11/29 15:41:20 I don't think we need to optimize this since Threa
danakj 2016/12/01 21:59:04 The assert methods are no-ops. The setters are not
fdoray 2016/12/01 22:30:43 Yes they are. The whole implementation file is gua
228 228
229 { 229 {
230 // Set up SequenceToken as expected for the scope of the task. 230 // Set up SequenceToken as expected for the scope of the task.
231 ScopedSetSequenceTokenForCurrentThread 231 ScopedSetSequenceTokenForCurrentThread
232 scoped_set_sequence_token_for_current_thread(sequence_token); 232 scoped_set_sequence_token_for_current_thread(sequence_token);
233 233
234 // Set up TaskRunnerHandle as expected for the scope of the task. 234 // Set up TaskRunnerHandle as expected for the scope of the task.
235 std::unique_ptr<SequencedTaskRunnerHandle> sequenced_task_runner_handle; 235 std::unique_ptr<SequencedTaskRunnerHandle> sequenced_task_runner_handle;
236 std::unique_ptr<ThreadTaskRunnerHandle> single_thread_task_runner_handle; 236 std::unique_ptr<ThreadTaskRunnerHandle> single_thread_task_runner_handle;
237 DCHECK(!task->sequenced_task_runner_ref || 237 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 254 // 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 255 // to the trace event generated above. This is not possible however until
256 // http://crbug.com/652692 is resolved. 256 // http://crbug.com/652692 is resolved.
257 TRACE_EVENT1("task_scheduler", "TaskTracker::RunTask", "task_info", 257 TRACE_EVENT1("task_scheduler", "TaskTracker::RunTask", "task_info",
258 MakeUnique<TaskTracingInfo>(task->traits, execution_mode, 258 MakeUnique<TaskTracingInfo>(task->traits, execution_mode,
259 sequence_token)); 259 sequence_token));
260 260
261 PerformRunTask(std::move(task)); 261 PerformRunTask(std::move(task));
262 } 262 }
263 263
264 ThreadRestrictions::SetIOAllowed(previous_io_allowed);
265 ThreadRestrictions::SetSingletonAllowed(previous_singleton_allowed);
266
264 AfterRunTask(shutdown_behavior); 267 AfterRunTask(shutdown_behavior);
265 } 268 }
266 269
267 if (!is_delayed) 270 if (!is_delayed)
268 DecrementNumPendingUndelayedTasks(); 271 DecrementNumPendingUndelayedTasks();
269 272
270 return can_run_task; 273 return can_run_task;
271 } 274 }
272 275
273 bool TaskTracker::HasShutdownStarted() const { 276 bool TaskTracker::HasShutdownStarted() const {
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 subtle::NoBarrier_AtomicIncrement(&num_pending_undelayed_tasks_, -1); 445 subtle::NoBarrier_AtomicIncrement(&num_pending_undelayed_tasks_, -1);
443 DCHECK_GE(new_num_pending_undelayed_tasks, 0); 446 DCHECK_GE(new_num_pending_undelayed_tasks, 0);
444 if (new_num_pending_undelayed_tasks == 0) { 447 if (new_num_pending_undelayed_tasks == 0) {
445 AutoSchedulerLock auto_lock(flush_lock_); 448 AutoSchedulerLock auto_lock(flush_lock_);
446 flush_cv_->Signal(); 449 flush_cv_->Signal();
447 } 450 }
448 } 451 }
449 452
450 } // namespace internal 453 } // namespace internal
451 } // namespace base 454 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698