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

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

Issue 2077093002: Rename SchedulerWorkerThread* to SchedulerWorker* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@rename2
Patch Set: CR Feedback Created 4 years, 6 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_SCHEDULER_WORKER_POOL_IMPL_H_ 5 #ifndef BASE_TASK_SCHEDULER_SCHEDULER_WORKER_POOL_IMPL_H_
6 #define BASE_TASK_SCHEDULER_SCHEDULER_WORKER_POOL_IMPL_H_ 6 #define BASE_TASK_SCHEDULER_SCHEDULER_WORKER_POOL_IMPL_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <memory> 10 #include <memory>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/base_export.h" 14 #include "base/base_export.h"
15 #include "base/callback.h" 15 #include "base/callback.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/memory/ref_counted.h" 18 #include "base/memory/ref_counted.h"
19 #include "base/strings/string_piece.h" 19 #include "base/strings/string_piece.h"
20 #include "base/synchronization/condition_variable.h" 20 #include "base/synchronization/condition_variable.h"
21 #include "base/task_runner.h" 21 #include "base/task_runner.h"
22 #include "base/task_scheduler/priority_queue.h" 22 #include "base/task_scheduler/priority_queue.h"
23 #include "base/task_scheduler/scheduler_lock.h" 23 #include "base/task_scheduler/scheduler_lock.h"
24 #include "base/task_scheduler/scheduler_worker.h"
24 #include "base/task_scheduler/scheduler_worker_pool.h" 25 #include "base/task_scheduler/scheduler_worker_pool.h"
25 #include "base/task_scheduler/scheduler_worker_thread.h" 26 #include "base/task_scheduler/scheduler_worker_stack.h"
26 #include "base/task_scheduler/scheduler_worker_thread_stack.h"
27 #include "base/task_scheduler/sequence.h" 27 #include "base/task_scheduler/sequence.h"
28 #include "base/task_scheduler/task.h" 28 #include "base/task_scheduler/task.h"
29 #include "base/task_scheduler/task_traits.h" 29 #include "base/task_scheduler/task_traits.h"
30 #include "base/threading/platform_thread.h" 30 #include "base/threading/platform_thread.h"
31 31
32 namespace base { 32 namespace base {
33 namespace internal { 33 namespace internal {
34 34
35 class DelayedTaskManager; 35 class DelayedTaskManager;
36 class TaskTracker; 36 class TaskTracker;
(...skipping 26 matching lines...) Expand all
63 static std::unique_ptr<SchedulerWorkerPoolImpl> Create( 63 static std::unique_ptr<SchedulerWorkerPoolImpl> Create(
64 StringPiece name, 64 StringPiece name,
65 ThreadPriority thread_priority, 65 ThreadPriority thread_priority,
66 size_t max_threads, 66 size_t max_threads,
67 IORestriction io_restriction, 67 IORestriction io_restriction,
68 const ReEnqueueSequenceCallback& re_enqueue_sequence_callback, 68 const ReEnqueueSequenceCallback& re_enqueue_sequence_callback,
69 TaskTracker* task_tracker, 69 TaskTracker* task_tracker,
70 DelayedTaskManager* delayed_task_manager); 70 DelayedTaskManager* delayed_task_manager);
71 71
72 // Waits until all workers are idle. 72 // Waits until all workers are idle.
73 void WaitForAllWorkerWorkersIdleForTesting(); 73 void WaitForAllWorkersIdleForTesting();
74 74
75 // Joins all workers of this worker pool. Tasks that are already running are 75 // Joins all workers of this worker pool. Tasks that are already running are
76 // allowed to complete their execution. This can only be called once. 76 // allowed to complete their execution. This can only be called once.
77 void JoinForTesting(); 77 void JoinForTesting();
78 78
79 // SchedulerWorkerPool: 79 // SchedulerWorkerPool:
80 scoped_refptr<TaskRunner> CreateTaskRunnerWithTraits( 80 scoped_refptr<TaskRunner> CreateTaskRunnerWithTraits(
81 const TaskTraits& traits, 81 const TaskTraits& traits,
82 ExecutionMode execution_mode) override; 82 ExecutionMode execution_mode) override;
83 void ReEnqueueSequence(scoped_refptr<Sequence> sequence, 83 void ReEnqueueSequence(scoped_refptr<Sequence> sequence,
84 const SequenceSortKey& sequence_sort_key) override; 84 const SequenceSortKey& sequence_sort_key) override;
85 bool PostTaskWithSequence(std::unique_ptr<Task> task, 85 bool PostTaskWithSequence(std::unique_ptr<Task> task,
86 scoped_refptr<Sequence> sequence, 86 scoped_refptr<Sequence> sequence,
87 SchedulerWorkerThread* worker_thread) override; 87 SchedulerWorker* worker) override;
88 void PostTaskWithSequenceNow(std::unique_ptr<Task> task, 88 void PostTaskWithSequenceNow(std::unique_ptr<Task> task,
89 scoped_refptr<Sequence> sequence, 89 scoped_refptr<Sequence> sequence,
90 SchedulerWorkerThread* worker_thread) override; 90 SchedulerWorker* worker) override;
91 91
92 private: 92 private:
93 class SchedulerWorkerThreadDelegateImpl; 93 class SchedulerWorkerDelegateImpl;
94 94
95 SchedulerWorkerPoolImpl(StringPiece name, 95 SchedulerWorkerPoolImpl(StringPiece name,
96 IORestriction io_restriction, 96 IORestriction io_restriction,
97 TaskTracker* task_tracker, 97 TaskTracker* task_tracker,
98 DelayedTaskManager* delayed_task_manager); 98 DelayedTaskManager* delayed_task_manager);
99 99
100 bool Initialize( 100 bool Initialize(
101 ThreadPriority thread_priority, 101 ThreadPriority thread_priority,
102 size_t max_threads, 102 size_t max_threads,
103 const ReEnqueueSequenceCallback& re_enqueue_sequence_callback); 103 const ReEnqueueSequenceCallback& re_enqueue_sequence_callback);
104 104
105 // Wakes up the last worker from this worker pool to go idle, if any. 105 // Wakes up the last worker from this worker pool to go idle, if any.
106 void WakeUpOneWorker(); 106 void WakeUpOneWorker();
107 107
108 // Adds |worker_thread| to |idle_worker_threads_stack_|. 108 // Adds |worker| to |idle_workers_stack_|.
109 void AddToIdleWorkerThreadsStack(SchedulerWorkerThread* worker_thread); 109 void AddToIdleWorkersStack(SchedulerWorker* worker);
110 110
111 // Removes |worker_thread| from |idle_worker_threads_stack_|. 111 // Removes |worker| from |idle_workers_stack_|.
112 void RemoveFromIdleWorkerThreadsStack(SchedulerWorkerThread* worker_thread); 112 void RemoveFromIdleWorkersStack(SchedulerWorker* worker);
113 113
114 // The name of this worker pool, used to label its worker threads. 114 // The name of this worker pool, used to label its worker threads.
115 const std::string name_; 115 const std::string name_;
116 116
117 // All worker threads owned by this worker pool. Only modified during 117 // All worker owned by this worker pool. Only modified during initialization
118 // initialization of the worker pool. 118 // of the worker pool.
119 std::vector<std::unique_ptr<SchedulerWorkerThread>> worker_threads_; 119 std::vector<std::unique_ptr<SchedulerWorker>> workers_;
120 120
121 // Synchronizes access to |next_worker_thread_index_|. 121 // Synchronizes access to |next_worker_index_|.
122 SchedulerLock next_worker_thread_index_lock_; 122 SchedulerLock next_worker_index_lock_;
123 123
124 // Index of the worker thread that will be assigned to the next single- 124 // Index of the worker that will be assigned to the next single-threaded
125 // threaded TaskRunner returned by this pool. 125 // TaskRunner returned by this pool.
126 size_t next_worker_thread_index_ = 0; 126 size_t next_worker_index_ = 0;
127 127
128 // PriorityQueue from which all threads of this worker pool get work. 128 // PriorityQueue from which all threads of this worker pool get work.
129 PriorityQueue shared_priority_queue_; 129 PriorityQueue shared_priority_queue_;
130 130
131 // Indicates whether Tasks on this worker pool are allowed to make I/O calls. 131 // Indicates whether Tasks on this worker pool are allowed to make I/O calls.
132 const IORestriction io_restriction_; 132 const IORestriction io_restriction_;
133 133
134 // Synchronizes access to |idle_worker_threads_stack_| and 134 // Synchronizes access to |idle_workers_stack_| and
135 // |idle_worker_threads_stack_cv_for_testing_|. Has |shared_priority_queue_|'s 135 // |idle_workers_stack_cv_for_testing_|. Has |shared_priority_queue_|'s
136 // lock as its predecessor so that a thread can be pushed to 136 // lock as its predecessor so that a worker can be pushed to
137 // |idle_worker_threads_stack_| within the scope of a Transaction (more 137 // |idle_workers_stack_| within the scope of a Transaction (more
138 // details in GetWork()). 138 // details in GetWork()).
139 SchedulerLock idle_worker_threads_stack_lock_; 139 SchedulerLock idle_workers_stack_lock_;
140 140
141 // Stack of idle worker threads. 141 // Stack of idle workers.
142 SchedulerWorkerThreadStack idle_worker_threads_stack_; 142 SchedulerWorkerStack idle_workers_stack_;
143 143
144 // Signaled when all worker threads become idle. 144 // Signaled when all workers become idle.
145 std::unique_ptr<ConditionVariable> idle_worker_threads_stack_cv_for_testing_; 145 std::unique_ptr<ConditionVariable> idle_workers_stack_cv_for_testing_;
146 146
147 // Signaled once JoinForTesting() has returned. 147 // Signaled once JoinForTesting() has returned.
148 WaitableEvent join_for_testing_returned_; 148 WaitableEvent join_for_testing_returned_;
149 149
150 #if DCHECK_IS_ON() 150 #if DCHECK_IS_ON()
151 // Signaled when all threads have been created. 151 // Signaled when all workers have been created.
152 WaitableEvent threads_created_; 152 WaitableEvent workers_created_;
153 #endif 153 #endif
154 154
155 TaskTracker* const task_tracker_; 155 TaskTracker* const task_tracker_;
156 DelayedTaskManager* const delayed_task_manager_; 156 DelayedTaskManager* const delayed_task_manager_;
157 157
158 DISALLOW_COPY_AND_ASSIGN(SchedulerWorkerPoolImpl); 158 DISALLOW_COPY_AND_ASSIGN(SchedulerWorkerPoolImpl);
159 }; 159 };
160 160
161 } // namespace internal 161 } // namespace internal
162 } // namespace base 162 } // namespace base
163 163
164 #endif // BASE_TASK_SCHEDULER_SCHEDULER_WORKER_POOL_IMPL_H_ 164 #endif // BASE_TASK_SCHEDULER_SCHEDULER_WORKER_POOL_IMPL_H_
OLDNEW
« no previous file with comments | « base/task_scheduler/scheduler_worker_pool.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