Bug 1323100 - Remove aThread argument from nsThreadPoolNaming::SetThreadPoolName, which is the last user of NS_SetThreadName.
MozReview-Commit-ID: 3DRkwYxPLCf
--- a/storage/mozStorageConnection.cpp
+++ b/storage/mozStorageConnection.cpp
@@ -584,24 +584,23 @@ Connection::getAsyncExecutionTarget()
MutexAutoLock lockedScope(sharedAsyncExecutionMutex);
// If we are shutting down the asynchronous thread, don't hand out any more
// references to the thread.
if (mAsyncExecutionThreadShuttingDown)
return nullptr;
if (!mAsyncExecutionThread) {
- nsresult rv = ::NS_NewThread(getter_AddRefs(mAsyncExecutionThread));
+ static nsThreadPoolNaming naming;
+ nsresult rv = naming.NewThreadWithThreadPoolName(NS_LITERAL_CSTRING("mozStorage"),
+ getter_AddRefs(mAsyncExecutionThread));
if (NS_FAILED(rv)) {
NS_WARNING("Failed to create async thread.");
return nullptr;
}
- static nsThreadPoolNaming naming;
- naming.SetThreadPoolName(NS_LITERAL_CSTRING("mozStorage"),
- mAsyncExecutionThread);
}
#ifdef DEBUG
mAsyncExecutionThreadIsAlive = true;
#endif
return mAsyncExecutionThread;
}
--- a/xpcom/glue/nsThreadUtils.cpp
+++ b/xpcom/glue/nsThreadUtils.cpp
@@ -437,37 +437,47 @@ nsIThread*
NS_GetCurrentThread()
{
return nsThreadManager::get().GetCurrentThread();
}
#endif
// nsThreadPoolNaming
void
-nsThreadPoolNaming::SetThreadPoolName(const nsACString& aPoolName,
- nsIThread* aThread)
+nsThreadPoolNaming::SetThreadPoolName(const nsACString& aPoolName)
{
nsCString name(aPoolName);
name.AppendLiteral(" #");
name.AppendInt(++mCounter, 10); // The counter is declared as volatile
- if (aThread) {
- // Set on the target thread
- NS_SetThreadName(aThread, name);
- } else {
- // Set on the current thread
+ // Set on the current thread
#ifndef XPCOM_GLUE_AVOID_NSPR
- PR_SetCurrentThreadName(name.BeginReading());
+ PR_SetCurrentThreadName(name.BeginReading());
#endif
- }
char stackBaseGuess;
profiler_register_thread(name.BeginReading(), &stackBaseGuess);
}
+nsresult
+nsThreadPoolNaming::NewThreadWithThreadPoolName(const nsACString& aPoolName,
+ nsIThread** aThread)
+{
+ nsCString name(aPoolName);
+ name.AppendLiteral(" #");
+ name.AppendInt(++mCounter, 10); // The counter is declared as volatile
+
+ nsresult rv = NS_NewNamedThread(name, aThread);
+ if (NS_FAILED(rv)) {
+ mCounter--;
+ }
+
+ return rv;
+}
+
// nsAutoLowPriorityIO
nsAutoLowPriorityIO::nsAutoLowPriorityIO()
{
#if defined(XP_WIN)
lowIOPrioritySet = IsVistaOrLater() &&
SetThreadPriority(GetCurrentThread(),
THREAD_MODE_BACKGROUND_BEGIN);
#elif defined(XP_MACOSX)
--- a/xpcom/glue/nsThreadUtils.h
+++ b/xpcom/glue/nsThreadUtils.h
@@ -1033,21 +1033,25 @@ private:
*/
class nsThreadPoolNaming
{
public:
nsThreadPoolNaming() : mCounter(0) {}
/**
* Creates and sets next thread name as "<aPoolName> #<n>"
- * on the specified thread. If no thread is specified (aThread
- * is null) then the name is synchronously set on the current thread.
+ * on the current thread.
*/
- void SetThreadPoolName(const nsACString& aPoolName,
- nsIThread* aThread = nullptr);
+ void SetThreadPoolName(const nsACString& aPoolName);
+
+ /**
+ * Creates a new thread and sets its thread name as "<aPoolName> #<n>".
+ */
+ nsresult NewThreadWithThreadPoolName(const nsACString& aPoolName,
+ nsIThread** aThread);
private:
mozilla::Atomic<uint32_t> mCounter;
nsThreadPoolNaming(const nsThreadPoolNaming&) = delete;
void operator=(const nsThreadPoolNaming&) = delete;
};