Bug 1347007 - Register with the profiler after doing so for the ThreadManager. r=njn
MozReview-Commit-ID: 6gtDxmlgOta
--- a/xpcom/threads/nsThread.cpp
+++ b/xpcom/threads/nsThread.cpp
@@ -455,27 +455,32 @@ nsThread::ThreadFunc(void* aArg)
char stackTop;
ThreadInitData* initData = static_cast<ThreadInitData*>(aArg);
nsThread* self = initData->thread; // strong reference
self->mThread = PR_GetCurrentThread();
SetupCurrentThreadForChaosMode();
- if (initData->name.Length() > 0) {
+ if (!initData->name.IsEmpty()) {
PR_SetCurrentThreadName(initData->name.BeginReading());
-
- profiler_register_thread(initData->name.BeginReading(), &stackTop);
}
// Inform the ThreadManager
nsThreadManager::get().RegisterCurrentThread(*self);
mozilla::IOInterposer::RegisterCurrentThread();
+ // This must come after the call to nsThreadManager::RegisterCurrentThread(),
+ // because that call is needed to properly set up this thread as an nsThread,
+ // which profiler_register_thread() requires. See bug 1347007.
+ if (!initData->name.IsEmpty()) {
+ profiler_register_thread(initData->name.BeginReading(), &stackTop);
+ }
+
// Wait for and process startup event
nsCOMPtr<nsIRunnable> event;
{
MutexAutoLock lock(self->mLock);
if (!self->mEvents->GetEvent(true, getter_AddRefs(event), lock)) {
NS_WARNING("failed waiting for thread startup event");
return;
}