Bug 743786 - Add IsMainThread assertions to ClearOnShutdown. r=bmsedberg

This commit is contained in:
Justin Lebar 2012-04-10 15:58:10 -04:00
parent 51d4c74935
commit da57cc811b

View File

@ -41,6 +41,7 @@
#define mozilla_ClearOnShutdown_h
#include "mozilla/LinkedList.h"
#include "nsThreadUtils.h"
/*
* This header exports one public method in the mozilla namespace:
@ -56,6 +57,10 @@
*
* There is no way to undo a call to ClearOnShutdown, so you can call it only
* on smart pointers which you know will live until the program shuts down.
*
* ClearOnShutdown is currently main-thread only because we don't want to
* accidentally free an object from a different thread than the one it was
* created on.
*/
namespace mozilla {
@ -96,6 +101,8 @@ inline void ClearOnShutdown(SmartPtr *aPtr)
{
using namespace ClearOnShutdown_Internal;
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(!sHasShutDown);
ShutdownObserver *observer = new PointerClearer<SmartPtr>(aPtr);
sShutdownObservers.insertBack(observer);
@ -107,6 +114,8 @@ inline void KillClearOnShutdown()
{
using namespace ClearOnShutdown_Internal;
MOZ_ASSERT(NS_IsMainThread());
ShutdownObserver *observer;
while ((observer = sShutdownObservers.popFirst())) {
observer->Shutdown();