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

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

Issue 1193303002: base/threading: restrict to set only current thread priority (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review #48 Created 5 years, 5 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/threading/platform_thread_android.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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 *NOT* be using this class directly. PlatformThread is 5 // WARNING: You should *NOT* be using this class directly. PlatformThread is
6 // the low-level platform-specific abstraction to the OS's threading interface. 6 // the low-level platform-specific abstraction to the OS's threading interface.
7 // You should instead be using a message-loop driven Thread, see thread.h. 7 // You should instead be using a message-loop driven Thread, see thread.h.
8 8
9 #ifndef BASE_THREADING_PLATFORM_THREAD_H_ 9 #ifndef BASE_THREADING_PLATFORM_THREAD_H_
10 #define BASE_THREADING_PLATFORM_THREAD_H_ 10 #define BASE_THREADING_PLATFORM_THREAD_H_
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 : handle_(handle), 82 : handle_(handle),
83 id_(0) { 83 id_(0) {
84 } 84 }
85 85
86 PlatformThreadHandle(Handle handle, 86 PlatformThreadHandle(Handle handle,
87 PlatformThreadId id) 87 PlatformThreadId id)
88 : handle_(handle), 88 : handle_(handle),
89 id_(id) { 89 id_(id) {
90 } 90 }
91 91
92 // TODO(toyoshim): Remove id() and use PlatformThread::CurrentId() instead.
92 PlatformThreadId id() const { 93 PlatformThreadId id() const {
93 return id_; 94 return id_;
94 } 95 }
95 96
96 bool is_equal(const PlatformThreadHandle& other) const { 97 bool is_equal(const PlatformThreadHandle& other) const {
97 return handle_ == other.handle_; 98 return handle_ == other.handle_;
98 } 99 }
99 100
100 bool is_null() const { 101 bool is_null() const {
101 return !handle_; 102 return !handle_;
102 } 103 }
103 104
104 Handle platform_handle() const { 105 Handle platform_handle() const {
105 return handle_; 106 return handle_;
106 } 107 }
107 108
108 private: 109 private:
109 Handle handle_; 110 Handle handle_;
110 PlatformThreadId id_; 111 PlatformThreadId id_;
111 }; 112 };
112 113
113 const PlatformThreadId kInvalidThreadId(0); 114 const PlatformThreadId kInvalidThreadId(0);
114 115
115 // Valid values for SetThreadPriority(), listed in increasing order of 116 // Valid values for priority of Thread::Options and SimpleThread::Options, and
116 // importance. 117 // SetCurrentThreadPriority(), listed in increasing order of importance.
117 enum class ThreadPriority { 118 enum class ThreadPriority {
118 // Suitable for threads that shouldn't disrupt high priority work. 119 // Suitable for threads that shouldn't disrupt high priority work.
119 BACKGROUND, 120 BACKGROUND,
120 // Default priority level. 121 // Default priority level.
121 NORMAL, 122 NORMAL,
122 // Suitable for threads which generate data for the display (at ~60Hz). 123 // Suitable for threads which generate data for the display (at ~60Hz).
123 DISPLAY, 124 DISPLAY,
124 // Suitable for low-latency, glitch-resistant audio. 125 // Suitable for low-latency, glitch-resistant audio.
125 REALTIME_AUDIO, 126 REALTIME_AUDIO,
126 }; 127 };
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 // |*thread_handle| will be assigned a handle to the newly created thread, 170 // |*thread_handle| will be assigned a handle to the newly created thread,
170 // and |delegate|'s ThreadMain method will be executed on the newly created 171 // and |delegate|'s ThreadMain method will be executed on the newly created
171 // thread. 172 // thread.
172 // NOTE: When you are done with the thread handle, you must call Join to 173 // NOTE: When you are done with the thread handle, you must call Join to
173 // release system resources associated with the thread. You must ensure that 174 // release system resources associated with the thread. You must ensure that
174 // the Delegate object outlives the thread. 175 // the Delegate object outlives the thread.
175 static bool Create(size_t stack_size, Delegate* delegate, 176 static bool Create(size_t stack_size, Delegate* delegate,
176 PlatformThreadHandle* thread_handle); 177 PlatformThreadHandle* thread_handle);
177 178
178 // CreateWithPriority() does the same thing as Create() except the priority of 179 // CreateWithPriority() does the same thing as Create() except the priority of
179 // the thread is set based on |priority|. Can be used in place of Create() 180 // the thread is set based on |priority|.
180 // followed by SetThreadPriority().
181 static bool CreateWithPriority(size_t stack_size, Delegate* delegate, 181 static bool CreateWithPriority(size_t stack_size, Delegate* delegate,
182 PlatformThreadHandle* thread_handle, 182 PlatformThreadHandle* thread_handle,
183 ThreadPriority priority); 183 ThreadPriority priority);
184 184
185 // CreateNonJoinable() does the same thing as Create() except the thread 185 // CreateNonJoinable() does the same thing as Create() except the thread
186 // cannot be Join()'d. Therefore, it also does not output a 186 // cannot be Join()'d. Therefore, it also does not output a
187 // PlatformThreadHandle. 187 // PlatformThreadHandle.
188 static bool CreateNonJoinable(size_t stack_size, Delegate* delegate); 188 static bool CreateNonJoinable(size_t stack_size, Delegate* delegate);
189 189
190 // Joins with a thread created via the Create function. This function blocks 190 // Joins with a thread created via the Create function. This function blocks
191 // the caller until the designated thread exits. This will invalidate 191 // the caller until the designated thread exits. This will invalidate
192 // |thread_handle|. 192 // |thread_handle|.
193 static void Join(PlatformThreadHandle thread_handle); 193 static void Join(PlatformThreadHandle thread_handle);
194 194
195 // Toggles the target thread's priority at runtime. Prefer 195 // Toggles the current thread's priority at runtime. A thread may not be able
196 // CreateWithPriority() to set the thread's initial priority. 196 // to raise its priority back up after lowering it if the process does not
197 // NOTE: The call may fail if the caller thread is not the same as the 197 // have a proper permission, e.g. CAP_SYS_NICE on Linux.
198 // target thread on POSIX. For example, seccomp-bpf blocks it by default 198 // Since changing other threads' priority is not permitted in favor of
199 // in the sandbox. 199 // security, this interface is restricted to change only the current thread
200 static void SetThreadPriority(PlatformThreadHandle handle, 200 // priority (https://crbug.com/399473).
201 ThreadPriority priority); 201 static void SetCurrentThreadPriority(ThreadPriority priority);
202 202
203 static ThreadPriority GetThreadPriority(PlatformThreadHandle handle); 203 static ThreadPriority GetCurrentThreadPriority();
204 204
205 private: 205 private:
206 DISALLOW_IMPLICIT_CONSTRUCTORS(PlatformThread); 206 DISALLOW_IMPLICIT_CONSTRUCTORS(PlatformThread);
207 }; 207 };
208 208
209 } // namespace base 209 } // namespace base
210 210
211 #endif // BASE_THREADING_PLATFORM_THREAD_H_ 211 #endif // BASE_THREADING_PLATFORM_THREAD_H_
OLDNEW
« no previous file with comments | « no previous file | base/threading/platform_thread_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698