Bug 1323100 - Make NS_NewNamedThread use nsThreadManager::NewNamedThread. r?froydnj
MozReview-Commit-ID: 7e6l1A89he9
--- 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)
{