diff --git a/xpcom/glue/nsThreadUtils.cpp b/xpcom/glue/nsThreadUtils.cpp index 994f71de7d25..7374f54d9251 100644 --- a/xpcom/glue/nsThreadUtils.cpp +++ b/xpcom/glue/nsThreadUtils.cpp @@ -440,13 +440,20 @@ NS_GetCurrentThread() #endif // nsThreadPoolNaming +nsCString +nsThreadPoolNaming::GetNextThreadName(const nsACString& aPoolName) +{ + nsCString name(aPoolName); + name.AppendLiteral(" #"); + name.AppendInt(++mCounter, 10); // The counter is declared as atomic + return name; +} + void nsThreadPoolNaming::SetThreadPoolName(const nsACString& aPoolName, nsIThread* aThread) { - nsCString name(aPoolName); - name.AppendLiteral(" #"); - name.AppendInt(++mCounter, 10); // The counter is declared as volatile + nsCString name = GetNextThreadName(aPoolName); if (aThread) { // Set on the target thread diff --git a/xpcom/glue/nsThreadUtils.h b/xpcom/glue/nsThreadUtils.h index 3644f48b1238..d9671b160fb2 100644 --- a/xpcom/glue/nsThreadUtils.h +++ b/xpcom/glue/nsThreadUtils.h @@ -1037,6 +1037,17 @@ class nsThreadPoolNaming public: nsThreadPoolNaming() : mCounter(0) {} + /** + * Returns a thread name as " #" and increments the counter. + */ + nsCString GetNextThreadName(const nsACString& aPoolName); + + template + nsCString GetNextThreadName(const char (&aPoolName)[LEN]) + { + return GetNextThreadName(nsDependentCString(aPoolName, LEN - 1)); + } + /** * Creates and sets next thread name as " #" * on the specified thread. If no thread is specified (aThread