Bug 1323100 - Create a version of NS_NewNamedThread that accepts an nsACString. r?froydnj draft
authorMarkus Stange <mstange@themasta.com>
Thu, 22 Dec 2016 00:05:51 +0100
changeset 456874 f0f368530cff86959cfc59c3f6a9ea59236b823e
parent 456873 5a1c5ae09ae0d43083b3e36956ff115915429c66
child 456875 591fba4a8a1803f4449a2c32dc4b9c8c5c3ca2e4
push id40636
push userbmo:mstange@themasta.com
push dateFri, 06 Jan 2017 12:38:48 +0000
reviewersfroydnj
bugs1323100
milestone53.0a1
Bug 1323100 - Create a version of NS_NewNamedThread that accepts an nsACString. r?froydnj MozReview-Commit-ID: LhRjdzZeWCB
xpcom/glue/nsThreadUtils.h
--- 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);