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

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

Issue 2809163003: Always use TaskScheduler::InitParams to initialize a TaskScheduler. (Closed)
Patch Set: CR-gab-robliao-17-18 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 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 <vector> 10 #include <vector>
10 11
11 #include "base/atomicops.h" 12 #include "base/atomicops.h"
12 #include "base/base_export.h" 13 #include "base/base_export.h"
13 #include "base/logging.h" 14 #include "base/logging.h"
14 #include "base/macros.h" 15 #include "base/macros.h"
15 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
16 #include "base/task_scheduler/scheduler_lock.h" 17 #include "base/task_scheduler/scheduler_lock.h"
17 #include "base/task_scheduler/scheduler_worker_pool_params.h" 18 #include "base/threading/platform_thread.h"
18 #include "base/task_scheduler/task_scheduler.h"
19 #include "build/build_config.h" 19 #include "build/build_config.h"
20 20
21 namespace base { 21 namespace base {
22 22
23 class TaskTraits; 23 class TaskTraits;
24 class SingleThreadTaskRunner; 24 class SingleThreadTaskRunner;
25 25
26 namespace internal { 26 namespace internal {
27 27
28 class DelayedTaskManager; 28 class DelayedTaskManager;
29 class SchedulerWorker; 29 class SchedulerWorker;
30 class TaskTracker; 30 class TaskTracker;
31 31
32 namespace { 32 namespace {
33 33
34 class SchedulerWorkerDelegate; 34 class SchedulerWorkerDelegate;
35 35
36 } // namespace 36 } // namespace
37 37
38 // Manages a pool of SchedulerWorkers associated with SingleThreadTaskRunners. 38 // Manages a pool of SchedulerWorkers associated with SingleThreadTaskRunners.
39 // 39 //
40 // No threads are created (and hence no tasks can run) before Start() is called. 40 // No threads are created (and hence no tasks can run) before Start() is called.
41 // 41 //
42 // This class is thread-safe. 42 // This class is thread-safe.
43 class BASE_EXPORT SchedulerSingleThreadTaskRunnerManager final { 43 class BASE_EXPORT SchedulerSingleThreadTaskRunnerManager final {
44 public: 44 public:
45 SchedulerSingleThreadTaskRunnerManager( 45 SchedulerSingleThreadTaskRunnerManager(
46 const std::vector<SchedulerWorkerPoolParams>& worker_pool_params_vector,
47 const TaskScheduler::WorkerPoolIndexForTraitsCallback&
48 worker_pool_index_for_traits_callback,
49 TaskTracker* task_tracker, 46 TaskTracker* task_tracker,
50 DelayedTaskManager* delayed_task_manager); 47 DelayedTaskManager* delayed_task_manager);
51 ~SchedulerSingleThreadTaskRunnerManager(); 48 ~SchedulerSingleThreadTaskRunnerManager();
52 49
53 // Starts threads for existing SingleThreadTaskRunners and allows threads to 50 // Starts threads for existing SingleThreadTaskRunners and allows threads to
54 // be started when SingleThreadTaskRunners are created in the future. 51 // be started when SingleThreadTaskRunners are created in the future.
55 void Start(); 52 void Start();
56 53
54 // Creates a SingleThreadTaskRunner which runs tasks with |traits| on a
55 // dedicated thread named "TaskSchedulerSingleThread" + |name| + index.
56 // |priority_hint| is the preferred thread priority; the actual thread
57 // priority depends on shutdown state and platform capabilities.
57 scoped_refptr<SingleThreadTaskRunner> CreateSingleThreadTaskRunnerWithTraits( 58 scoped_refptr<SingleThreadTaskRunner> CreateSingleThreadTaskRunnerWithTraits(
59 const std::string& name,
60 ThreadPriority priority_hint,
58 const TaskTraits& traits); 61 const TaskTraits& traits);
59 62
60 #if defined(OS_WIN) 63 #if defined(OS_WIN)
64 // Creates a SingleThreadTaskRunner which runs tasks with |traits| on a
65 // dedicated COM STA thread named "TaskSchedulerSingleThreadCOMSTA" + |name| +
66 // index. |priority_hint| is the preferred thread priority; the actual thread
67 // priority depends on shutdown state and platform capabilities.
61 scoped_refptr<SingleThreadTaskRunner> CreateCOMSTATaskRunnerWithTraits( 68 scoped_refptr<SingleThreadTaskRunner> CreateCOMSTATaskRunnerWithTraits(
69 const std::string& name,
70 ThreadPriority priority_hint,
62 const TaskTraits& traits); 71 const TaskTraits& traits);
63 #endif // defined(OS_WIN) 72 #endif // defined(OS_WIN)
64 73
65 void JoinForTesting(); 74 void JoinForTesting();
66 75
67 private: 76 private:
68 class SchedulerSingleThreadTaskRunner; 77 class SchedulerSingleThreadTaskRunner;
69 78
70 template <typename DelegateType> 79 template <typename DelegateType>
71 scoped_refptr<SingleThreadTaskRunner> 80 scoped_refptr<SingleThreadTaskRunner>
72 CreateSingleThreadTaskRunnerWithDelegate(const TaskTraits& traits); 81 CreateSingleThreadTaskRunnerWithDelegate(const std::string& name,
82 ThreadPriority priority_hint,
83 const TaskTraits& traits);
73 84
74 template <typename DelegateType> 85 template <typename DelegateType>
75 std::unique_ptr<SchedulerWorkerDelegate> CreateSchedulerWorkerDelegate( 86 std::unique_ptr<SchedulerWorkerDelegate> CreateSchedulerWorkerDelegate(
76 const SchedulerWorkerPoolParams& params, 87 const std::string& name,
77 int id); 88 int id);
78 89
79 template <typename DelegateType> 90 template <typename DelegateType>
80 SchedulerWorker* CreateAndRegisterSchedulerWorker( 91 SchedulerWorker* CreateAndRegisterSchedulerWorker(
81 const SchedulerWorkerPoolParams& params); 92 const std::string& name,
93 ThreadPriority priority_hint);
82 94
83 void UnregisterSchedulerWorker(SchedulerWorker* worker); 95 void UnregisterSchedulerWorker(SchedulerWorker* worker);
84 96
85 const std::vector<SchedulerWorkerPoolParams> worker_pool_params_vector_;
86 const TaskScheduler::WorkerPoolIndexForTraitsCallback
87 worker_pool_index_for_traits_callback_;
88 TaskTracker* const task_tracker_; 97 TaskTracker* const task_tracker_;
89 DelayedTaskManager* const delayed_task_manager_; 98 DelayedTaskManager* const delayed_task_manager_;
90 99
91 // Synchronizes access to |workers_|, |next_worker_id_| and |started_|. 100 // Synchronizes access to |workers_|, |next_worker_id_| and |started_|.
92 SchedulerLock lock_; 101 SchedulerLock lock_;
93 std::vector<scoped_refptr<SchedulerWorker>> workers_; 102 std::vector<scoped_refptr<SchedulerWorker>> workers_;
94 int next_worker_id_ = 0; 103 int next_worker_id_ = 0;
95 104
96 // Set to true when Start() is called. 105 // Set to true when Start() is called.
97 bool started_ = false; 106 bool started_ = false;
98 107
99 #if DCHECK_IS_ON() 108 #if DCHECK_IS_ON()
100 subtle::Atomic32 workers_unregistered_during_join_ = 0; 109 subtle::Atomic32 workers_unregistered_during_join_ = 0;
101 #endif 110 #endif
102 111
103 DISALLOW_COPY_AND_ASSIGN(SchedulerSingleThreadTaskRunnerManager); 112 DISALLOW_COPY_AND_ASSIGN(SchedulerSingleThreadTaskRunnerManager);
104 }; 113 };
105 114
106 } // namespace internal 115 } // namespace internal
107 } // namespace base 116 } // namespace base
108 117
109 #endif // BASE_TASK_SCHEDULER_SCHEDULER_SINGLE_THREAD_TASK_RUNNER_MANAGER_H_ 118 #endif // BASE_TASK_SCHEDULER_SCHEDULER_SINGLE_THREAD_TASK_RUNNER_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698