OLD | NEW |
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 #ifndef BASE_TASK_SCHEDULER_SCHEDULER_SINGLE_THREAD_TASK_RUNNER_MANAGER_H_ | 5 #ifndef BASE_TASK_SCHEDULER_SCHEDULER_SINGLE_THREAD_TASK_RUNNER_MANAGER_H_ |
6 #define BASE_TASK_SCHEDULER_SCHEDULER_SINGLE_THREAD_TASK_RUNNER_MANAGER_H_ | 6 #define BASE_TASK_SCHEDULER_SCHEDULER_SINGLE_THREAD_TASK_RUNNER_MANAGER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 22 matching lines...) Expand all Loading... |
33 | 33 |
34 namespace { | 34 namespace { |
35 | 35 |
36 class SchedulerWorkerDelegate; | 36 class SchedulerWorkerDelegate; |
37 | 37 |
38 } // namespace | 38 } // namespace |
39 | 39 |
40 // Manages a pool of threads which are each associated with one or more | 40 // Manages a pool of threads which are each associated with one or more |
41 // SingleThreadTaskRunners. | 41 // SingleThreadTaskRunners. |
42 // | 42 // |
43 // SingleThreadTaskRunners using SingleThreadTaskRunnerThreadMode::SHARED, are | 43 // SingleThreadTaskRunners using SingleThreadTaskRunnerThreadMode::SHARED are |
44 // backed by shared SchedulerWorkers for each COM+task environment combination. | 44 // backed by shared SchedulerWorkers for each COM+task environment combination. |
45 // These workers are only reclaimed during JoinForTesting(). | 45 // These workers are lazily instantiated and then only reclaimed during |
| 46 // JoinForTesting() |
46 // | 47 // |
47 // No threads are created (and hence no tasks can run) before Start() is called. | 48 // No threads are created (and hence no tasks can run) before Start() is called. |
48 // | 49 // |
49 // This class is thread-safe. | 50 // This class is thread-safe. |
50 class BASE_EXPORT SchedulerSingleThreadTaskRunnerManager final { | 51 class BASE_EXPORT SchedulerSingleThreadTaskRunnerManager final { |
51 public: | 52 public: |
52 SchedulerSingleThreadTaskRunnerManager( | 53 SchedulerSingleThreadTaskRunnerManager( |
53 TaskTracker* task_tracker, | 54 TaskTracker* task_tracker, |
54 DelayedTaskManager* delayed_task_manager); | 55 DelayedTaskManager* delayed_task_manager); |
55 ~SchedulerSingleThreadTaskRunnerManager(); | 56 ~SchedulerSingleThreadTaskRunnerManager(); |
56 | 57 |
57 // Starts threads for existing SingleThreadTaskRunners and allows threads to | 58 // Starts threads for existing SingleThreadTaskRunners and allows threads to |
58 // be started when SingleThreadTaskRunners are created in the future. | 59 // be started when SingleThreadTaskRunners are created in the future. |
59 void Start(); | 60 void Start(); |
60 | 61 |
61 // Creates a SingleThreadTaskRunner which runs tasks with |traits| on a thread | 62 // Creates a SingleThreadTaskRunner which runs tasks with |traits| on a thread |
62 // named "TaskSchedulerSingleThread[Shared]" + |name| + | 63 // named "TaskSchedulerSingleThread[Shared]" + |name| + |
63 // kEnvironmentParams[GetEnvironmentIndexForTraits(traits)].name_suffix + | 64 // kEnvironmentParams[GetEnvironmentIndexForTraits(traits)].name_suffix + |
64 // index. "Shared" will be in the thread name when |thread_mode| is SHARED. If | 65 // index. |
65 // |thread_mode| is DEDICATED, a thread will be dedicated to the returned task | |
66 // runner, otherwise it could be shared with other SingleThreadTaskRunners. | |
67 scoped_refptr<SingleThreadTaskRunner> CreateSingleThreadTaskRunnerWithTraits( | 66 scoped_refptr<SingleThreadTaskRunner> CreateSingleThreadTaskRunnerWithTraits( |
68 const std::string& name, | 67 const std::string& name, |
69 const TaskTraits& traits, | 68 const TaskTraits& traits, |
70 SingleThreadTaskRunnerThreadMode thread_mode); | 69 SingleThreadTaskRunnerThreadMode thread_mode); |
71 | 70 |
72 #if defined(OS_WIN) | 71 #if defined(OS_WIN) |
73 // Creates a SingleThreadTaskRunner which runs tasks with |traits| on a COM | 72 // Creates a SingleThreadTaskRunner which runs tasks with |traits| on a COM |
74 // STA thread named "TaskSchedulerSingleThreadCOMSTA[Shared]" + |name| + | 73 // STA thread named "TaskSchedulerSingleThreadCOMSTA[Shared]" + |name| + |
75 // kEnvironmentParams[GetEnvironmentIndexForTraits(traits)].name_suffix + | 74 // kEnvironmentParams[GetEnvironmentIndexForTraits(traits)].name_suffix + |
76 // index. "Shared" will be in the thread name when |thread_mode| is SHARED. If | 75 // index. |
77 // |thread_mode| is DEDICATED, a thread will be dedicated to the returned task | |
78 // runner, otherwise it could be shared with other SingleThreadTaskRunners. | |
79 scoped_refptr<SingleThreadTaskRunner> CreateCOMSTATaskRunnerWithTraits( | 76 scoped_refptr<SingleThreadTaskRunner> CreateCOMSTATaskRunnerWithTraits( |
80 const std::string& name, | 77 const std::string& name, |
81 const TaskTraits& traits, | 78 const TaskTraits& traits, |
82 SingleThreadTaskRunnerThreadMode thread_mode); | 79 SingleThreadTaskRunnerThreadMode thread_mode); |
83 #endif // defined(OS_WIN) | 80 #endif // defined(OS_WIN) |
84 | 81 |
85 void JoinForTesting(); | 82 void JoinForTesting(); |
86 | 83 |
87 private: | 84 private: |
88 class SchedulerSingleThreadTaskRunner; | 85 class SchedulerSingleThreadTaskRunner; |
(...skipping 26 matching lines...) Expand all Loading... |
115 | 112 |
116 #if DCHECK_IS_ON() | 113 #if DCHECK_IS_ON() |
117 subtle::Atomic32 workers_unregistered_during_join_ = 0; | 114 subtle::Atomic32 workers_unregistered_during_join_ = 0; |
118 #endif | 115 #endif |
119 | 116 |
120 // Synchronizes access to all members below. | 117 // Synchronizes access to all members below. |
121 SchedulerLock lock_; | 118 SchedulerLock lock_; |
122 std::vector<scoped_refptr<SchedulerWorker>> workers_; | 119 std::vector<scoped_refptr<SchedulerWorker>> workers_; |
123 int next_worker_id_ = 0; | 120 int next_worker_id_ = 0; |
124 | 121 |
125 SchedulerWorker* shared_scheduler_workers_[4]; | 122 SchedulerWorker* shared_scheduler_workers_[ENVIRONMENT_COUNT] = {}; |
126 | 123 |
127 #if defined(OS_WIN) | 124 #if defined(OS_WIN) |
128 SchedulerWorker* shared_com_scheduler_workers_[4]; | 125 SchedulerWorker* shared_com_scheduler_workers_[ENVIRONMENT_COUNT] = {}; |
129 #endif // defined(OS_WIN) | 126 #endif // defined(OS_WIN) |
130 | 127 |
131 // Set to true when Start() is called. | 128 // Set to true when Start() is called. |
132 bool started_ = false; | 129 bool started_ = false; |
133 | 130 |
134 DISALLOW_COPY_AND_ASSIGN(SchedulerSingleThreadTaskRunnerManager); | 131 DISALLOW_COPY_AND_ASSIGN(SchedulerSingleThreadTaskRunnerManager); |
135 }; | 132 }; |
136 | 133 |
137 } // namespace internal | 134 } // namespace internal |
138 } // namespace base | 135 } // namespace base |
139 | 136 |
140 #endif // BASE_TASK_SCHEDULER_SCHEDULER_SINGLE_THREAD_TASK_RUNNER_MANAGER_H_ | 137 #endif // BASE_TASK_SCHEDULER_SCHEDULER_SINGLE_THREAD_TASK_RUNNER_MANAGER_H_ |
OLD | NEW |