Bug 1323100 - Create a version of NS_NewNamedThread that accepts an nsACString. r?froydnj
MozReview-Commit-ID: LhRjdzZeWCB
--- a/xpcom/glue/nsThreadUtils.h
+++ b/xpcom/glue/nsThreadUtils.h
@@ -66,40 +66,52 @@ NS_SetThreadName(nsIThread* aThread, con
extern nsresult
NS_NewThread(nsIThread** aResult,
nsIRunnable* aInitialEvent = nullptr,
uint32_t aStackSize = nsIThreadManager::DEFAULT_STACK_SIZE);
/**
* Creates a named thread, otherwise the same as NS_NewThread
*/
-template<size_t LEN>
inline nsresult
-NS_NewNamedThread(const char (&aName)[LEN],
+NS_NewNamedThread(const nsACString& aName,
nsIThread** aResult,
nsIRunnable* aInitialEvent = nullptr,
uint32_t aStackSize = nsIThreadManager::DEFAULT_STACK_SIZE)
{
// Hold a ref while dispatching the initial event to match NS_NewThread()
nsCOMPtr<nsIThread> thread;
nsresult rv = NS_NewThread(getter_AddRefs(thread), nullptr, aStackSize);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
- NS_SetThreadName<LEN>(thread, aName);
+ NS_SetThreadName(thread, aName);
if (aInitialEvent) {
rv = thread->Dispatch(aInitialEvent, NS_DISPATCH_NORMAL);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Initial event dispatch failed");
}
*aResult = nullptr;
thread.swap(*aResult);
return rv;
}
+template<size_t LEN>
+inline nsresult
+NS_NewNamedThread(const char (&aName)[LEN],
+ nsIThread** aResult,
+ nsIRunnable* aInitialEvent = nullptr,
+ uint32_t aStackSize = nsIThreadManager::DEFAULT_STACK_SIZE)
+{
+ static_assert(LEN <= 16,
+ "Thread name must be no more than 16 characters");
+ return NS_NewNamedThread(nsDependentCString(aName, LEN - 1),
+ aResult, aInitialEvent, aStackSize);
+}
+
/**
* Get a reference to the current thread.
*
* @param aResult
* The resulting nsIThread object.
*/
extern nsresult NS_GetCurrentThread(nsIThread** aResult);