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

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

Issue 2823103003: Introduce TaskRunner::RunsTasksInCurrentSequence() (Closed)
Patch Set: rebase & remove inline keyword Created 3 years, 7 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
« no previous file with comments | « base/task_runner.h ('k') | base/task_scheduler/scheduler_worker_pool_impl.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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/scheduler_single_thread_task_runner_manager.h" 5 #include "base/task_scheduler/scheduler_single_thread_task_runner_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 DCHECK_EQ(sequence, sequence_); 89 DCHECK_EQ(sequence, sequence_);
90 has_work_ = true; 90 has_work_ = true;
91 } 91 }
92 92
93 TimeDelta GetSleepTimeout() override { return TimeDelta::Max(); } 93 TimeDelta GetSleepTimeout() override { return TimeDelta::Max(); }
94 94
95 bool CanDetach(SchedulerWorker* worker) override { return false; } 95 bool CanDetach(SchedulerWorker* worker) override { return false; }
96 96
97 void OnDetach() override { NOTREACHED(); } 97 void OnDetach() override { NOTREACHED(); }
98 98
99 bool RunsTasksOnCurrentThread() { 99 bool RunsTasksInCurrentSequence() {
100 // We check the thread ref instead of the sequence for the benefit of COM 100 // We check the thread ref instead of the sequence for the benefit of COM
101 // callbacks which may execute without a sequence context. 101 // callbacks which may execute without a sequence context.
102 return thread_ref_checker_.IsCurrentThreadSameAsSetThread(); 102 return thread_ref_checker_.IsCurrentThreadSameAsSetThread();
103 } 103 }
104 104
105 void OnMainExit() override { 105 void OnMainExit() override {
106 // Move |sequence_| to |local_sequence| so that if we have the last 106 // Move |sequence_| to |local_sequence| so that if we have the last
107 // reference to the sequence we don't destroy it (and its tasks) within 107 // reference to the sequence we don't destroy it (and its tasks) within
108 // |sequence_lock_|. 108 // |sequence_lock_|.
109 scoped_refptr<Sequence> local_sequence; 109 scoped_refptr<Sequence> local_sequence;
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 return true; 272 return true;
273 } 273 }
274 274
275 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, 275 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here,
276 OnceClosure closure, 276 OnceClosure closure,
277 TimeDelta delay) override { 277 TimeDelta delay) override {
278 // Tasks are never nested within the task scheduler. 278 // Tasks are never nested within the task scheduler.
279 return PostDelayedTask(from_here, std::move(closure), delay); 279 return PostDelayedTask(from_here, std::move(closure), delay);
280 } 280 }
281 281
282 bool RunsTasksOnCurrentThread() const override { 282 bool RunsTasksInCurrentSequence() const override {
283 return GetDelegate()->RunsTasksOnCurrentThread(); 283 return GetDelegate()->RunsTasksInCurrentSequence();
284 } 284 }
285 285
286 private: 286 private:
287 ~SchedulerSingleThreadTaskRunner() override { 287 ~SchedulerSingleThreadTaskRunner() override {
288 // Note: This will crash if SchedulerSingleThreadTaskRunnerManager is 288 // Note: This will crash if SchedulerSingleThreadTaskRunnerManager is
289 // incorrectly destroyed first in tests (in production the TaskScheduler and 289 // incorrectly destroyed first in tests (in production the TaskScheduler and
290 // all of its state are intentionally leaked after 290 // all of its state are intentionally leaked after
291 // TaskScheduler::Shutdown(). See ~SchedulerSingleThreadTaskRunnerManager() 291 // TaskScheduler::Shutdown(). See ~SchedulerSingleThreadTaskRunnerManager()
292 // for more details. 292 // for more details.
293 outer_->UnregisterSchedulerWorker(worker_); 293 outer_->UnregisterSchedulerWorker(worker_);
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 }); 487 });
488 DCHECK(worker_iter != workers_.end()); 488 DCHECK(worker_iter != workers_.end());
489 worker_to_destroy = std::move(*worker_iter); 489 worker_to_destroy = std::move(*worker_iter);
490 workers_.erase(worker_iter); 490 workers_.erase(worker_iter);
491 } 491 }
492 worker_to_destroy->Cleanup(); 492 worker_to_destroy->Cleanup();
493 } 493 }
494 494
495 } // namespace internal 495 } // namespace internal
496 } // namespace base 496 } // namespace base
OLDNEW
« no previous file with comments | « base/task_runner.h ('k') | base/task_scheduler/scheduler_worker_pool_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698