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

Side by Side Diff: base/threading/simple_thread.h

Issue 1739993004: content: Implement dynamic priorities for raster threads. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: preparing for checkin. Created 4 years, 9 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // WARNING: You should probably be using Thread (thread.h) instead. Thread is 5 // WARNING: You should probably be using Thread (thread.h) instead. Thread is
6 // Chrome's message-loop based Thread abstraction, and if you are a 6 // Chrome's message-loop based Thread abstraction, and if you are a
7 // thread running in the browser, there will likely be assumptions 7 // thread running in the browser, there will likely be assumptions
8 // that your thread will have an associated message loop. 8 // that your thread will have an associated message loop.
9 // 9 //
10 // This is a simple thread interface that backs to a native operating system 10 // This is a simple thread interface that backs to a native operating system
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 105
106 // Return True if Start() has ever been called. 106 // Return True if Start() has ever been called.
107 bool HasBeenStarted(); 107 bool HasBeenStarted();
108 108
109 // Return True if Join() has evern been called. 109 // Return True if Join() has evern been called.
110 bool HasBeenJoined() { return joined_; } 110 bool HasBeenJoined() { return joined_; }
111 111
112 // Overridden from PlatformThread::Delegate: 112 // Overridden from PlatformThread::Delegate:
113 void ThreadMain() override; 113 void ThreadMain() override;
114 114
115 // Set the priority of this thread.
116 bool SetThreadPriority(ThreadPriority priority);
117
118 // Get the priority of this thread.
119 ThreadPriority GetThreadPriority() { return priority_; }
120
115 private: 121 private:
116 const std::string name_prefix_; 122 const std::string name_prefix_;
117 std::string name_; 123 std::string name_;
118 const Options options_; 124 const Options options_;
119 PlatformThreadHandle thread_; // PlatformThread handle, invalid after Join! 125 PlatformThreadHandle thread_; // PlatformThread handle, invalid after Join!
120 WaitableEvent event_; // Signaled if Start() was ever called. 126 WaitableEvent event_; // Signaled if Start() was ever called.
121 PlatformThreadId tid_; // The backing thread's id. 127 PlatformThreadId tid_; // The backing thread's id.
122 bool joined_; // True if Join has been called. 128 bool joined_; // True if Join has been called.
129 ThreadPriority priority_; // Stores currently set priority.
130 };
131
132 // This class creates a simple thread with capability of changing priority
133 // when it is scheduled. Thread starts with |default_priority| from
134 // |priorities_| and it must be started to change the priority.
135 class BASE_EXPORT DynamicPriorityThread : public SimpleThread {
136 public:
137 struct BASE_EXPORT PrioritySet {
138 explicit PrioritySet(const ThreadPriority default_prio,
139 const ThreadPriority lower_prio,
140 const ThreadPriority higher_prio)
141 : default_priority(default_prio),
142 lower_priority(lower_prio),
143 higher_priority(higher_prio) {}
144 const ThreadPriority default_priority;
145 const ThreadPriority lower_priority;
146 const ThreadPriority higher_priority;
147 };
148
149 explicit DynamicPriorityThread(const PrioritySet& priorities,
150 const std::string& name_prefix,
151 const Options& options);
152
153 // Sets higher priority from |priorities_|.
154 bool Speedup();
155 // Sets lower priority from |priorities_|.
156 bool Slowdown();
157 // Sets default priority from |priorities_|.
158 bool RestoreDefaultPriority();
159
160 // Returns true if thread is having lower and higher priorities different.
161 bool HasDynamicPriorities() { return dynamic_priorities_; }
162
163 ThreadPriority GetDefaultPriority() { return priorities_.default_priority; }
164
165 private:
166 const PrioritySet priorities_;
167 bool dynamic_priorities_;
168 bool priority_changed_;
123 }; 169 };
124 170
125 class BASE_EXPORT DelegateSimpleThread : public SimpleThread { 171 class BASE_EXPORT DelegateSimpleThread : public SimpleThread {
126 public: 172 public:
127 class BASE_EXPORT Delegate { 173 class BASE_EXPORT Delegate {
128 public: 174 public:
129 Delegate() { } 175 Delegate() { }
130 virtual ~Delegate() { } 176 virtual ~Delegate() { }
131 virtual void Run() = 0; 177 virtual void Run() = 0;
132 }; 178 };
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 int num_threads_; 230 int num_threads_;
185 std::vector<DelegateSimpleThread*> threads_; 231 std::vector<DelegateSimpleThread*> threads_;
186 std::queue<Delegate*> delegates_; 232 std::queue<Delegate*> delegates_;
187 base::Lock lock_; // Locks delegates_ 233 base::Lock lock_; // Locks delegates_
188 WaitableEvent dry_; // Not signaled when there is no work to do. 234 WaitableEvent dry_; // Not signaled when there is no work to do.
189 }; 235 };
190 236
191 } // namespace base 237 } // namespace base
192 238
193 #endif // BASE_THREADING_SIMPLE_THREAD_H_ 239 #endif // BASE_THREADING_SIMPLE_THREAD_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698