Bug 1491558 - Remove the XPCOM registration for nsThreadPool; r=froydnj

Differential Revision: https://phabricator.services.mozilla.com/D5943
This commit is contained in:
Ehsan Akhgari
2018-09-15 04:10:21 -04:00
parent b0186c1718
commit 8c6e3d874c
15 changed files with 22 additions and 43 deletions

View File

@@ -14,7 +14,7 @@
#include "mozilla/SyncRunnable.h" #include "mozilla/SyncRunnable.h"
#include "mozilla/Unused.h" #include "mozilla/Unused.h"
#include "gfxUtils.h" #include "gfxUtils.h"
#include "nsIThreadPool.h" #include "nsThreadPool.h"
#include "nsNetUtil.h" #include "nsNetUtil.h"
#include "nsXPCOMCIDInternal.h" #include "nsXPCOMCIDInternal.h"
#include "YCbCrUtils.h" #include "YCbCrUtils.h"
@@ -558,7 +558,7 @@ nsresult
ImageEncoder::EnsureThreadPool() ImageEncoder::EnsureThreadPool()
{ {
if (!sThreadPool) { if (!sThreadPool) {
nsCOMPtr<nsIThreadPool> threadPool = do_CreateInstance(NS_THREADPOOL_CONTRACTID); nsCOMPtr<nsIThreadPool> threadPool = new nsThreadPool();
sThreadPool = threadPool; sThreadPool = threadPool;
if (!NS_IsMainThread()) { if (!NS_IsMainThread()) {

View File

@@ -14,7 +14,7 @@
#include "nsXPCOMCIDInternal.h" #include "nsXPCOMCIDInternal.h"
#include "nsXPCOMPrivate.h" #include "nsXPCOMPrivate.h"
#include "nsIObserverService.h" #include "nsIObserverService.h"
#include "nsIThreadPool.h" #include "nsThreadPool.h"
namespace mozilla { namespace mozilla {
namespace dom { namespace dom {
@@ -73,7 +73,7 @@ WebCryptoThreadPool::DispatchInternal(nsIRunnable* aRunnable)
if (!mPool) { if (!mPool) {
NS_ENSURE_TRUE(EnsureNSSInitializedChromeOrContent(), NS_ERROR_FAILURE); NS_ENSURE_TRUE(EnsureNSSInitializedChromeOrContent(), NS_ERROR_FAILURE);
nsCOMPtr<nsIThreadPool> pool(do_CreateInstance(NS_THREADPOOL_CONTRACTID)); nsCOMPtr<nsIThreadPool> pool(new nsThreadPool());
NS_ENSURE_TRUE(pool, NS_ERROR_FAILURE); NS_ENSURE_TRUE(pool, NS_ERROR_FAILURE);
nsresult rv = pool->SetName(NS_LITERAL_CSTRING("SubtleCrypto")); nsresult rv = pool->SetName(NS_LITERAL_CSTRING("SubtleCrypto"));

View File

@@ -33,7 +33,3 @@ LOCAL_INCLUDES += [
] ]
FINAL_LIBRARY = 'xul' FINAL_LIBRARY = 'xul'
LOCAL_INCLUDES += [
'/xpcom/threads',
]

View File

@@ -107,7 +107,6 @@ LOCAL_INCLUDES += [
'/dom/storage', '/dom/storage',
'/ipc/glue', '/ipc/glue',
'/xpcom/build', '/xpcom/build',
'/xpcom/threads',
] ]
XPIDL_SOURCES += [ XPIDL_SOURCES += [

View File

@@ -16,7 +16,7 @@
#include "nsIPipe.h" #include "nsIPipe.h"
#include "nsITransport.h" #include "nsITransport.h"
#include "nsIObserverService.h" #include "nsIObserverService.h"
#include "nsIThreadPool.h" #include "nsThreadPool.h"
#include "mozilla/Services.h" #include "mozilla/Services.h"
namespace mozilla { namespace mozilla {
@@ -204,7 +204,7 @@ nsStreamTransportService::~nsStreamTransportService()
nsresult nsresult
nsStreamTransportService::Init() nsStreamTransportService::Init()
{ {
mPool = do_CreateInstance(NS_THREADPOOL_CONTRACTID); mPool = new nsThreadPool();
NS_ENSURE_STATE(mPool); NS_ENSURE_STATE(mPool);
// Configure the pool // Configure the pool

View File

@@ -31,6 +31,7 @@
#include "plstr.h" #include "plstr.h"
#include "nsURLHelper.h" #include "nsURLHelper.h"
#include "nsThreadUtils.h" #include "nsThreadUtils.h"
#include "nsThreadPool.h"
#include "GetAddrInfo.h" #include "GetAddrInfo.h"
#include "GeckoProfiler.h" #include "GeckoProfiler.h"
#include "TRR.h" #include "TRR.h"
@@ -632,7 +633,7 @@ nsHostResolver::Init()
0, 3600 * 1000); 0, 3600 * 1000);
} }
nsCOMPtr<nsIThreadPool> threadPool = do_CreateInstance(NS_THREADPOOL_CONTRACTID); nsCOMPtr<nsIThreadPool> threadPool = new nsThreadPool();
MOZ_ALWAYS_SUCCEEDS(threadPool->SetThreadLimit(MAX_RESOLVER_THREADS)); MOZ_ALWAYS_SUCCEEDS(threadPool->SetThreadLimit(MAX_RESOLVER_THREADS));
MOZ_ALWAYS_SUCCEEDS(threadPool->SetIdleThreadLimit(MAX_RESOLVER_THREADS)); MOZ_ALWAYS_SUCCEEDS(threadPool->SetIdleThreadLimit(MAX_RESOLVER_THREADS));
MOZ_ALWAYS_SUCCEEDS(threadPool->SetIdleThreadTimeout(poolTimeoutMs)); MOZ_ALWAYS_SUCCEEDS(threadPool->SetIdleThreadTimeout(poolTimeoutMs));

View File

@@ -121,7 +121,7 @@
#include "nsICertOverrideService.h" #include "nsICertOverrideService.h"
#include "nsISiteSecurityService.h" #include "nsISiteSecurityService.h"
#include "nsISocketProvider.h" #include "nsISocketProvider.h"
#include "nsIThreadPool.h" #include "nsThreadPool.h"
#include "nsNetUtil.h" #include "nsNetUtil.h"
#include "nsNSSCertificate.h" #include "nsNSSCertificate.h"
#include "nsNSSComponent.h" #include "nsNSSComponent.h"
@@ -165,14 +165,8 @@ void
InitializeSSLServerCertVerificationThreads() InitializeSSLServerCertVerificationThreads()
{ {
// TODO: tuning, make parameters preferences // TODO: tuning, make parameters preferences
// XXX: instantiate nsThreadPool directly, to make this more bulletproof. gCertVerificationThreadPool = new nsThreadPool();
// Currently, the nsThreadPool.h header isn't exported for us to do so. NS_ADDREF(gCertVerificationThreadPool);
nsresult rv = CallCreateInstance(NS_THREADPOOL_CONTRACTID,
&gCertVerificationThreadPool);
if (NS_FAILED(rv)) {
NS_WARNING("Failed to create SSL cert verification threads.");
return;
}
(void) gCertVerificationThreadPool->SetIdleThreadLimit(5); (void) gCertVerificationThreadPool->SetIdleThreadLimit(5);
(void) gCertVerificationThreadPool->SetIdleThreadTimeout(30 * 1000); (void) gCertVerificationThreadPool->SetIdleThreadTimeout(30 * 1000);

View File

@@ -242,8 +242,6 @@ nsThreadManagerGetSingleton(nsISupports* aOuter,
return nsThreadManager::get().QueryInterface(aIID, aInstancePtr); return nsThreadManager::get().QueryInterface(aIID, aInstancePtr);
} }
NS_GENERIC_FACTORY_CONSTRUCTOR(nsThreadPool)
nsComponentManagerImpl* nsComponentManagerImpl::gComponentManager = nullptr; nsComponentManagerImpl* nsComponentManagerImpl::gComponentManager = nullptr;
bool gXPCOMShuttingDown = false; bool gXPCOMShuttingDown = false;
bool gXPCOMThreadsShutDown = false; bool gXPCOMThreadsShutDown = false;

View File

@@ -49,7 +49,6 @@
COMPONENT(ENVIRONMENT, nsEnvironment::Create) COMPONENT(ENVIRONMENT, nsEnvironment::Create)
COMPONENT(THREADMANAGER, nsThreadManagerGetSingleton) COMPONENT(THREADMANAGER, nsThreadManagerGetSingleton)
COMPONENT_M(THREADPOOL, nsThreadPoolConstructor, Module::ALLOW_IN_GPU_PROCESS)
COMPONENT(STRINGINPUTSTREAM, nsStringInputStreamConstructor) COMPONENT(STRINGINPUTSTREAM, nsStringInputStreamConstructor)
COMPONENT(MULTIPLEXINPUTSTREAM, nsMultiplexInputStreamConstructor) COMPONENT(MULTIPLEXINPUTSTREAM, nsMultiplexInputStreamConstructor)

View File

@@ -33,12 +33,6 @@
*/ */
#define NS_THREADMANAGER_CONTRACTID "@mozilla.org/thread-manager;1" #define NS_THREADMANAGER_CONTRACTID "@mozilla.org/thread-manager;1"
/**
* A thread pool component.
* @implements nsIThreadPool
*/
#define NS_THREADPOOL_CONTRACTID "@mozilla.org/thread-pool;1"
/** /**
* The contract id for the nsIXULAppInfo service. * The contract id for the nsIXULAppInfo service.
*/ */

View File

@@ -10,7 +10,7 @@
#include "mozilla/ThrottledEventQueue.h" #include "mozilla/ThrottledEventQueue.h"
#include "nsComponentManagerUtils.h" #include "nsComponentManagerUtils.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsIThreadPool.h" #include "nsThreadPool.h"
#include "nsThreadUtils.h" #include "nsThreadUtils.h"
#include "nsXPCOM.h" #include "nsXPCOM.h"
#include "nsXPCOMCIDInternal.h" #include "nsXPCOMCIDInternal.h"
@@ -20,7 +20,7 @@ using namespace mozilla;
TEST(TestEventTargetQI, ThreadPool) TEST(TestEventTargetQI, ThreadPool)
{ {
nsCOMPtr<nsIThreadPool> thing = do_CreateInstance(NS_THREADPOOL_CONTRACTID); nsCOMPtr<nsIThreadPool> thing = new nsThreadPool();
EXPECT_TRUE(thing); EXPECT_TRUE(thing);
nsCOMPtr<nsISerialEventTarget> serial = do_QueryInterface(thing); nsCOMPtr<nsISerialEventTarget> serial = do_QueryInterface(thing);

View File

@@ -8,7 +8,7 @@
#include <stdlib.h> #include <stdlib.h>
#include "nsXPCOM.h" #include "nsXPCOM.h"
#include "nsXPCOMCIDInternal.h" #include "nsXPCOMCIDInternal.h"
#include "nsIThreadPool.h" #include "nsThreadPool.h"
#include "nsComponentManagerUtils.h" #include "nsComponentManagerUtils.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsIRunnable.h" #include "nsIRunnable.h"
@@ -49,7 +49,7 @@ mozilla::Atomic<int> Task::sCount;
TEST(ThreadPool, Main) TEST(ThreadPool, Main)
{ {
nsCOMPtr<nsIThreadPool> pool = do_CreateInstance(NS_THREADPOOL_CONTRACTID); nsCOMPtr<nsIThreadPool> pool = new nsThreadPool();
EXPECT_TRUE(pool); EXPECT_TRUE(pool);
for (int i = 0; i < 100; ++i) { for (int i = 0; i < 100; ++i) {
@@ -65,7 +65,7 @@ TEST(ThreadPool, Main)
TEST(ThreadPool, Parallelism) TEST(ThreadPool, Parallelism)
{ {
nsCOMPtr<nsIThreadPool> pool = do_CreateInstance(NS_THREADPOOL_CONTRACTID); nsCOMPtr<nsIThreadPool> pool = new nsThreadPool();
EXPECT_TRUE(pool); EXPECT_TRUE(pool);
// Dispatch and sleep to ensure we have an idle thread // Dispatch and sleep to ensure we have an idle thread

View File

@@ -4,9 +4,9 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsIThread.h" #include "nsIThread.h"
#include "nsIThreadPool.h"
#include "nsComponentManagerUtils.h" #include "nsComponentManagerUtils.h"
#include "nsThreadPool.h"
#include "nsThreadUtils.h" #include "nsThreadUtils.h"
#include "nsXPCOMCIDInternal.h" #include "nsXPCOMCIDInternal.h"
#include "pratom.h" #include "pratom.h"
@@ -136,9 +136,7 @@ TEST(ThreadPoolListener, Test)
nsresult rv; nsresult rv;
nsCOMPtr<nsIThreadPool> pool = nsCOMPtr<nsIThreadPool> pool = new nsThreadPool();
do_CreateInstance(NS_THREADPOOL_CONTRACTID, &rv);
ASSERT_TRUE(NS_SUCCEEDED(rv));
rv = pool->SetThreadLimit(NUMBER_OF_THREADS); rv = pool->SetThreadLimit(NUMBER_OF_THREADS);
ASSERT_TRUE(NS_SUCCEEDED(rv)); ASSERT_TRUE(NS_SUCCEEDED(rv));

View File

@@ -15,6 +15,7 @@
#include "nsIObserver.h" #include "nsIObserver.h"
#include "nsIObserverService.h" #include "nsIObserverService.h"
#include "nsIThreadManager.h" #include "nsIThreadManager.h"
#include "nsThreadPool.h"
#ifdef XP_WIN #ifdef XP_WIN
#include "ThreadPoolCOMListener.h" #include "ThreadPoolCOMListener.h"
#endif #endif
@@ -225,11 +226,9 @@ SharedThreadPool::EnsureThreadLimitIsAtLeast(uint32_t aLimit)
static already_AddRefed<nsIThreadPool> static already_AddRefed<nsIThreadPool>
CreateThreadPool(const nsCString& aName) CreateThreadPool(const nsCString& aName)
{ {
nsresult rv; nsCOMPtr<nsIThreadPool> pool = new nsThreadPool();
nsCOMPtr<nsIThreadPool> pool = do_CreateInstance(NS_THREADPOOL_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, nullptr);
rv = pool->SetName(aName); nsresult rv = pool->SetName(aName);
NS_ENSURE_SUCCESS(rv, nullptr); NS_ENSURE_SUCCESS(rv, nullptr);
rv = pool->SetThreadStackSize(nsIThreadManager::kThreadPoolStackSize); rv = pool->SetThreadStackSize(nsIThreadManager::kThreadPoolStackSize);

View File

@@ -32,6 +32,7 @@ EXPORTS += [
'nsProxyRelease.h', 'nsProxyRelease.h',
'nsThread.h', 'nsThread.h',
'nsThreadManager.h', 'nsThreadManager.h',
'nsThreadPool.h',
'nsThreadUtils.h', 'nsThreadUtils.h',
] ]