Bug 619096 - nsMemoryReporterManager should be threadsafe. r=vlad a=mfinkle

This commit is contained in:
Doug Turner
2010-12-15 09:47:16 -08:00
parent f2f7ee865f
commit b2800960b9
2 changed files with 23 additions and 3 deletions

View File

@@ -39,7 +39,6 @@
#include "nsCOMPtr.h"
#include "nsServiceManagerUtils.h"
#include "nsMemoryReporterManager.h"
#include "nsArrayEnumerator.h"
/**
@@ -210,7 +209,7 @@ NS_MEMORY_REPORTER_IMPLEMENT(Win32PrivateBytes,
** nsMemoryReporterManager implementation
**/
NS_IMPL_ISUPPORTS1(nsMemoryReporterManager, nsIMemoryReporterManager)
NS_IMPL_THREADSAFE_ISUPPORTS1(nsMemoryReporterManager, nsIMemoryReporterManager)
NS_IMETHODIMP
nsMemoryReporterManager::Init()
@@ -250,15 +249,28 @@ nsMemoryReporterManager::Init()
return NS_OK;
}
nsMemoryReporterManager::nsMemoryReporterManager()
: mMutex("nsMemoryReporterManager::mMutex")
{
}
nsMemoryReporterManager::~nsMemoryReporterManager()
{
}
NS_IMETHODIMP
nsMemoryReporterManager::EnumerateReporters(nsISimpleEnumerator **result)
{
return NS_NewArrayEnumerator(result, mReporters);
nsresult rv;
mozilla::MutexAutoLock autoLock(mMutex);
rv = NS_NewArrayEnumerator(result, mReporters);
return rv;
}
NS_IMETHODIMP
nsMemoryReporterManager::RegisterReporter(nsIMemoryReporter *reporter)
{
mozilla::MutexAutoLock autoLock(mMutex);
if (mReporters.IndexOf(reporter) != -1)
return NS_ERROR_FAILURE;
@@ -269,6 +281,7 @@ nsMemoryReporterManager::RegisterReporter(nsIMemoryReporter *reporter)
NS_IMETHODIMP
nsMemoryReporterManager::UnregisterReporter(nsIMemoryReporter *reporter)
{
mozilla::MutexAutoLock autoLock(mMutex);
if (!mReporters.RemoveObject(reporter))
return NS_ERROR_FAILURE;