Bug 724368 - Expose the maximum number of threads. r=dougt

This commit is contained in:
David Rajchenbach-Teller 2013-04-19 07:54:18 -04:00
parent 95df688710
commit cc48ca0412
2 changed files with 26 additions and 2 deletions

View File

@ -160,6 +160,11 @@ nsThreadManager::RegisterCurrentThread(nsThread *thread)
MutexAutoLock lock(*mLock);
++mCurrentNumberOfThreads;
if (mCurrentNumberOfThreads > mHighestNumberOfThreads) {
mHighestNumberOfThreads = mCurrentNumberOfThreads;
}
mThreadsByPRThread.Put(thread->GetPRThread(), thread); // XXX check OOM?
NS_ADDREF(thread); // for TLS entry
@ -173,6 +178,7 @@ nsThreadManager::UnregisterCurrentThread(nsThread *thread)
MutexAutoLock lock(*mLock);
--mCurrentNumberOfThreads;
mThreadsByPRThread.Remove(thread->GetPRThread());
PR_SetThreadPrivate(mCurThreadIndex, nullptr);
@ -279,3 +285,10 @@ nsThreadManager::GetIsCycleCollectorThread(bool *result)
*result = bool(NS_IsCycleCollectorThread());
return NS_OK;
}
uint32_t
nsThreadManager::GetHighestNumberOfThreads()
{
MutexAutoLock lock(*mLock);
return mHighestNumberOfThreads;
}

View File

@ -42,6 +42,10 @@ public:
// initialized.
nsThread *GetCurrentThread();
// Returns the maximal number of threads that have been in existence
// simultaneously during the execution of the thread manager.
uint32_t GetHighestNumberOfThreads();
// This needs to be public in order to support static instantiation of this
// class with older compilers (e.g., egcs-2.91.66).
~nsThreadManager() {}
@ -51,9 +55,11 @@ private:
: mCurThreadIndex(0)
, mMainPRThread(nullptr)
, mLock(nullptr)
, mInitialized(false) {
, mInitialized(false)
, mCurrentNumberOfThreads(1)
, mHighestNumberOfThreads(1) {
}
static nsThreadManager sInstance;
nsRefPtrHashtable<nsPtrHashKey<PRThread>, nsThread> mThreadsByPRThread;
@ -64,6 +70,11 @@ private:
// the static context in debug builds.
nsAutoPtr<mozilla::Mutex> mLock; // protects tables
bool mInitialized;
// The current number of threads
uint32_t mCurrentNumberOfThreads;
// The highest number of threads encountered so far during the session
uint32_t mHighestNumberOfThreads;
};
#define NS_THREADMANAGER_CID \