Bug 1323100 - Make NS_NewNamedThread use nsThreadManager::NewNamedThread. r?froydnj draft
authorMarkus Stange <mstange@themasta.com>
Tue, 20 Dec 2016 14:18:22 +0100
changeset 456885 e31e965d18dccbf9fdc5f98feb8f721139c099f7
parent 456884 bd93ef94d0b494db38464df65ed14a0c000b639c
child 456886 16f75b1ed9f65b89a4b8418b7e4a14240a35331d
push id40636
push userbmo:mstange@themasta.com
push dateFri, 06 Jan 2017 12:38:48 +0000
reviewersfroydnj
bugs1323100
milestone53.0a1
Bug 1323100 - Make NS_NewNamedThread use nsThreadManager::NewNamedThread. r?froydnj MozReview-Commit-ID: 7e6l1A89he9
xpcom/glue/nsThreadUtils.cpp
xpcom/glue/nsThreadUtils.h
--- a/xpcom/glue/nsThreadUtils.cpp
+++ b/xpcom/glue/nsThreadUtils.cpp
@@ -90,32 +90,35 @@ IncrementalRunnable::SetDeadline(TimeSta
   // Do nothing
 }
 
 #endif  // XPCOM_GLUE_AVOID_NSPR
 
 //-----------------------------------------------------------------------------
 
 nsresult
-NS_NewThread(nsIThread** aResult, nsIRunnable* aEvent, uint32_t aStackSize)
+NS_NewNamedThread(const nsACString& aName,
+                  nsIThread** aResult,
+                  nsIRunnable* aEvent,
+                  uint32_t aStackSize)
 {
   nsCOMPtr<nsIThread> thread;
 #ifdef MOZILLA_INTERNAL_API
   nsresult rv =
-    nsThreadManager::get().nsThreadManager::NewThread(0, aStackSize,
-                                                      getter_AddRefs(thread));
+    nsThreadManager::get().nsThreadManager::NewNamedThread(aName, aStackSize,
+                                                           getter_AddRefs(thread));
 #else
   nsresult rv;
   nsCOMPtr<nsIThreadManager> mgr =
     do_GetService(NS_THREADMANAGER_CONTRACTID, &rv);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = mgr->NewThread(0, aStackSize, getter_AddRefs(thread));
+  rv = mgr->NewNamedThread(aName, aStackSize, getter_AddRefs(thread));
 #endif
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   if (aEvent) {
     rv = thread->Dispatch(aEvent, NS_DISPATCH_NORMAL);
     if (NS_WARN_IF(NS_FAILED(rv))) {
@@ -124,16 +127,22 @@ NS_NewThread(nsIThread** aResult, nsIRun
   }
 
   *aResult = nullptr;
   thread.swap(*aResult);
   return NS_OK;
 }
 
 nsresult
+NS_NewThread(nsIThread** aResult, nsIRunnable* aEvent, uint32_t aStackSize)
+{
+  return NS_NewNamedThread(NS_LITERAL_CSTRING(""), aResult, aEvent, aStackSize);
+}
+
+nsresult
 NS_GetCurrentThread(nsIThread** aResult)
 {
 #ifdef MOZILLA_INTERNAL_API
   return nsThreadManager::get().nsThreadManager::GetCurrentThread(aResult);
 #else
   nsresult rv;
   nsCOMPtr<nsIThreadManager> mgr =
     do_GetService(NS_THREADMANAGER_CONTRACTID, &rv);
--- a/xpcom/glue/nsThreadUtils.h
+++ b/xpcom/glue/nsThreadUtils.h
@@ -66,38 +66,21 @@ 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
  */
-inline nsresult
+extern nsresult
 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(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;
-}
+                  uint32_t aStackSize = nsIThreadManager::DEFAULT_STACK_SIZE);
 
 template<size_t LEN>
 inline nsresult
 NS_NewNamedThread(const char (&aName)[LEN],
                   nsIThread** aResult,
                   nsIRunnable* aInitialEvent = nullptr,
                   uint32_t aStackSize = nsIThreadManager::DEFAULT_STACK_SIZE)
 {