Bug 1390681 - Use NS_DISPATCH_AT_END when dispatching crypto tasks to the thread pool, so that we don't launch new threads if all threads are busy. r?bkelly draft
authorMarkus Stange <mstange@themasta.com>
Tue, 15 Aug 2017 19:00:35 -0400
changeset 647652 53414ce6361c1d4e5f2f55888d3e0837cbe68133
parent 647651 8fc2fe003e4ff7b95378097ba5d04c83252f7b6f
child 726585 579422e84250190a01284fd5be148a15f75b8f1d
push id74490
push userbmo:mstange@themasta.com
push dateWed, 16 Aug 2017 17:54:11 +0000
reviewersbkelly
bugs1390681
milestone57.0a1
Bug 1390681 - Use NS_DISPATCH_AT_END when dispatching crypto tasks to the thread pool, so that we don't launch new threads if all threads are busy. r?bkelly MozReview-Commit-ID: 8sgZ4LHQbac
dom/crypto/WebCryptoThreadPool.cpp
--- a/dom/crypto/WebCryptoThreadPool.cpp
+++ b/dom/crypto/WebCryptoThreadPool.cpp
@@ -71,17 +71,24 @@ WebCryptoThreadPool::DispatchInternal(ns
     NS_ENSURE_TRUE(pool, NS_ERROR_FAILURE);
 
     nsresult rv = pool->SetName(NS_LITERAL_CSTRING("SubtleCrypto"));
     NS_ENSURE_SUCCESS(rv, rv);
 
     pool.swap(mPool);
   }
 
-  return mPool->Dispatch(aRunnable, NS_DISPATCH_NORMAL);
+  // Use NS_DISPATCH_AT_END instead of NS_DISPATCH_NORMAL.
+  // NS_DISPATCH_NORMAL causes the thread pool to try hard to service the event
+  // immediately, and if all threads are currently busy, it will spin up a new
+  // thread. But we don't want any extra threads to be created.
+  // NS_DISPATCH_AT_END gives the behavior you'd expect of a thread pool: the
+  // event is simply queued at the end and serviced by the first available
+  // thread.
+  return mPool->Dispatch(aRunnable, NS_DISPATCH_AT_END);
 }
 
 void
 WebCryptoThreadPool::Shutdown()
 {
   MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
   MutexAutoLock lock(mMutex);