Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_H_ | 5 #ifndef BASE_TASK_SCHEDULER_SCHEDULER_WORKER_H_ |
| 6 #define BASE_TASK_SCHEDULER_SCHEDULER_WORKER_H_ | 6 #define BASE_TASK_SCHEDULER_SCHEDULER_WORKER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/base_export.h" | 10 #include "base/base_export.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 // - The next WakeUp() could be more costly due to new thread creation. | 70 // - The next WakeUp() could be more costly due to new thread creation. |
| 71 // - The worker will take this as a signal that it can detach, but it is not | 71 // - The worker will take this as a signal that it can detach, but it is not |
| 72 // obligated to do so. | 72 // obligated to do so. |
| 73 // This MUST return false if SchedulerWorker::JoinForTesting() is in | 73 // This MUST return false if SchedulerWorker::JoinForTesting() is in |
| 74 // progress. | 74 // progress. |
| 75 virtual bool CanDetach(SchedulerWorker* worker) = 0; | 75 virtual bool CanDetach(SchedulerWorker* worker) = 0; |
| 76 }; | 76 }; |
| 77 | 77 |
| 78 enum class InitialState { ALIVE, DETACHED }; | 78 enum class InitialState { ALIVE, DETACHED }; |
| 79 | 79 |
| 80 // Creates a SchedulerWorker with priority |thread_priority| that runs Tasks | 80 // Creates a SchedulerWorker that runs Tasks from Sequences returned by |
| 81 // from Sequences returned by |delegate|. |task_tracker| is used to handle | 81 // |delegate|. |thread_priority| is the preferred thread priority; the actual |
| 82 // shutdown behavior of Tasks. If |worker_state| is DETACHED, the thread will | 82 // thread priority depends on shutdown state and platform capabilities. |
| 83 // be created upon a WakeUp(). Returns nullptr if creating the underlying | 83 // |task_tracker| is used to handle shutdown behavior of Tasks. If |
| 84 // platform thread fails during Create(). | 84 // |worker_state| is DETACHED, the thread will be created upon a WakeUp(). |
| 85 // Returns nullptr if creating the underlying platform thread fails during | |
| 86 // Create(). | |
| 85 static std::unique_ptr<SchedulerWorker> Create( | 87 static std::unique_ptr<SchedulerWorker> Create( |
| 86 ThreadPriority thread_priority, | 88 ThreadPriority thread_priority, |
|
gab
2016/08/03 13:35:24
s/thread_priority/priority_hint/ or something?
fdoray
2016/08/03 18:42:49
Done.
| |
| 87 std::unique_ptr<Delegate> delegate, | 89 std::unique_ptr<Delegate> delegate, |
| 88 TaskTracker* task_tracker, | 90 TaskTracker* task_tracker, |
| 89 InitialState initial_state); | 91 InitialState initial_state); |
| 90 | 92 |
| 91 // Destroying a SchedulerWorker in production is not allowed; it is always | 93 // Destroying a SchedulerWorker in production is not allowed; it is always |
| 92 // leaked. In tests, it can only be destroyed after JoinForTesting() has | 94 // leaked. In tests, it can only be destroyed after JoinForTesting() has |
| 93 // returned. | 95 // returned. |
| 94 ~SchedulerWorker(); | 96 ~SchedulerWorker(); |
| 95 | 97 |
| 96 // Wakes up this SchedulerWorker if it wasn't already awake. After this | 98 // Wakes up this SchedulerWorker if it wasn't already awake. After this |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 // True once JoinForTesting() has been called. | 145 // True once JoinForTesting() has been called. |
| 144 bool should_exit_for_testing_ = false; | 146 bool should_exit_for_testing_ = false; |
| 145 | 147 |
| 146 DISALLOW_COPY_AND_ASSIGN(SchedulerWorker); | 148 DISALLOW_COPY_AND_ASSIGN(SchedulerWorker); |
| 147 }; | 149 }; |
| 148 | 150 |
| 149 } // namespace internal | 151 } // namespace internal |
| 150 } // namespace base | 152 } // namespace base |
| 151 | 153 |
| 152 #endif // BASE_TASK_SCHEDULER_SCHEDULER_WORKER_H_ | 154 #endif // BASE_TASK_SCHEDULER_SCHEDULER_WORKER_H_ |
| OLD | NEW |