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

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

Issue 1784623005: Test dynamic priorities (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
« no previous file with comments | « base/threading/platform_thread_posix.cc ('k') | base/threading/simple_thread.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 (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 bool SetThreadPriority(ThreadPriority priority);
116 ThreadPriority GetThreadPriority() { return priority_; }
117
115 private: 118 private:
116 const std::string name_prefix_; 119 const std::string name_prefix_;
117 std::string name_; 120 std::string name_;
118 const Options options_; 121 const Options options_;
119 PlatformThreadHandle thread_; // PlatformThread handle, invalid after Join! 122 PlatformThreadHandle thread_; // PlatformThread handle, invalid after Join!
120 WaitableEvent event_; // Signaled if Start() was ever called. 123 WaitableEvent event_; // Signaled if Start() was ever called.
121 PlatformThreadId tid_; // The backing thread's id. 124 PlatformThreadId tid_; // The backing thread's id.
122 bool joined_; // True if Join has been called. 125 bool joined_; // True if Join has been called.
126 ThreadPriority priority_;
127 };
128
129 class BASE_EXPORT TestSimpleThread : public SimpleThread {
130 public:
131 struct BASE_EXPORT PrioritySet {
132 explicit PrioritySet(const ThreadPriority d,
133 const ThreadPriority l,
134 const ThreadPriority h)
135 : default_prio(d), low_prio(l), high_prio(h) {}
136 const ThreadPriority default_prio;
137 const ThreadPriority low_prio;
138 const ThreadPriority high_prio;
139 };
140
141 TestSimpleThread(const PrioritySet& priorities,
142 const std::string& name_prefix,
143 const Options& options);
144 bool Speedup();
145 bool Slowdown();
146 bool Restore();
147 bool IsDynamic() { return dynamic_prio_; }
148 ThreadPriority GetDefaultPriority() { return priorities_.default_prio; }
149 std::string GetPrioritySetForDebugging();
150
151 private:
152 const PrioritySet priorities_;
153 bool dynamic_prio_;
154 bool changed_;
155 std::string priorities_str_;
123 }; 156 };
124 157
125 class BASE_EXPORT DelegateSimpleThread : public SimpleThread { 158 class BASE_EXPORT DelegateSimpleThread : public SimpleThread {
126 public: 159 public:
127 class BASE_EXPORT Delegate { 160 class BASE_EXPORT Delegate {
128 public: 161 public:
129 Delegate() { } 162 Delegate() { }
130 virtual ~Delegate() { } 163 virtual ~Delegate() { }
131 virtual void Run() = 0; 164 virtual void Run() = 0;
132 }; 165 };
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 int num_threads_; 217 int num_threads_;
185 std::vector<DelegateSimpleThread*> threads_; 218 std::vector<DelegateSimpleThread*> threads_;
186 std::queue<Delegate*> delegates_; 219 std::queue<Delegate*> delegates_;
187 base::Lock lock_; // Locks delegates_ 220 base::Lock lock_; // Locks delegates_
188 WaitableEvent dry_; // Not signaled when there is no work to do. 221 WaitableEvent dry_; // Not signaled when there is no work to do.
189 }; 222 };
190 223
191 } // namespace base 224 } // namespace base
192 225
193 #endif // BASE_THREADING_SIMPLE_THREAD_H_ 226 #endif // BASE_THREADING_SIMPLE_THREAD_H_
OLDNEW
« no previous file with comments | « base/threading/platform_thread_posix.cc ('k') | base/threading/simple_thread.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698