OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/platform_thread.h" | 5 #include "base/platform_thread.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/win_util.h" | 8 #include "base/win/windows_version.h" |
9 | 9 |
10 namespace { | 10 namespace { |
11 | 11 |
12 // The information on how to set the thread name comes from | 12 // The information on how to set the thread name comes from |
13 // a MSDN article: http://msdn2.microsoft.com/en-us/library/xcb2z8hs.aspx | 13 // a MSDN article: http://msdn2.microsoft.com/en-us/library/xcb2z8hs.aspx |
14 const DWORD kVCThreadNameException = 0x406D1388; | 14 const DWORD kVCThreadNameException = 0x406D1388; |
15 | 15 |
16 typedef struct tagTHREADNAME_INFO { | 16 typedef struct tagTHREADNAME_INFO { |
17 DWORD dwType; // Must be 0x1000. | 17 DWORD dwType; // Must be 0x1000. |
18 LPCSTR szName; // Pointer to name (in user addr space). | 18 LPCSTR szName; // Pointer to name (in user addr space). |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 RaiseException(kVCThreadNameException, 0, sizeof(info)/sizeof(DWORD), | 61 RaiseException(kVCThreadNameException, 0, sizeof(info)/sizeof(DWORD), |
62 reinterpret_cast<DWORD_PTR*>(&info)); | 62 reinterpret_cast<DWORD_PTR*>(&info)); |
63 } __except(EXCEPTION_CONTINUE_EXECUTION) { | 63 } __except(EXCEPTION_CONTINUE_EXECUTION) { |
64 } | 64 } |
65 } | 65 } |
66 | 66 |
67 // static | 67 // static |
68 bool PlatformThread::Create(size_t stack_size, Delegate* delegate, | 68 bool PlatformThread::Create(size_t stack_size, Delegate* delegate, |
69 PlatformThreadHandle* thread_handle) { | 69 PlatformThreadHandle* thread_handle) { |
70 unsigned int flags = 0; | 70 unsigned int flags = 0; |
71 if (stack_size > 0 && win_util::GetWinVersion() >= win_util::WINVERSION_XP) { | 71 if (stack_size > 0 && base::win::GetVersion() >= base::win::VERSION_XP) { |
72 flags = STACK_SIZE_PARAM_IS_A_RESERVATION; | 72 flags = STACK_SIZE_PARAM_IS_A_RESERVATION; |
73 } else { | 73 } else { |
74 stack_size = 0; | 74 stack_size = 0; |
75 } | 75 } |
76 | 76 |
77 // Using CreateThread here vs _beginthreadex makes thread creation a bit | 77 // Using CreateThread here vs _beginthreadex makes thread creation a bit |
78 // faster and doesn't require the loader lock to be available. Our code will | 78 // faster and doesn't require the loader lock to be available. Our code will |
79 // have to work running on CreateThread() threads anyway, since we run code | 79 // have to work running on CreateThread() threads anyway, since we run code |
80 // on the Windows thread pool, etc. For some background on the difference: | 80 // on the Windows thread pool, etc. For some background on the difference: |
81 // http://www.microsoft.com/msj/1099/win32/win321099.aspx | 81 // http://www.microsoft.com/msj/1099/win32/win321099.aspx |
(...skipping 14 matching lines...) Expand all Loading... |
96 void PlatformThread::Join(PlatformThreadHandle thread_handle) { | 96 void PlatformThread::Join(PlatformThreadHandle thread_handle) { |
97 DCHECK(thread_handle); | 97 DCHECK(thread_handle); |
98 | 98 |
99 // Wait for the thread to exit. It should already have terminated but make | 99 // Wait for the thread to exit. It should already have terminated but make |
100 // sure this assumption is valid. | 100 // sure this assumption is valid. |
101 DWORD result = WaitForSingleObject(thread_handle, INFINITE); | 101 DWORD result = WaitForSingleObject(thread_handle, INFINITE); |
102 DCHECK_EQ(WAIT_OBJECT_0, result); | 102 DCHECK_EQ(WAIT_OBJECT_0, result); |
103 | 103 |
104 CloseHandle(thread_handle); | 104 CloseHandle(thread_handle); |
105 } | 105 } |
OLD | NEW |