| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/debug/activity_tracker.h" | 9 #include "base/debug/activity_tracker.h" |
| 10 #include "base/debug/alias.h" | 10 #include "base/debug/alias.h" |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 // static | 218 // static |
| 219 bool PlatformThread::CreateNonJoinableWithPriority(size_t stack_size, | 219 bool PlatformThread::CreateNonJoinableWithPriority(size_t stack_size, |
| 220 Delegate* delegate, | 220 Delegate* delegate, |
| 221 ThreadPriority priority) { | 221 ThreadPriority priority) { |
| 222 return CreateThreadInternal(stack_size, delegate, nullptr /* non-joinable */, | 222 return CreateThreadInternal(stack_size, delegate, nullptr /* non-joinable */, |
| 223 priority); | 223 priority); |
| 224 } | 224 } |
| 225 | 225 |
| 226 // static | 226 // static |
| 227 void PlatformThread::Join(PlatformThreadHandle thread_handle) { | 227 void PlatformThread::Join(PlatformThreadHandle thread_handle) { |
| 228 DCHECK(thread_handle.platform_handle()); |
| 229 |
| 230 // Joining another thread may block the current thread for a long time, since |
| 231 // the thread referred to by |thread_handle| may still be running long-lived / |
| 232 // blocking tasks. |
| 233 base::ThreadRestrictions::AssertWaitAllowed(); |
| 234 |
| 228 // Record the event that this thread is blocking upon (for hang diagnosis). | 235 // Record the event that this thread is blocking upon (for hang diagnosis). |
| 229 base::debug::ScopedThreadJoinActivity thread_activity(&thread_handle); | 236 base::debug::ScopedThreadJoinActivity thread_activity(&thread_handle); |
| 230 | 237 |
| 231 DCHECK(thread_handle.platform_handle()); | |
| 232 // TODO(willchan): Enable this check once I can get it to work for Windows | |
| 233 // shutdown. | |
| 234 // Joining another thread may block the current thread for a long time, since | |
| 235 // the thread referred to by |thread_handle| may still be running long-lived / | |
| 236 // blocking tasks. | |
| 237 #if 0 | |
| 238 base::ThreadRestrictions::AssertIOAllowed(); | |
| 239 #endif | |
| 240 | |
| 241 // Wait for the thread to exit. It should already have terminated but make | 238 // Wait for the thread to exit. It should already have terminated but make |
| 242 // sure this assumption is valid. | 239 // sure this assumption is valid. |
| 243 CHECK_EQ(WAIT_OBJECT_0, | 240 CHECK_EQ(WAIT_OBJECT_0, |
| 244 WaitForSingleObject(thread_handle.platform_handle(), INFINITE)); | 241 WaitForSingleObject(thread_handle.platform_handle(), INFINITE)); |
| 245 CloseHandle(thread_handle.platform_handle()); | 242 CloseHandle(thread_handle.platform_handle()); |
| 246 } | 243 } |
| 247 | 244 |
| 248 // static | 245 // static |
| 249 void PlatformThread::Detach(PlatformThreadHandle thread_handle) { | 246 void PlatformThread::Detach(PlatformThreadHandle thread_handle) { |
| 250 CloseHandle(thread_handle.platform_handle()); | 247 CloseHandle(thread_handle.platform_handle()); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 return ThreadPriority::REALTIME_AUDIO; | 298 return ThreadPriority::REALTIME_AUDIO; |
| 302 case THREAD_PRIORITY_ERROR_RETURN: | 299 case THREAD_PRIORITY_ERROR_RETURN: |
| 303 DPCHECK(false) << "GetThreadPriority error"; // Falls through. | 300 DPCHECK(false) << "GetThreadPriority error"; // Falls through. |
| 304 default: | 301 default: |
| 305 NOTREACHED() << "Unexpected priority: " << priority; | 302 NOTREACHED() << "Unexpected priority: " << priority; |
| 306 return ThreadPriority::NORMAL; | 303 return ThreadPriority::NORMAL; |
| 307 } | 304 } |
| 308 } | 305 } |
| 309 | 306 |
| 310 } // namespace base | 307 } // namespace base |
| OLD | NEW |