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

Side by Side Diff: base/task_scheduler/task_scheduler_impl.h

Issue 2834063002: Separate the create and start phases in TaskSchedulerImpl. (Closed)
Patch Set: self-review Created 3 years, 8 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 #ifndef BASE_TASK_SCHEDULER_TASK_SCHEDULER_IMPL_H_ 5 #ifndef BASE_TASK_SCHEDULER_TASK_SCHEDULER_IMPL_H_
6 #define BASE_TASK_SCHEDULER_TASK_SCHEDULER_IMPL_H_ 6 #define BASE_TASK_SCHEDULER_TASK_SCHEDULER_IMPL_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 20 matching lines...) Expand all
31 31
32 namespace base { 32 namespace base {
33 33
34 class HistogramBase; 34 class HistogramBase;
35 35
36 namespace internal { 36 namespace internal {
37 37
38 // Default TaskScheduler implementation. This class is thread-safe. 38 // Default TaskScheduler implementation. This class is thread-safe.
39 class BASE_EXPORT TaskSchedulerImpl : public TaskScheduler { 39 class BASE_EXPORT TaskSchedulerImpl : public TaskScheduler {
40 public: 40 public:
41 // Creates and returns an initialized TaskSchedulerImpl. CHECKs on failure. 41 explicit TaskSchedulerImpl(StringPiece name);
robliao 2017/04/24 22:32:19 Readd the comment for |name| for public consistenc
gab 2017/04/25 15:16:15 Also mention explicitly that it now must be starte
fdoray 2017/04/25 18:43:34 Done.
42 // |name| is used to label threads and histograms. It should identify the
43 // component that creates the TaskScheduler. |init_params| contains params to
44 // initialize worker pools.
45 static std::unique_ptr<TaskSchedulerImpl> Create(
46 StringPiece name,
47 const TaskScheduler::InitParams& init_params);
48
49 ~TaskSchedulerImpl() override; 42 ~TaskSchedulerImpl() override;
50 43
51 // TaskScheduler: 44 // TaskScheduler:
45 void Start(const TaskScheduler::InitParams& init_params) override;
52 void PostDelayedTaskWithTraits(const tracked_objects::Location& from_here, 46 void PostDelayedTaskWithTraits(const tracked_objects::Location& from_here,
53 const TaskTraits& traits, 47 const TaskTraits& traits,
54 OnceClosure task, 48 OnceClosure task,
55 TimeDelta delay) override; 49 TimeDelta delay) override;
56 scoped_refptr<TaskRunner> CreateTaskRunnerWithTraits( 50 scoped_refptr<TaskRunner> CreateTaskRunnerWithTraits(
57 const TaskTraits& traits) override; 51 const TaskTraits& traits) override;
58 scoped_refptr<SequencedTaskRunner> CreateSequencedTaskRunnerWithTraits( 52 scoped_refptr<SequencedTaskRunner> CreateSequencedTaskRunnerWithTraits(
59 const TaskTraits& traits) override; 53 const TaskTraits& traits) override;
60 scoped_refptr<SingleThreadTaskRunner> CreateSingleThreadTaskRunnerWithTraits( 54 scoped_refptr<SingleThreadTaskRunner> CreateSingleThreadTaskRunnerWithTraits(
61 const TaskTraits& traits) override; 55 const TaskTraits& traits) override;
62 #if defined(OS_WIN) 56 #if defined(OS_WIN)
63 scoped_refptr<SingleThreadTaskRunner> CreateCOMSTATaskRunnerWithTraits( 57 scoped_refptr<SingleThreadTaskRunner> CreateCOMSTATaskRunnerWithTraits(
64 const TaskTraits& traits) override; 58 const TaskTraits& traits) override;
65 #endif // defined(OS_WIN) 59 #endif // defined(OS_WIN)
66 std::vector<const HistogramBase*> GetHistograms() const override; 60 std::vector<const HistogramBase*> GetHistograms() const override;
67 int GetMaxConcurrentTasksWithTraitsDeprecated( 61 int GetMaxConcurrentTasksWithTraitsDeprecated(
68 const TaskTraits& traits) const override; 62 const TaskTraits& traits) const override;
69 void Shutdown() override; 63 void Shutdown() override;
70 void FlushForTesting() override; 64 void FlushForTesting() override;
71 void JoinForTesting() override; 65 void JoinForTesting() override;
72 66
73 private: 67 private:
74 explicit TaskSchedulerImpl(StringPiece name);
75
76 void Initialize(const TaskScheduler::InitParams& init_params);
77
78 // Returns the worker pool that runs Tasks with |traits|. 68 // Returns the worker pool that runs Tasks with |traits|.
79 SchedulerWorkerPoolImpl* GetWorkerPoolForTraits( 69 SchedulerWorkerPoolImpl* GetWorkerPoolForTraits(
80 const TaskTraits& traits) const; 70 const TaskTraits& traits) const;
81 71
82 // Callback invoked when a non-single-thread |sequence| isn't empty after a 72 // Callback invoked when a non-single-thread |sequence| isn't empty after a
83 // worker pops a Task from it. 73 // worker pops a Task from it.
84 void ReEnqueueSequenceCallback(scoped_refptr<Sequence> sequence); 74 void ReEnqueueSequenceCallback(scoped_refptr<Sequence> sequence);
85 75
86 const std::string name_; 76 const std::string name_;
87 Thread service_thread_; 77 Thread service_thread_;
(...skipping 14 matching lines...) Expand all
102 AtomicFlag join_for_testing_returned_; 92 AtomicFlag join_for_testing_returned_;
103 #endif 93 #endif
104 94
105 DISALLOW_COPY_AND_ASSIGN(TaskSchedulerImpl); 95 DISALLOW_COPY_AND_ASSIGN(TaskSchedulerImpl);
106 }; 96 };
107 97
108 } // namespace internal 98 } // namespace internal
109 } // namespace base 99 } // namespace base
110 100
111 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_IMPL_H_ 101 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698