Bug 968016 - Add threadStackSize attribute to nsIThreadPool. r=bsmedberg

This commit is contained in:
Chris Pearce 2014-02-18 11:53:53 +13:00
parent aa8aee7920
commit 8d5deb7730
4 changed files with 33 additions and 4 deletions

View File

@ -244,6 +244,9 @@ CreateThreadPool(const nsCString& aName)
rv = pool->SetName(aName);
NS_ENSURE_SUCCESS(rv, nullptr);
rv = pool->SetThreadStackSize(MEDIA_THREAD_STACK_SIZE);
NS_ENSURE_SUCCESS(rv, nullptr);
#ifdef XP_WIN
// Ensure MSCOM is initialized on the thread pools threads.
nsCOMPtr<nsIThreadPoolListener> listener = new MSCOMInitThreadPoolListener();

View File

@ -27,7 +27,7 @@ interface nsIThreadPoolListener : nsISupports
* anonymous (unnamed) worker threads. An event dispatched to the thread pool
* will be run on the next available worker thread.
*/
[scriptable, uuid(ba9a466b-8d4a-4b33-ae5c-6ed751068c90)]
[scriptable, uuid(53675068-cb3a-40e5-a026-1be5a97c9b23)]
interface nsIThreadPool : nsIEventTarget
{
/**
@ -43,7 +43,7 @@ interface nsIThreadPool : nsIEventTarget
/**
* Get/set the maximum number of threads allowed at one time in this pool.
*/
*/
attribute unsigned long threadLimit;
/**
@ -57,6 +57,12 @@ interface nsIThreadPool : nsIEventTarget
*/
attribute unsigned long idleThreadTimeout;
/**
* Get/set the number of bytes reserved for the stack of all threads in
* the pool. By default this is nsIThreadManager::DEFAULT_STACK_SIZE.
*/
attribute unsigned long threadStackSize;
/**
* An optional listener that will be notified when a thread is created or
* destroyed in the course of the thread pool's operation.

View File

@ -52,6 +52,7 @@ nsThreadPool::nsThreadPool()
: mThreadLimit(DEFAULT_THREAD_LIMIT)
, mIdleThreadLimit(DEFAULT_IDLE_THREAD_LIMIT)
, mIdleThreadTimeout(DEFAULT_IDLE_THREAD_TIMEOUT)
, mStackSize(nsIThreadManager::DEFAULT_STACK_SIZE)
, mIdleCount(0)
, mShutdown(false)
{
@ -68,8 +69,9 @@ nsresult
nsThreadPool::PutEvent(nsIRunnable *event)
{
// Avoid spawning a new thread while holding the event queue lock...
bool spawnThread = false;
uint32_t stackSize = 0;
{
ReentrantMonitorAutoEnter mon(mEvents.GetReentrantMonitor());
@ -82,6 +84,7 @@ nsThreadPool::PutEvent(nsIRunnable *event)
spawnThread = true;
mEvents.PutEvent(event);
stackSize = mStackSize;
}
LOG(("THRD-P(%p) put [spawn=%d]\n", this, spawnThread));
@ -90,7 +93,7 @@ nsThreadPool::PutEvent(nsIRunnable *event)
nsCOMPtr<nsIThread> thread;
nsThreadManager::get()->NewThread(0,
nsIThreadManager::DEFAULT_STACK_SIZE,
stackSize,
getter_AddRefs(thread));
if (NS_WARN_IF(!thread))
return NS_ERROR_UNEXPECTED;
@ -355,6 +358,22 @@ nsThreadPool::SetIdleThreadTimeout(uint32_t value)
return NS_OK;
}
NS_IMETHODIMP
nsThreadPool::GetThreadStackSize(uint32_t* value)
{
ReentrantMonitorAutoEnter mon(mEvents.GetReentrantMonitor());
*value = mStackSize;
return NS_OK;
}
NS_IMETHODIMP
nsThreadPool::SetThreadStackSize(uint32_t value)
{
ReentrantMonitorAutoEnter mon(mEvents.GetReentrantMonitor());
mStackSize = value;
return NS_OK;
}
NS_IMETHODIMP
nsThreadPool::GetListener(nsIThreadPoolListener** aListener)
{

View File

@ -39,6 +39,7 @@ private:
uint32_t mIdleThreadLimit;
uint32_t mIdleThreadTimeout;
uint32_t mIdleCount;
uint32_t mStackSize;
nsCOMPtr<nsIThreadPoolListener> mListener;
bool mShutdown;
nsCString mName;