OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/browser/sync/util/pthread_helpers.h" | 5 #include "chrome/browser/sync/util/pthread_helpers.h" |
6 | 6 |
7 #if (defined(OS_LINUX) || defined(OS_MACOSX)) | 7 #if (defined(OS_LINUX) || defined(OS_MACOSX)) |
8 #include <sys/time.h> | 8 #include <sys/time.h> |
9 #endif // (defined(OS_LINUX) || defined(OS_MACOSX)) | 9 #endif // (defined(OS_LINUX) || defined(OS_MACOSX)) |
10 | 10 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 struct timespec deadline = { now.tv_sec }; | 126 struct timespec deadline = { now.tv_sec }; |
127 // microseconds to nanoseconds. | 127 // microseconds to nanoseconds. |
128 // and add the ms delay. | 128 // and add the ms delay. |
129 ms += now.tv_usec / 1000; | 129 ms += now.tv_usec / 1000; |
130 deadline.tv_sec += ms / 1000; | 130 deadline.tv_sec += ms / 1000; |
131 deadline.tv_nsec = (ms % 1000) * 1000000; | 131 deadline.tv_nsec = (ms % 1000) * 1000000; |
132 return deadline; | 132 return deadline; |
133 #endif // OS_WIN | 133 #endif // OS_WIN |
134 } | 134 } |
135 | 135 |
136 void NameCurrentThreadForDebugging(char* name) { | 136 void NameCurrentThreadForDebugging(const char* name) { |
137 #if defined(OS_WIN) | 137 #if defined(OS_WIN) |
138 // This implementation is taken from Chromium's platform_thread framework. | 138 // This implementation is taken from Chromium's platform_thread framework. |
139 // The information on how to set the thread name comes from a MSDN article: | 139 // The information on how to set the thread name comes from a MSDN article: |
140 // http://msdn2.microsoft.com/en-us/library/xcb2z8hs.aspx | 140 // http://msdn2.microsoft.com/en-us/library/xcb2z8hs.aspx |
141 const DWORD kVCThreadNameException = 0x406D1388; | 141 const DWORD kVCThreadNameException = 0x406D1388; |
142 typedef struct tagTHREADNAME_INFO { | 142 typedef struct tagTHREADNAME_INFO { |
143 DWORD dwType; // Must be 0x1000. | 143 DWORD dwType; // Must be 0x1000. |
144 LPCSTR szName; // Pointer to name (in user addr space). | 144 LPCSTR szName; // Pointer to name (in user addr space). |
145 DWORD dwThreadID; // Thread ID (-1=caller thread). | 145 DWORD dwThreadID; // Thread ID (-1=caller thread). |
146 DWORD dwFlags; // Reserved for future use, must be zero. | 146 DWORD dwFlags; // Reserved for future use, must be zero. |
147 } THREADNAME_INFO; | 147 } THREADNAME_INFO; |
148 | 148 |
149 // The debugger needs to be around to catch the name in the exception. If | 149 // The debugger needs to be around to catch the name in the exception. If |
150 // there isn't a debugger, we are just needlessly throwing an exception. | 150 // there isn't a debugger, we are just needlessly throwing an exception. |
151 if (!::IsDebuggerPresent()) | 151 if (!::IsDebuggerPresent()) |
152 return; | 152 return; |
153 | 153 |
154 THREADNAME_INFO info = { 0x1000, name, GetCurrentThreadId(), 0 }; | 154 THREADNAME_INFO info = { 0x1000, name, GetCurrentThreadId(), 0 }; |
155 | 155 |
156 __try { | 156 __try { |
157 RaiseException(kVCThreadNameException, 0, sizeof(info)/sizeof(DWORD), | 157 RaiseException(kVCThreadNameException, 0, sizeof(info)/sizeof(DWORD), |
158 reinterpret_cast<DWORD_PTR*>(&info)); | 158 reinterpret_cast<DWORD_PTR*>(&info)); |
159 } __except(EXCEPTION_CONTINUE_EXECUTION) { | 159 } __except(EXCEPTION_CONTINUE_EXECUTION) { |
160 } | 160 } |
161 #endif // defined(OS_WIN) | 161 #endif // defined(OS_WIN) |
162 } | 162 } |
OLD | NEW |