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

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

Issue 2340793002: TaskScheduler: Match behavior of SequencedWorkerPool in RunsTasksOnCurrentThread(). (Closed)
Patch Set: self-review (return --> returns) Created 4 years, 3 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 | « no previous file | base/task_scheduler/scheduler_worker_pool_impl_unittest.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 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/scheduler_worker_pool_impl.h" 5 #include "base/task_scheduler/scheduler_worker_pool_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/atomicops.h" 12 #include "base/atomicops.h"
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/bind_helpers.h" 14 #include "base/bind_helpers.h"
15 #include "base/lazy_instance.h" 15 #include "base/lazy_instance.h"
16 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
17 #include "base/metrics/histogram.h" 17 #include "base/metrics/histogram.h"
18 #include "base/sequence_token.h"
18 #include "base/sequenced_task_runner.h" 19 #include "base/sequenced_task_runner.h"
19 #include "base/single_thread_task_runner.h" 20 #include "base/single_thread_task_runner.h"
20 #include "base/strings/stringprintf.h" 21 #include "base/strings/stringprintf.h"
21 #include "base/task_scheduler/delayed_task_manager.h" 22 #include "base/task_scheduler/delayed_task_manager.h"
22 #include "base/task_scheduler/task_tracker.h" 23 #include "base/task_scheduler/task_tracker.h"
23 #include "base/threading/platform_thread.h" 24 #include "base/threading/platform_thread.h"
24 #include "base/threading/thread_local.h" 25 #include "base/threading/thread_local.h"
25 #include "base/threading/thread_restrictions.h" 26 #include "base/threading/thread_restrictions.h"
26 #include "base/time/time.h" 27 #include "base/time/time.h"
27 28
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 } 104 }
104 105
105 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, 106 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here,
106 const Closure& closure, 107 const Closure& closure,
107 base::TimeDelta delay) override { 108 base::TimeDelta delay) override {
108 // Tasks are never nested within the task scheduler. 109 // Tasks are never nested within the task scheduler.
109 return PostDelayedTask(from_here, closure, delay); 110 return PostDelayedTask(from_here, closure, delay);
110 } 111 }
111 112
112 bool RunsTasksOnCurrentThread() const override { 113 bool RunsTasksOnCurrentThread() const override {
113 return tls_current_worker_pool.Get().Get() == worker_pool_; 114 // TODO(fdoray): Rename TaskRunner::RunsTaskOnCurrentThread() to something
115 // that reflects this behavior more accurately. crbug.com/646905
116 return sequence_->token() == SequenceToken::GetForCurrentThread();
114 } 117 }
115 118
116 private: 119 private:
117 ~SchedulerSequencedTaskRunner() override = default; 120 ~SchedulerSequencedTaskRunner() override = default;
118 121
119 // Sequence for all Tasks posted through this TaskRunner. 122 // Sequence for all Tasks posted through this TaskRunner.
120 const scoped_refptr<Sequence> sequence_ = new Sequence; 123 const scoped_refptr<Sequence> sequence_ = new Sequence;
121 124
122 const TaskTraits traits_; 125 const TaskTraits traits_;
123 SchedulerWorkerPool* const worker_pool_; 126 SchedulerWorkerPool* const worker_pool_;
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 AutoSchedulerLock auto_lock(idle_workers_stack_lock_); 700 AutoSchedulerLock auto_lock(idle_workers_stack_lock_);
698 idle_workers_stack_.Remove(worker); 701 idle_workers_stack_.Remove(worker);
699 } 702 }
700 703
701 bool SchedulerWorkerPoolImpl::CanWorkerDetachForTesting() { 704 bool SchedulerWorkerPoolImpl::CanWorkerDetachForTesting() {
702 return !worker_detachment_disallowed_.IsSet(); 705 return !worker_detachment_disallowed_.IsSet();
703 } 706 }
704 707
705 } // namespace internal 708 } // namespace internal
706 } // namespace base 709 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/task_scheduler/scheduler_worker_pool_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698