2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* 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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsIClassInfoImpl.h"
|
|
|
|
#include "nsThreadPool.h"
|
|
|
|
#include "nsThreadManager.h"
|
|
|
|
#include "nsThread.h"
|
|
|
|
#include "nsMemory.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "prinrval.h"
|
|
|
|
#include "prlog.h"
|
2013-10-23 13:31:15 -07:00
|
|
|
#include "mozilla/DebugOnly.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-03-31 21:29:02 -07:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef PR_LOGGING
|
2012-10-29 16:32:10 -07:00
|
|
|
static PRLogModuleInfo *
|
|
|
|
GetThreadPoolLog()
|
|
|
|
{
|
|
|
|
static PRLogModuleInfo *sLog;
|
|
|
|
if (!sLog)
|
|
|
|
sLog = PR_NewLogModule("nsThreadPool");
|
|
|
|
return sLog;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
2012-10-29 16:32:10 -07:00
|
|
|
#define LOG(args) PR_LOG(GetThreadPoolLog(), PR_LOG_DEBUG, args)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// DESIGN:
|
|
|
|
// o Allocate anonymous threads.
|
|
|
|
// o Use nsThreadPool::Run as the main routine for each thread.
|
|
|
|
// o Each thread waits on the event queue's monitor, checking for
|
|
|
|
// pending events and rescheduling itself as an idle thread.
|
|
|
|
|
|
|
|
#define DEFAULT_THREAD_LIMIT 4
|
|
|
|
#define DEFAULT_IDLE_THREAD_LIMIT 1
|
|
|
|
#define DEFAULT_IDLE_THREAD_TIMEOUT PR_SecondsToInterval(60)
|
|
|
|
|
2013-07-18 19:31:26 -07:00
|
|
|
NS_IMPL_ADDREF(nsThreadPool)
|
|
|
|
NS_IMPL_RELEASE(nsThreadPool)
|
2013-10-10 13:42:16 -07:00
|
|
|
NS_IMPL_CLASSINFO(nsThreadPool, nullptr, nsIClassInfo::THREADSAFE,
|
2010-06-22 09:59:57 -07:00
|
|
|
NS_THREADPOOL_CID)
|
2013-10-23 13:31:15 -07:00
|
|
|
NS_IMPL_QUERY_INTERFACE2_CI(nsThreadPool, nsIThreadPool, nsIEventTarget)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMPL_CI_INTERFACE_GETTER2(nsThreadPool, nsIThreadPool, nsIEventTarget)
|
|
|
|
|
|
|
|
nsThreadPool::nsThreadPool()
|
|
|
|
: mThreadLimit(DEFAULT_THREAD_LIMIT)
|
|
|
|
, mIdleThreadLimit(DEFAULT_IDLE_THREAD_LIMIT)
|
|
|
|
, mIdleThreadTimeout(DEFAULT_IDLE_THREAD_TIMEOUT)
|
|
|
|
, mIdleCount(0)
|
2011-10-17 07:59:28 -07:00
|
|
|
, mShutdown(false)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsThreadPool::~nsThreadPool()
|
|
|
|
{
|
2013-10-23 11:21:37 -07:00
|
|
|
// Threads keep a reference to the nsThreadPool until they return from Run()
|
|
|
|
// after removing themselves from mThreads.
|
|
|
|
MOZ_ASSERT(mThreads.IsEmpty());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsThreadPool::PutEvent(nsIRunnable *event)
|
|
|
|
{
|
|
|
|
// Avoid spawning a new thread while holding the event queue lock...
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool spawnThread = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-04-29 12:21:57 -07:00
|
|
|
ReentrantMonitorAutoEnter mon(mEvents.GetReentrantMonitor());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-10-23 13:31:15 -07:00
|
|
|
LOG(("THRD-P(%p) put [%d %u %d]\n", this, mIdleCount, mThreads.Length(),
|
2007-03-22 10:30:00 -07:00
|
|
|
mThreadLimit));
|
2013-10-23 13:31:15 -07:00
|
|
|
MOZ_ASSERT(mIdleCount <= mThreads.Length(), "oops");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Make sure we have a thread to service this event.
|
2013-10-23 13:31:15 -07:00
|
|
|
if (mIdleCount == 0 && mThreads.Length() < mThreadLimit) {
|
|
|
|
// Run() will replace this with the real PRThread*
|
|
|
|
mThreads.AppendElement<PRThread*>(nullptr);
|
2011-10-17 07:59:28 -07:00
|
|
|
spawnThread = true;
|
2013-10-23 13:31:15 -07:00
|
|
|
} else {
|
|
|
|
mEvents.PutEvent(event);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
LOG(("THRD-P(%p) put [spawn=%d]\n", this, spawnThread));
|
|
|
|
if (!spawnThread)
|
|
|
|
return NS_OK;
|
|
|
|
|
2013-10-23 13:31:15 -07:00
|
|
|
NS_ADDREF_THIS(); // Released in ThreadFunc
|
|
|
|
PRThread* thread = PR_CreateThread(PR_USER_THREAD, ThreadFunc, this,
|
|
|
|
PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD,
|
|
|
|
PR_JOINABLE_THREAD, 0);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
{
|
2011-04-29 12:21:57 -07:00
|
|
|
ReentrantMonitorAutoEnter mon(mEvents.GetReentrantMonitor());
|
2013-10-23 13:31:15 -07:00
|
|
|
if (!thread) {
|
|
|
|
NS_WARNING("PR_CreateThread() failed");
|
|
|
|
NS_RELEASE_THIS();
|
|
|
|
mThreads.RemoveElement<PRThread*>(nullptr);
|
|
|
|
if (mThreads.IsEmpty())
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2013-10-23 13:31:15 -07:00
|
|
|
|
|
|
|
mEvents.PutEvent(event);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-10-23 13:31:15 -07:00
|
|
|
nsThreadPool::ShutdownThread(PRThread *thread)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
LOG(("THRD-P(%p) shutdown async [%p]\n", this, thread));
|
|
|
|
|
|
|
|
// This method is responsible for calling Shutdown on |thread|. This must be
|
|
|
|
// done from some other thread, so we use the main thread of the application.
|
|
|
|
|
2013-02-07 21:54:20 -08:00
|
|
|
MOZ_ASSERT(!NS_IsMainThread(), "wrong thread");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-10-23 13:31:15 -07:00
|
|
|
class JoinEvent MOZ_FINAL : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit JoinEvent(PRThread *thread) : mThread(thread) { }
|
|
|
|
|
|
|
|
NS_IMETHODIMP Run() MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
DebugOnly<PRStatus> status = PR_JoinThread(mThread);
|
|
|
|
MOZ_ASSERT(status == PR_SUCCESS, "PR_JoinThread failed");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
PRThread *mThread;
|
|
|
|
};
|
|
|
|
|
|
|
|
nsRefPtr<nsIRunnable> r = new JoinEvent(thread);
|
2012-01-11 08:28:21 -08:00
|
|
|
NS_DispatchToMainThread(r);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-10-23 13:31:15 -07:00
|
|
|
/*static*/ void
|
|
|
|
nsThreadPool::ThreadFunc(void *arg)
|
|
|
|
{
|
|
|
|
auto self = static_cast<nsThreadPool*>(arg); // strong reference
|
|
|
|
self->Run();
|
|
|
|
NS_RELEASE(self); // Reference added on thread creation
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsThreadPool::Run()
|
|
|
|
{
|
|
|
|
LOG(("THRD-P(%p) enter\n", this));
|
|
|
|
|
2012-06-12 10:06:20 -07:00
|
|
|
mThreadNaming.SetThreadPoolName(mName);
|
|
|
|
|
2013-10-23 13:31:15 -07:00
|
|
|
PRThread* current = PR_GetCurrentThread();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-08-11 17:01:47 -07:00
|
|
|
nsCOMPtr<nsIThreadPoolListener> listener;
|
|
|
|
{
|
2011-04-29 12:21:57 -07:00
|
|
|
ReentrantMonitorAutoEnter mon(mEvents.GetReentrantMonitor());
|
2013-10-23 13:31:15 -07:00
|
|
|
|
|
|
|
auto index = mThreads.IndexOf<PRThread*>(nullptr);
|
|
|
|
MOZ_ASSERT(index != mThreads.NoIndex, "mThreads entry has gone!");
|
|
|
|
mThreads[index] = current;
|
|
|
|
|
2008-08-11 17:01:47 -07:00
|
|
|
listener = mListener;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (listener) {
|
|
|
|
listener->OnThreadCreated();
|
|
|
|
}
|
|
|
|
|
2013-10-23 13:31:15 -07:00
|
|
|
bool shutdownThreadOnExit = false;
|
|
|
|
bool exitThread = false;
|
|
|
|
bool wasIdle = false;
|
|
|
|
PRIntervalTime idleSince;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
do {
|
|
|
|
nsCOMPtr<nsIRunnable> event;
|
|
|
|
{
|
2011-04-29 12:21:57 -07:00
|
|
|
ReentrantMonitorAutoEnter mon(mEvents.GetReentrantMonitor());
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!mEvents.GetPendingEvent(getter_AddRefs(event))) {
|
|
|
|
PRIntervalTime now = PR_IntervalNow();
|
|
|
|
PRIntervalTime timeout = PR_MillisecondsToInterval(mIdleThreadTimeout);
|
|
|
|
|
|
|
|
// If we are shutting down, then don't keep any idle threads
|
|
|
|
if (mShutdown) {
|
2011-10-17 07:59:28 -07:00
|
|
|
exitThread = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
|
|
|
if (wasIdle) {
|
|
|
|
// if too many idle threads or idle for too long, then bail.
|
|
|
|
if (mIdleCount > mIdleThreadLimit || (now - idleSince) >= timeout)
|
2011-10-17 07:59:28 -07:00
|
|
|
exitThread = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
|
|
|
// if would be too many idle threads...
|
|
|
|
if (mIdleCount == mIdleThreadLimit) {
|
2011-10-17 07:59:28 -07:00
|
|
|
exitThread = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
|
|
|
++mIdleCount;
|
|
|
|
idleSince = now;
|
2011-10-17 07:59:28 -07:00
|
|
|
wasIdle = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (exitThread) {
|
|
|
|
if (wasIdle)
|
|
|
|
--mIdleCount;
|
2013-10-23 13:31:15 -07:00
|
|
|
shutdownThreadOnExit = mThreads.RemoveElement(current);
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
|
|
|
PRIntervalTime delta = timeout - (now - idleSince);
|
|
|
|
LOG(("THRD-P(%p) waiting [%d]\n", this, delta));
|
|
|
|
mon.Wait(delta);
|
|
|
|
}
|
|
|
|
} else if (wasIdle) {
|
2011-10-17 07:59:28 -07:00
|
|
|
wasIdle = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
--mIdleCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (event) {
|
|
|
|
LOG(("THRD-P(%p) running [%p]\n", this, event.get()));
|
|
|
|
event->Run();
|
|
|
|
}
|
|
|
|
} while (!exitThread);
|
|
|
|
|
2008-08-11 17:01:47 -07:00
|
|
|
if (listener) {
|
|
|
|
listener->OnThreadShuttingDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (shutdownThreadOnExit) {
|
2007-03-22 10:30:00 -07:00
|
|
|
ShutdownThread(current);
|
2008-08-11 17:01:47 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
LOG(("THRD-P(%p) leave\n", this));
|
2013-10-23 13:31:15 -07:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsThreadPool::Dispatch(nsIRunnable *event, uint32_t flags)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
LOG(("THRD-P(%p) dispatch [%p %x]\n", this, event, flags));
|
|
|
|
|
|
|
|
NS_ENSURE_STATE(!mShutdown);
|
|
|
|
|
|
|
|
if (flags & DISPATCH_SYNC) {
|
|
|
|
nsCOMPtr<nsIThread> thread;
|
|
|
|
nsThreadManager::get()->GetCurrentThread(getter_AddRefs(thread));
|
|
|
|
NS_ENSURE_STATE(thread);
|
|
|
|
|
|
|
|
nsRefPtr<nsThreadSyncDispatch> wrapper =
|
|
|
|
new nsThreadSyncDispatch(thread, event);
|
|
|
|
PutEvent(wrapper);
|
|
|
|
|
|
|
|
while (wrapper->IsPending())
|
|
|
|
NS_ProcessNextEvent(thread);
|
|
|
|
} else {
|
|
|
|
NS_ASSERTION(flags == NS_DISPATCH_NORMAL, "unexpected dispatch flags");
|
|
|
|
PutEvent(event);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsThreadPool::IsOnCurrentThread(bool *result)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// No one should be calling this method. If this assertion gets hit, then we
|
|
|
|
// need to think carefully about what this method should be returning.
|
|
|
|
NS_NOTREACHED("implement me");
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
*result = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsThreadPool::Shutdown()
|
|
|
|
{
|
2013-10-23 13:31:15 -07:00
|
|
|
nsTArray<PRThread*> threads;
|
2008-08-11 17:01:47 -07:00
|
|
|
nsCOMPtr<nsIThreadPoolListener> listener;
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-04-29 12:21:57 -07:00
|
|
|
ReentrantMonitorAutoEnter mon(mEvents.GetReentrantMonitor());
|
2011-10-17 07:59:28 -07:00
|
|
|
mShutdown = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
mon.NotifyAll();
|
|
|
|
|
2008-08-11 17:01:47 -07:00
|
|
|
// Swap in a null listener so that we release the listener at the end of
|
|
|
|
// this method. The listener will be kept alive as long as the other threads
|
|
|
|
// that were created when it was set.
|
|
|
|
mListener.swap(listener);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-10-23 13:31:15 -07:00
|
|
|
while (mThreads.Length()) {
|
|
|
|
// It's important that we shutdown the threads while outside the event
|
|
|
|
// queue monitor. Otherwise, we could end up dead-locking.
|
|
|
|
ReentrantMonitorAutoExit mon(mEvents.GetReentrantMonitor());
|
|
|
|
// ShutdownThread() will ensure there is another event to process
|
|
|
|
NS_ProcessNextEvent();
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsThreadPool::GetThreadLimit(uint32_t *value)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
*value = mThreadLimit;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsThreadPool::SetThreadLimit(uint32_t value)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-04-29 12:21:57 -07:00
|
|
|
ReentrantMonitorAutoEnter mon(mEvents.GetReentrantMonitor());
|
2007-03-22 10:30:00 -07:00
|
|
|
mThreadLimit = value;
|
|
|
|
if (mIdleThreadLimit > mThreadLimit)
|
|
|
|
mIdleThreadLimit = mThreadLimit;
|
2013-05-16 09:02:46 -07:00
|
|
|
|
2013-10-23 13:31:15 -07:00
|
|
|
if (mThreads.Length() > mThreadLimit) {
|
2013-05-16 09:02:46 -07:00
|
|
|
mon.NotifyAll(); // wake up threads so they observe this change
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsThreadPool::GetIdleThreadLimit(uint32_t *value)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
*value = mIdleThreadLimit;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsThreadPool::SetIdleThreadLimit(uint32_t value)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-04-29 12:21:57 -07:00
|
|
|
ReentrantMonitorAutoEnter mon(mEvents.GetReentrantMonitor());
|
2007-03-22 10:30:00 -07:00
|
|
|
mIdleThreadLimit = value;
|
|
|
|
if (mIdleThreadLimit > mThreadLimit)
|
|
|
|
mIdleThreadLimit = mThreadLimit;
|
2013-05-16 09:02:46 -07:00
|
|
|
|
|
|
|
// Do we need to kill some idle threads?
|
|
|
|
if (mIdleCount > mIdleThreadLimit) {
|
|
|
|
mon.NotifyAll(); // wake up threads so they observe this change
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsThreadPool::GetIdleThreadTimeout(uint32_t *value)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
*value = mIdleThreadTimeout;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsThreadPool::SetIdleThreadTimeout(uint32_t value)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-04-29 12:21:57 -07:00
|
|
|
ReentrantMonitorAutoEnter mon(mEvents.GetReentrantMonitor());
|
2013-05-16 09:02:46 -07:00
|
|
|
uint32_t oldTimeout = mIdleThreadTimeout;
|
2007-03-22 10:30:00 -07:00
|
|
|
mIdleThreadTimeout = value;
|
2013-05-16 09:02:46 -07:00
|
|
|
|
|
|
|
// Do we need to notify any idle threads that their sleep time has shortened?
|
|
|
|
if (mIdleThreadTimeout < oldTimeout && mIdleCount > 0) {
|
|
|
|
mon.NotifyAll(); // wake up threads so they observe this change
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2008-08-11 17:01:47 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsThreadPool::GetListener(nsIThreadPoolListener** aListener)
|
|
|
|
{
|
2011-04-29 12:21:57 -07:00
|
|
|
ReentrantMonitorAutoEnter mon(mEvents.GetReentrantMonitor());
|
2008-08-11 17:01:47 -07:00
|
|
|
NS_IF_ADDREF(*aListener = mListener);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsThreadPool::SetListener(nsIThreadPoolListener* aListener)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIThreadPoolListener> swappedListener(aListener);
|
|
|
|
{
|
2011-04-29 12:21:57 -07:00
|
|
|
ReentrantMonitorAutoEnter mon(mEvents.GetReentrantMonitor());
|
2008-08-11 17:01:47 -07:00
|
|
|
mListener.swap(swappedListener);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-06-12 10:06:20 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsThreadPool::SetName(const nsACString& aName)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ReentrantMonitorAutoEnter mon(mEvents.GetReentrantMonitor());
|
2013-10-23 13:31:15 -07:00
|
|
|
if (mThreads.Length())
|
2012-06-12 10:06:20 -07:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
mName = aName;
|
|
|
|
return NS_OK;
|
|
|
|
}
|