зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1476405: Part 2a - Create nsThread wrappers/set names for chromium threads. r=erahm,jld
MozReview-Commit-ID: FvGhq6nhIde --HG-- extra : rebase_source : 3d9ef99840da37bce0117515b03a165f6821e74d
This commit is contained in:
Родитель
c2cc4cf6e5
Коммит
8a9627cd5c
|
@ -26,6 +26,8 @@
|
|||
#include <pthread_np.h>
|
||||
#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<PlatformThread::Delegate*>(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<uintptr_t>(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
|
||||
|
||||
|
|
|
@ -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<PlatformThread::Delegate*>(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<DWORD_PTR*>(&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
|
||||
|
|
Загрузка…
Ссылка в новой задаче