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

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

Issue 2208493002: TaskScheduler: No BACKGROUND threads when unsupported. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase + CR robliao #6 (nit) Created 4 years, 4 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
« no previous file with comments | « no previous file | base/task_scheduler/scheduler_worker.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_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
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|. |priority_hint| 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 priority_hint,
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 29 matching lines...) Expand all
126 void CreateThreadAssertSynchronized(); 128 void CreateThreadAssertSynchronized();
127 129
128 bool ShouldExitForTesting() const; 130 bool ShouldExitForTesting() const;
129 131
130 // Synchronizes access to |thread_| 132 // Synchronizes access to |thread_|
131 mutable SchedulerLock thread_lock_; 133 mutable SchedulerLock thread_lock_;
132 134
133 // The underlying thread for this SchedulerWorker. 135 // The underlying thread for this SchedulerWorker.
134 std::unique_ptr<Thread> thread_; 136 std::unique_ptr<Thread> thread_;
135 137
136 const ThreadPriority thread_priority_; 138 const ThreadPriority priority_hint_;
137 const std::unique_ptr<Delegate> delegate_; 139 const std::unique_ptr<Delegate> delegate_;
138 TaskTracker* const task_tracker_; 140 TaskTracker* const task_tracker_;
139 141
140 // Synchronizes access to |should_exit_for_testing_|. 142 // Synchronizes access to |should_exit_for_testing_|.
141 mutable SchedulerLock should_exit_for_testing_lock_; 143 mutable SchedulerLock should_exit_for_testing_lock_;
142 144
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_
OLDNEW
« no previous file with comments | « no previous file | base/task_scheduler/scheduler_worker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698