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

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

Issue 1906083002: TaskScheduler: Remove base/task_scheduler/utils.h/.cc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@sched_2_stack
Patch Set: Created 4 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_SCHEDULER_THREAD_POOL_H_ 5 #ifndef BASE_TASK_SCHEDULER_SCHEDULER_THREAD_POOL_H_
6 #define BASE_TASK_SCHEDULER_SCHEDULER_THREAD_POOL_H_ 6 #define BASE_TASK_SCHEDULER_SCHEDULER_THREAD_POOL_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <memory> 10 #include <memory>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/base_export.h" 13 #include "base/base_export.h"
14 #include "base/callback.h" 14 #include "base/callback.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
17 #include "base/synchronization/condition_variable.h" 17 #include "base/synchronization/condition_variable.h"
18 #include "base/task_runner.h" 18 #include "base/task_runner.h"
19 #include "base/task_scheduler/priority_queue.h" 19 #include "base/task_scheduler/priority_queue.h"
20 #include "base/task_scheduler/scheduler_lock.h" 20 #include "base/task_scheduler/scheduler_lock.h"
21 #include "base/task_scheduler/scheduler_task_executor.h" 21 #include "base/task_scheduler/scheduler_thread_pool_interface.h"
22 #include "base/task_scheduler/scheduler_unique_stack.h" 22 #include "base/task_scheduler/scheduler_unique_stack.h"
23 #include "base/task_scheduler/scheduler_worker_thread.h" 23 #include "base/task_scheduler/scheduler_worker_thread.h"
24 #include "base/task_scheduler/sequence.h" 24 #include "base/task_scheduler/sequence.h"
25 #include "base/task_scheduler/task.h" 25 #include "base/task_scheduler/task.h"
26 #include "base/task_scheduler/task_traits.h" 26 #include "base/task_scheduler/task_traits.h"
27 #include "base/threading/platform_thread.h" 27 #include "base/threading/platform_thread.h"
28 28
29 namespace base { 29 namespace base {
30 namespace internal { 30 namespace internal {
31 31
32 class DelayedTaskManager; 32 class DelayedTaskManager;
33 struct SequenceSortKey; 33 struct SequenceSortKey;
34 class TaskTracker; 34 class TaskTracker;
35 35
36 // A pool of threads that run Tasks. This class is thread-safe. 36 // A pool of threads that run Tasks. This class is thread-safe.
37 class BASE_EXPORT SchedulerThreadPool : public SchedulerTaskExecutor { 37 class BASE_EXPORT SchedulerThreadPool : public SchedulerThreadPoolInterface {
38 public: 38 public:
39 // Callback invoked when a Sequence isn't empty after a worker thread pops a 39 // Callback invoked when a Sequence isn't empty after a worker thread pops a
40 // Task from it. 40 // Task from it.
41 using EnqueueSequenceCallback = Callback<void(scoped_refptr<Sequence>)>; 41 using EnqueueSequenceCallback = Callback<void(scoped_refptr<Sequence>)>;
42 42
43 // Destroying a SchedulerThreadPool returned by CreateThreadPool() is not 43 // Destroying a SchedulerThreadPool returned by CreateThreadPool() is not
44 // allowed in production; it is always leaked. In tests, it can only be 44 // allowed in production; it is always leaked. In tests, it can only be
45 // destroyed after JoinForTesting() has returned. 45 // destroyed after JoinForTesting() has returned.
46 ~SchedulerThreadPool() override; 46 ~SchedulerThreadPool() override;
47 47
(...skipping 23 matching lines...) Expand all
71 void EnqueueSequence(scoped_refptr<Sequence> sequence, 71 void EnqueueSequence(scoped_refptr<Sequence> sequence,
72 const SequenceSortKey& sequence_sort_key); 72 const SequenceSortKey& sequence_sort_key);
73 73
74 // Waits until all threads are idle. 74 // Waits until all threads are idle.
75 void WaitForAllWorkerThreadsIdleForTesting(); 75 void WaitForAllWorkerThreadsIdleForTesting();
76 76
77 // Joins all threads of this thread pool. Tasks that are already running are 77 // Joins all threads of this thread pool. Tasks that are already running are
78 // allowed to complete their execution. This can only be called once. 78 // allowed to complete their execution. This can only be called once.
79 void JoinForTesting(); 79 void JoinForTesting();
80 80
81 // SchedulerTaskExecutor: 81 // Posts |task| to be executed as part of |sequence|. Returns true if |task|
82 void PostTaskWithSequence(std::unique_ptr<Task> task, 82 // is posted.
83 scoped_refptr<Sequence> sequence) override; 83 bool PostTaskWithSequence(std::unique_ptr<Task> task,
84 scoped_refptr<Sequence> sequence);
85
86 // SchedulerThreadPoolInterface:
87 void PostTaskWithSequenceNow(std::unique_ptr<Task> task,
88 scoped_refptr<Sequence> sequence) override;
84 89
85 private: 90 private:
86 class SchedulerWorkerThreadDelegateImpl; 91 class SchedulerWorkerThreadDelegateImpl;
87 92
88 SchedulerThreadPool(const EnqueueSequenceCallback& enqueue_sequence_callback, 93 SchedulerThreadPool(const EnqueueSequenceCallback& enqueue_sequence_callback,
89 TaskTracker* task_tracker, 94 TaskTracker* task_tracker,
90 DelayedTaskManager* delayed_task_manager); 95 DelayedTaskManager* delayed_task_manager);
91 96
92 bool Initialize(ThreadPriority thread_priority, size_t max_threads); 97 bool Initialize(ThreadPriority thread_priority, size_t max_threads);
93 98
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 TaskTracker* const task_tracker_; 135 TaskTracker* const task_tracker_;
131 DelayedTaskManager* const delayed_task_manager_; 136 DelayedTaskManager* const delayed_task_manager_;
132 137
133 DISALLOW_COPY_AND_ASSIGN(SchedulerThreadPool); 138 DISALLOW_COPY_AND_ASSIGN(SchedulerThreadPool);
134 }; 139 };
135 140
136 } // namespace internal 141 } // namespace internal
137 } // namespace base 142 } // namespace base
138 143
139 #endif // BASE_TASK_SCHEDULER_SCHEDULER_THREAD_POOL_H_ 144 #endif // BASE_TASK_SCHEDULER_SCHEDULER_THREAD_POOL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698