Bug 1190496 - Remove dependency on VideoUtils.h for stack size. r=cpearce
authorBobby Holley <bobbyholley@gmail.com>
Mon, 03 Aug 2015 11:39:45 -0700
changeset 287863 47350b936bdf6c2a1b3a5ecb4d492b1c3c8ad806
parent 287862 c4dc03f004d602576c19243cb1963130e6e5a9a4
child 287864 4b540d54de839ba764b7bc815b39390d2b090dc2
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce
bugs1190496
milestone42.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1190496 - Remove dependency on VideoUtils.h for stack size. r=cpearce
dom/media/AudioSink.cpp
dom/media/FileBlockCache.cpp
dom/media/SharedThreadPool.cpp
dom/media/SharedThreadPool.h
dom/media/VideoUtils.h
--- a/dom/media/AudioSink.cpp
+++ b/dom/media/AudioSink.cpp
@@ -85,17 +85,17 @@ AudioSink::ScheduleNextLoopCrossThread()
 
 nsRefPtr<GenericPromise>
 AudioSink::Init()
 {
   nsRefPtr<GenericPromise> p = mEndPromise.Ensure(__func__);
   nsresult rv = NS_NewNamedThread("Media Audio",
                                   getter_AddRefs(mThread),
                                   nullptr,
-                                  MEDIA_THREAD_STACK_SIZE);
+                                  SharedThreadPool::kStackSize);
   if (NS_FAILED(rv)) {
     mEndPromise.Reject(rv, __func__);
     return p;
   }
 
   ScheduleNextLoopCrossThread();
   return p;
 }
--- a/dom/media/FileBlockCache.cpp
+++ b/dom/media/FileBlockCache.cpp
@@ -18,17 +18,17 @@ nsresult FileBlockCache::Open(PRFileDesc
   {
     MonitorAutoLock mon(mFileMonitor);
     mFD = aFD;
   }
   {
     MonitorAutoLock mon(mDataMonitor);
     nsresult res = NS_NewThread(getter_AddRefs(mThread),
                                 nullptr,
-                                MEDIA_THREAD_STACK_SIZE);
+                                SharedThreadPool::kStackSize);
     mIsOpen = NS_SUCCEEDED(res);
     return res;
   }
 }
 
 FileBlockCache::FileBlockCache()
   : mFileMonitor("MediaCache.Writer.IO.Monitor"),
     mFD(nullptr),
--- a/dom/media/SharedThreadPool.cpp
+++ b/dom/media/SharedThreadPool.cpp
@@ -2,19 +2,19 @@
 /* vim:set ts=2 sw=2 sts=2 et cindent: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "SharedThreadPool.h"
 #include "mozilla/ClearOnShutdown.h"
 #include "mozilla/Monitor.h"
+#include "mozilla/ReentrantMonitor.h"
 #include "mozilla/StaticPtr.h"
 #include "nsDataHashtable.h"
-#include "VideoUtils.h"
 #include "nsXPCOMCIDInternal.h"
 #include "nsComponentManagerUtils.h"
 #ifdef XP_WIN
 #include "ThreadPoolCOMListener.h"
 #endif
 
 namespace mozilla {
 
@@ -142,17 +142,17 @@ SharedThreadPool::SharedThreadPool(const
 SharedThreadPool::~SharedThreadPool()
 {
   MOZ_COUNT_DTOR(SharedThreadPool);
 }
 
 nsresult
 SharedThreadPool::EnsureThreadLimitIsAtLeast(uint32_t aLimit)
 {
-  // We limit the number of threads that we use for media. Note that we
+  // We limit the number of threads that we use. Note that we
   // set the thread limit to the same as the idle limit so that we're not
   // constantly creating and destroying threads (see Bug 881954). When the
   // thread pool threads shutdown they dispatch an event to the main thread
   // to call nsIThread::Shutdown(), and if we're very busy that can take a
   // while to run, and we end up with dozens of extra threads. Note that
   // threads that are idle for 60 seconds are shutdown naturally.
   uint32_t existingLimit = 0;
   nsresult rv;
@@ -179,17 +179,17 @@ CreateThreadPool(const nsCString& aName)
 {
   nsresult rv;
   nsCOMPtr<nsIThreadPool> pool = do_CreateInstance(NS_THREADPOOL_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, nullptr);
 
   rv = pool->SetName(aName);
   NS_ENSURE_SUCCESS(rv, nullptr);
 
-  rv = pool->SetThreadStackSize(MEDIA_THREAD_STACK_SIZE);
+  rv = pool->SetThreadStackSize(SharedThreadPool::kStackSize);
   NS_ENSURE_SUCCESS(rv, nullptr);
 
 #ifdef XP_WIN
   // Ensure MSCOM is initialized on the thread pools threads.
   nsCOMPtr<nsIThreadPoolListener> listener = new MSCOMInitThreadPoolListener();
   rv = pool->SetListener(listener);
   NS_ENSURE_SUCCESS(rv, nullptr);
 #endif
--- a/dom/media/SharedThreadPool.h
+++ b/dom/media/SharedThreadPool.h
@@ -5,16 +5,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef SharedThreadPool_h_
 #define SharedThreadPool_h_
 
 #include <queue>
 #include "mozilla/RefPtr.h"
 #include "nsThreadUtils.h"
+#include "nsIThreadManager.h"
 #include "nsIThreadPool.h"
 #include "nsISupports.h"
 #include "nsISupportsImpl.h"
 #include "nsCOMPtr.h"
 
 namespace mozilla {
 
 // Wrapper that makes an nsIThreadPool a singleton, and provides a
@@ -61,16 +62,27 @@ public:
 
   // Creates necessary statics. Called once at startup.
   static void InitStatics();
 
   // Spins the event loop until all thread pools are shutdown.
   // *Must* be called on the main thread.
   static void SpinUntilEmpty();
 
+#if defined(MOZ_ASAN)
+  // Use the system default in ASAN builds, because the default is assumed to be
+  // larger than the size we want to use and is hopefully sufficient for ASAN.
+  static const uint32_t kStackSize = nsIThreadManager::DEFAULT_STACK_SIZE;
+#elif defined(XP_WIN) || defined(XP_MACOSX) || defined(LINUX)
+  static const uint32_t kStackSize = (256 * 1024);
+#else
+  // All other platforms use their system defaults.
+  static const uint32_t kStackSize = nsIThreadManager::DEFAULT_STACK_SIZE;
+#endif
+
 private:
 
   // Returns whether there are no pools in existence at the moment.
   static bool IsEmpty();
 
   // Creates a singleton SharedThreadPool wrapper around aPool.
   // aName is the name of the aPool, and is used to lookup the
   // SharedThreadPool in the hash table of all created pools.
--- a/dom/media/VideoUtils.h
+++ b/dom/media/VideoUtils.h
@@ -12,21 +12,16 @@
 #include "mozilla/MozPromise.h"
 #include "mozilla/ReentrantMonitor.h"
 #include "mozilla/RefPtr.h"
 
 #include "nsIThread.h"
 #include "nsSize.h"
 #include "nsRect.h"
 
-#if !(defined(XP_WIN) || defined(XP_MACOSX) || defined(LINUX)) || \
-    defined(MOZ_ASAN)
-// For MEDIA_THREAD_STACK_SIZE
-#include "nsIThreadManager.h"
-#endif
 #include "nsThreadUtils.h"
 #include "prtime.h"
 #include "AudioSampleFormat.h"
 #include "TimeUnits.h"
 
 using mozilla::CheckedInt64;
 using mozilla::CheckedUint64;
 using mozilla::CheckedInt32;
@@ -160,28 +155,16 @@ nsresult SecondsToUsecs(double aSeconds,
 static const int32_t MAX_VIDEO_WIDTH = 4000;
 static const int32_t MAX_VIDEO_HEIGHT = 3000;
 
 // Scales the display rect aDisplay by aspect ratio aAspectRatio.
 // Note that aDisplay must be validated by IsValidVideoRegion()
 // before being used!
 void ScaleDisplayByAspectRatio(nsIntSize& aDisplay, float aAspectRatio);
 
-// The amount of virtual memory reserved for thread stacks.
-#if defined(MOZ_ASAN)
-// Use the system default in ASAN builds, because the default is assumed to be
-// larger than the size we want to use and is hopefully sufficient for ASAN.
-#define MEDIA_THREAD_STACK_SIZE nsIThreadManager::DEFAULT_STACK_SIZE
-#elif defined(XP_WIN) || defined(XP_MACOSX) || defined(LINUX)
-#define MEDIA_THREAD_STACK_SIZE (256 * 1024)
-#else
-// All other platforms use their system defaults.
-#define MEDIA_THREAD_STACK_SIZE nsIThreadManager::DEFAULT_STACK_SIZE
-#endif
-
 // Downmix multichannel Audio samples to Stereo.
 // Input are the buffer contains multichannel data,
 // the number of channels and the number of frames.
 int DownmixAudioToStereo(mozilla::AudioDataValue* buffer,
                          int channels,
                          uint32_t frames);
 
 bool IsVideoContentType(const nsCString& aContentType);