diff --git a/ipc/chromium/src/base/platform_thread_posix.cc b/ipc/chromium/src/base/platform_thread_posix.cc index 21398dc8a5b0..53075fd36b7d 100644 --- a/ipc/chromium/src/base/platform_thread_posix.cc +++ b/ipc/chromium/src/base/platform_thread_posix.cc @@ -26,6 +26,8 @@ #include #endif +#include "nsThreadUtils.h" + #if defined(OS_MACOSX) namespace base { void InitThreading(); @@ -33,6 +35,10 @@ void InitThreading(); #endif static void* ThreadFunc(void* closure) { + // Create a nsThread wrapper for the current platform thread, and register it + // with the thread manager. + (void) NS_GetCurrentThread(); + PlatformThread::Delegate* delegate = static_cast(closure); delegate->ThreadMain(); @@ -92,21 +98,10 @@ void PlatformThread::SetName(const char* name) { if (PlatformThread::CurrentId() == getpid()) return; - // http://0pointer.de/blog/projects/name-your-threads.html - // Set the name for the LWP (which gets truncated to 15 characters). - // Note that glibc also has a 'pthread_setname_np' api, but it may not be - // available everywhere and it's only benefit over using prctl directly is - // that it can set the name of threads other than the current thread. -#if defined(OS_LINUX) - prctl(PR_SET_NAME, reinterpret_cast(name), 0, 0, 0); -#elif defined(OS_NETBSD) - pthread_setname_np(pthread_self(), "%s", (void *)name); -#elif defined(OS_BSD) && !defined(__GLIBC__) - pthread_set_name_np(pthread_self(), name); -#elif defined(OS_SOLARIS) - pthread_setname_np(pthread_self(), name); -#else -#endif + // Using NS_SetCurrentThreadName, as opposed to using platform APIs directly, + // also sets the thread name on the PRThread wrapper, and allows us to + // retrieve it using PR_GetThreadName. + NS_SetCurrentThreadName(name); } #endif // !OS_MACOSX diff --git a/ipc/chromium/src/base/platform_thread_win.cc b/ipc/chromium/src/base/platform_thread_win.cc index 2e7614230624..762aa7e305e3 100644 --- a/ipc/chromium/src/base/platform_thread_win.cc +++ b/ipc/chromium/src/base/platform_thread_win.cc @@ -9,6 +9,8 @@ #include "base/logging.h" #include "base/win_util.h" +#include "nsThreadUtils.h" + namespace { // The information on how to set the thread name comes from @@ -23,6 +25,10 @@ typedef struct tagTHREADNAME_INFO { } THREADNAME_INFO; DWORD __stdcall ThreadFunc(void* closure) { + // Create a nsThread wrapper for the current platform thread, and register it + // with the thread manager. + (void) NS_GetCurrentThread(); + PlatformThread::Delegate* delegate = static_cast(closure); delegate->ThreadMain(); @@ -48,24 +54,10 @@ void PlatformThread::Sleep(int duration_ms) { // static void PlatformThread::SetName(const char* name) { -#ifdef HAVE_SEH_EXCEPTIONS - // The debugger needs to be around to catch the name in the exception. If - // there isn't a debugger, we are just needlessly throwing an exception. - if (!::IsDebuggerPresent()) - return; - - THREADNAME_INFO info; - info.dwType = 0x1000; - info.szName = name; - info.dwThreadID = CurrentId(); - info.dwFlags = 0; - - MOZ_SEH_TRY { - RaiseException(kVCThreadNameException, 0, sizeof(info)/sizeof(DWORD), - reinterpret_cast(&info)); - } MOZ_SEH_EXCEPT(EXCEPTION_CONTINUE_EXECUTION) { - } -#endif + // Using NS_SetCurrentThreadName, as opposed to using platform APIs directly, + // also sets the thread name on the PRThread wrapper, and allows us to + // retrieve it using PR_GetThreadName. + NS_SetCurrentThreadName(name); } // static