diff --git a/dom/media/AudioSink.cpp b/dom/media/AudioSink.cpp index 522a4c33b64c..a60ba86f91c7 100644 --- a/dom/media/AudioSink.cpp +++ b/dom/media/AudioSink.cpp @@ -90,7 +90,7 @@ AudioSink::Init() 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; diff --git a/dom/media/FileBlockCache.cpp b/dom/media/FileBlockCache.cpp index 4cc9ef219c19..b17f25aa0582 100644 --- a/dom/media/FileBlockCache.cpp +++ b/dom/media/FileBlockCache.cpp @@ -23,7 +23,7 @@ nsresult FileBlockCache::Open(PRFileDesc* aFD) MonitorAutoLock mon(mDataMonitor); nsresult res = NS_NewThread(getter_AddRefs(mThread), nullptr, - MEDIA_THREAD_STACK_SIZE); + SharedThreadPool::kStackSize); mIsOpen = NS_SUCCEEDED(res); return res; } diff --git a/dom/media/SharedThreadPool.cpp b/dom/media/SharedThreadPool.cpp index 4098d9e71114..cde6eca41b32 100644 --- a/dom/media/SharedThreadPool.cpp +++ b/dom/media/SharedThreadPool.cpp @@ -7,9 +7,9 @@ #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 @@ -147,7 +147,7 @@ SharedThreadPool::~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 @@ -184,7 +184,7 @@ CreateThreadPool(const nsCString& aName) 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 diff --git a/dom/media/SharedThreadPool.h b/dom/media/SharedThreadPool.h index f93f1c5006a2..331773c4f1f2 100644 --- a/dom/media/SharedThreadPool.h +++ b/dom/media/SharedThreadPool.h @@ -10,6 +10,7 @@ #include #include "mozilla/RefPtr.h" #include "nsThreadUtils.h" +#include "nsIThreadManager.h" #include "nsIThreadPool.h" #include "nsISupports.h" #include "nsISupportsImpl.h" @@ -66,6 +67,17 @@ public: // *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. diff --git a/dom/media/VideoUtils.h b/dom/media/VideoUtils.h index 197061f59676..0b9452dea34b 100644 --- a/dom/media/VideoUtils.h +++ b/dom/media/VideoUtils.h @@ -17,11 +17,6 @@ #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" @@ -165,18 +160,6 @@ static const int32_t MAX_VIDEO_HEIGHT = 3000; // 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.