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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 ThreadParams* params = new ThreadParams; | 107 ThreadParams* params = new ThreadParams; |
108 params->delegate = delegate; | 108 params->delegate = delegate; |
109 params->joinable = out_thread_handle != nullptr; | 109 params->joinable = out_thread_handle != nullptr; |
110 params->priority = priority; | 110 params->priority = priority; |
111 | 111 |
112 // Using CreateThread here vs _beginthreadex makes thread creation a bit | 112 // Using CreateThread here vs _beginthreadex makes thread creation a bit |
113 // faster and doesn't require the loader lock to be available. Our code will | 113 // faster and doesn't require the loader lock to be available. Our code will |
114 // have to work running on CreateThread() threads anyway, since we run code | 114 // have to work running on CreateThread() threads anyway, since we run code |
115 // on the Windows thread pool, etc. For some background on the difference: | 115 // on the Windows thread pool, etc. For some background on the difference: |
116 // http://www.microsoft.com/msj/1099/win32/win321099.aspx | 116 // http://www.microsoft.com/msj/1099/win32/win321099.aspx |
117 void* thread_handle = | 117 base::win::ScopedHandle thread_handle( |
118 ::CreateThread(nullptr, stack_size, ThreadFunc, params, flags, nullptr); | 118 ::CreateThread(nullptr, stack_size, ThreadFunc, params, flags, nullptr)); |
119 if (!thread_handle) { | 119 if (!thread_handle.IsValid()) { |
120 delete params; | 120 delete params; |
121 return false; | 121 return false; |
122 } | 122 } |
123 | 123 |
124 if (out_thread_handle) | 124 if (out_thread_handle) |
125 *out_thread_handle = PlatformThreadHandle(thread_handle); | 125 *out_thread_handle = PlatformThreadHandle(thread_handle.Take()); |
126 else | |
127 CloseHandle(thread_handle); | |
128 return true; | 126 return true; |
129 } | 127 } |
130 | 128 |
131 } // namespace | 129 } // namespace |
132 | 130 |
133 // static | 131 // static |
134 PlatformThreadId PlatformThread::CurrentId() { | 132 PlatformThreadId PlatformThread::CurrentId() { |
135 return ::GetCurrentThreadId(); | 133 return ::GetCurrentThreadId(); |
136 } | 134 } |
137 | 135 |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 return ThreadPriority::REALTIME_AUDIO; | 271 return ThreadPriority::REALTIME_AUDIO; |
274 case THREAD_PRIORITY_ERROR_RETURN: | 272 case THREAD_PRIORITY_ERROR_RETURN: |
275 DPCHECK(false) << "GetThreadPriority error"; // Falls through. | 273 DPCHECK(false) << "GetThreadPriority error"; // Falls through. |
276 default: | 274 default: |
277 NOTREACHED() << "Unexpected priority: " << priority; | 275 NOTREACHED() << "Unexpected priority: " << priority; |
278 return ThreadPriority::NORMAL; | 276 return ThreadPriority::NORMAL; |
279 } | 277 } |
280 } | 278 } |
281 | 279 |
282 } // namespace base | 280 } // namespace base |
OLD | NEW |