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 #include "base/threading/platform_thread.h" | 5 #include "base/threading/platform_thread.h" |
6 | 6 |
7 #include "base/debug/alias.h" | 7 #include "base/debug/alias.h" |
8 #include "base/debug/profiler.h" | 8 #include "base/debug/profiler.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/threading/thread_id_name_manager.h" | 10 #include "base/threading/thread_id_name_manager.h" |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
188 DCHECK(thread_handle); | 188 DCHECK(thread_handle); |
189 return CreateThreadInternal(stack_size, delegate, thread_handle); | 189 return CreateThreadInternal(stack_size, delegate, thread_handle); |
190 } | 190 } |
191 | 191 |
192 // static | 192 // static |
193 bool PlatformThread::CreateWithPriority(size_t stack_size, Delegate* delegate, | 193 bool PlatformThread::CreateWithPriority(size_t stack_size, Delegate* delegate, |
194 PlatformThreadHandle* thread_handle, | 194 PlatformThreadHandle* thread_handle, |
195 ThreadPriority priority) { | 195 ThreadPriority priority) { |
196 bool result = Create(stack_size, delegate, thread_handle); | 196 bool result = Create(stack_size, delegate, thread_handle); |
197 if (result) | 197 if (result) |
198 SetThreadPriority(*thread_handle, priority); | 198 SetCurrentThreadPriority(priority); |
gab
2015/06/23 17:01:32
Hmm, this is incorrect no? This code runs on the t
Takashi Toyoshima
2015/06/24 04:15:39
Oops, thank you for catching this.
Yes, definitely
| |
199 return result; | 199 return result; |
200 } | 200 } |
201 | 201 |
202 // static | 202 // static |
203 bool PlatformThread::CreateNonJoinable(size_t stack_size, Delegate* delegate) { | 203 bool PlatformThread::CreateNonJoinable(size_t stack_size, Delegate* delegate) { |
204 return CreateThreadInternal(stack_size, delegate, NULL); | 204 return CreateThreadInternal(stack_size, delegate, NULL); |
205 } | 205 } |
206 | 206 |
207 // static | 207 // static |
208 void PlatformThread::Join(PlatformThreadHandle thread_handle) { | 208 void PlatformThread::Join(PlatformThreadHandle thread_handle) { |
(...skipping 15 matching lines...) Expand all Loading... | |
224 DWORD error = GetLastError(); | 224 DWORD error = GetLastError(); |
225 debug::Alias(&error); | 225 debug::Alias(&error); |
226 debug::Alias(&result); | 226 debug::Alias(&result); |
227 CHECK(false); | 227 CHECK(false); |
228 } | 228 } |
229 | 229 |
230 CloseHandle(thread_handle.platform_handle()); | 230 CloseHandle(thread_handle.platform_handle()); |
231 } | 231 } |
232 | 232 |
233 // static | 233 // static |
234 void PlatformThread::SetThreadPriority(PlatformThreadHandle handle, | 234 void PlatformThread::SetCurrentThreadPriority(ThreadPriority priority) { |
235 ThreadPriority priority) { | |
236 DCHECK(!handle.is_null()); | |
237 | |
238 int desired_priority = THREAD_PRIORITY_ERROR_RETURN; | 235 int desired_priority = THREAD_PRIORITY_ERROR_RETURN; |
239 switch (priority) { | 236 switch (priority) { |
240 case ThreadPriority::BACKGROUND: | 237 case ThreadPriority::BACKGROUND: |
241 desired_priority = THREAD_PRIORITY_LOWEST; | 238 desired_priority = THREAD_PRIORITY_LOWEST; |
242 break; | 239 break; |
243 case ThreadPriority::NORMAL: | 240 case ThreadPriority::NORMAL: |
244 desired_priority = THREAD_PRIORITY_NORMAL; | 241 desired_priority = THREAD_PRIORITY_NORMAL; |
245 break; | 242 break; |
246 case ThreadPriority::DISPLAY: | 243 case ThreadPriority::DISPLAY: |
247 desired_priority = THREAD_PRIORITY_ABOVE_NORMAL; | 244 desired_priority = THREAD_PRIORITY_ABOVE_NORMAL; |
248 break; | 245 break; |
249 case ThreadPriority::REALTIME_AUDIO: | 246 case ThreadPriority::REALTIME_AUDIO: |
250 desired_priority = THREAD_PRIORITY_TIME_CRITICAL; | 247 desired_priority = THREAD_PRIORITY_TIME_CRITICAL; |
251 break; | 248 break; |
252 default: | 249 default: |
253 NOTREACHED() << "Unknown priority."; | 250 NOTREACHED() << "Unknown priority."; |
254 break; | 251 break; |
255 } | 252 } |
256 DCHECK_NE(desired_priority, THREAD_PRIORITY_ERROR_RETURN); | 253 DCHECK_NE(desired_priority, THREAD_PRIORITY_ERROR_RETURN); |
257 | 254 |
258 #ifndef NDEBUG | 255 #ifndef NDEBUG |
259 const BOOL success = | 256 const BOOL success = |
260 #endif | 257 #endif |
261 ::SetThreadPriority(handle.platform_handle(), desired_priority); | 258 ::SetThreadPriority(PlatformThread::CurrentHandle().platform_handle(), |
259 desired_priority); | |
262 DPLOG_IF(ERROR, !success) << "Failed to set thread priority to " | 260 DPLOG_IF(ERROR, !success) << "Failed to set thread priority to " |
263 << desired_priority; | 261 << desired_priority; |
264 } | 262 } |
265 | 263 |
266 // static | 264 // static |
267 ThreadPriority PlatformThread::GetThreadPriority(PlatformThreadHandle handle) { | 265 ThreadPriority PlatformThread::GetCurrentThreadPriority() { |
268 DCHECK(!handle.is_null()); | 266 int priority = |
269 | 267 ::GetThreadPriority(PlatformThread::CurrentHandle().platform_handle()); |
270 int priority = ::GetThreadPriority(handle.platform_handle()); | |
271 switch (priority) { | 268 switch (priority) { |
272 case THREAD_PRIORITY_LOWEST: | 269 case THREAD_PRIORITY_LOWEST: |
273 return ThreadPriority::BACKGROUND; | 270 return ThreadPriority::BACKGROUND; |
274 case THREAD_PRIORITY_NORMAL: | 271 case THREAD_PRIORITY_NORMAL: |
275 return ThreadPriority::NORMAL; | 272 return ThreadPriority::NORMAL; |
276 case THREAD_PRIORITY_ABOVE_NORMAL: | 273 case THREAD_PRIORITY_ABOVE_NORMAL: |
277 return ThreadPriority::DISPLAY; | 274 return ThreadPriority::DISPLAY; |
278 case THREAD_PRIORITY_TIME_CRITICAL: | 275 case THREAD_PRIORITY_TIME_CRITICAL: |
279 return ThreadPriority::REALTIME_AUDIO; | 276 return ThreadPriority::REALTIME_AUDIO; |
280 case THREAD_PRIORITY_ERROR_RETURN: | 277 case THREAD_PRIORITY_ERROR_RETURN: |
281 DPCHECK(false) << "GetThreadPriority error"; // Falls through. | 278 DPCHECK(false) << "GetThreadPriority error"; // Falls through. |
282 default: | 279 default: |
283 NOTREACHED() << "Unexpected priority: " << priority; | 280 NOTREACHED() << "Unexpected priority: " << priority; |
284 return ThreadPriority::NORMAL; | 281 return ThreadPriority::NORMAL; |
285 } | 282 } |
286 } | 283 } |
287 | 284 |
288 } // namespace base | 285 } // namespace base |
OLD | NEW |