OLD | NEW |
---|---|
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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 return handle_; | 105 return handle_; |
106 } | 106 } |
107 | 107 |
108 private: | 108 private: |
109 Handle handle_; | 109 Handle handle_; |
110 PlatformThreadId id_; | 110 PlatformThreadId id_; |
111 }; | 111 }; |
112 | 112 |
113 const PlatformThreadId kInvalidThreadId(0); | 113 const PlatformThreadId kInvalidThreadId(0); |
114 | 114 |
115 // Valid values for SetThreadPriority(), listed in increasing order of | 115 // Valid values for priority of Thread::Options and SimpleThread::Options, and |
116 // importance. | 116 // SetCurrentThreadPriority(), listed in increasing order of importance. |
117 enum class ThreadPriority { | 117 enum class ThreadPriority { |
118 // Suitable for threads that shouldn't disrupt high priority work. | 118 // Suitable for threads that shouldn't disrupt high priority work. |
119 BACKGROUND, | 119 BACKGROUND, |
120 // Default priority level. | 120 // Default priority level. |
121 NORMAL, | 121 NORMAL, |
122 // Suitable for threads which generate data for the display (at ~60Hz). | 122 // Suitable for threads which generate data for the display (at ~60Hz). |
123 DISPLAY, | 123 DISPLAY, |
124 // Suitable for low-latency, glitch-resistant audio. | 124 // Suitable for low-latency, glitch-resistant audio. |
125 REALTIME_AUDIO, | 125 REALTIME_AUDIO, |
126 }; | 126 }; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
169 // |*thread_handle| will be assigned a handle to the newly created thread, | 169 // |*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 | 170 // and |delegate|'s ThreadMain method will be executed on the newly created |
171 // thread. | 171 // thread. |
172 // NOTE: When you are done with the thread handle, you must call Join to | 172 // 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 | 173 // release system resources associated with the thread. You must ensure that |
174 // the Delegate object outlives the thread. | 174 // the Delegate object outlives the thread. |
175 static bool Create(size_t stack_size, Delegate* delegate, | 175 static bool Create(size_t stack_size, Delegate* delegate, |
176 PlatformThreadHandle* thread_handle); | 176 PlatformThreadHandle* thread_handle); |
177 | 177 |
178 // CreateWithPriority() does the same thing as Create() except the priority of | 178 // 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() | 179 // the thread is set based on |priority|. |
180 // followed by SetThreadPriority(). | |
181 static bool CreateWithPriority(size_t stack_size, Delegate* delegate, | 180 static bool CreateWithPriority(size_t stack_size, Delegate* delegate, |
182 PlatformThreadHandle* thread_handle, | 181 PlatformThreadHandle* thread_handle, |
183 ThreadPriority priority); | 182 ThreadPriority priority); |
184 | 183 |
185 // CreateNonJoinable() does the same thing as Create() except the thread | 184 // CreateNonJoinable() does the same thing as Create() except the thread |
186 // cannot be Join()'d. Therefore, it also does not output a | 185 // cannot be Join()'d. Therefore, it also does not output a |
187 // PlatformThreadHandle. | 186 // PlatformThreadHandle. |
188 static bool CreateNonJoinable(size_t stack_size, Delegate* delegate); | 187 static bool CreateNonJoinable(size_t stack_size, Delegate* delegate); |
189 | 188 |
190 // Joins with a thread created via the Create function. This function blocks | 189 // Joins with a thread created via the Create function. This function blocks |
191 // the caller until the designated thread exits. This will invalidate | 190 // the caller until the designated thread exits. This will invalidate |
192 // |thread_handle|. | 191 // |thread_handle|. |
193 static void Join(PlatformThreadHandle thread_handle); | 192 static void Join(PlatformThreadHandle thread_handle); |
194 | 193 |
195 // Toggles the target thread's priority at runtime. Prefer | 194 // Toggles the current thread's priority at runtime. |
gab
2015/06/23 17:01:32
Should we add an explanation here with link to a b
Takashi Toyoshima
2015/06/24 04:15:39
Done.
| |
196 // CreateWithPriority() to set the thread's initial priority. | 195 static void SetCurrentThreadPriority(ThreadPriority priority); |
197 // NOTE: The call may fail if the caller thread is not the same as the | |
198 // target thread on POSIX. For example, seccomp-bpf blocks it by default | |
199 // in the sandbox. | |
200 static void SetThreadPriority(PlatformThreadHandle handle, | |
201 ThreadPriority priority); | |
202 | 196 |
203 static ThreadPriority GetThreadPriority(PlatformThreadHandle handle); | 197 static ThreadPriority GetCurrentThreadPriority(); |
204 | 198 |
205 private: | 199 private: |
206 DISALLOW_IMPLICIT_CONSTRUCTORS(PlatformThread); | 200 DISALLOW_IMPLICIT_CONSTRUCTORS(PlatformThread); |
207 }; | 201 }; |
208 | 202 |
209 } // namespace base | 203 } // namespace base |
210 | 204 |
211 #endif // BASE_THREADING_PLATFORM_THREAD_H_ | 205 #endif // BASE_THREADING_PLATFORM_THREAD_H_ |
OLD | NEW |