Fix the holding past XPCOM shutdown of an nsTimerManager in a static nsCOMPtr. r=jag sr=shaver b=43589

This commit is contained in:
dbaron%fas.harvard.edu 2001-12-08 22:40:08 +00:00
Родитель 82cc6db0e2
Коммит b4ec9a8f10
3 изменённых файлов: 30 добавлений и 16 удалений

Просмотреть файл

@ -210,14 +210,14 @@ static nsModuleComponentInfo components[] =
nsDragServiceConstructor },
{ "Timer",
NS_TIMER_CID,
"@mozilla.org/timer;1",
nsTimerConstructor },
"@mozilla.org/timer;1",
nsTimerConstructor },
{ "Timer Manager",
NS_TIMERMANAGER_CID,
"@mozilla.org/widget/timermanager;1",
nsTimerManagerConstructor },
"@mozilla.org/widget/timermanager;1",
nsTimerManagerConstructor },
#ifdef IBMBIDI
{ "Gtk Bidi Keyboard",
{ "Bidi Keyboard",
NS_BIDIKEYBOARD_CID,
"@mozilla.org/widget/bidikeyboard;1",
nsBidiKeyboardConstructor },
@ -225,4 +225,11 @@ static nsModuleComponentInfo components[] =
};
NS_IMPL_NSGETMODULE(nsWidgetModule, components)
PR_STATIC_CALLBACK(void)
nsWidgetWinModuleDtor(nsIModule *self)
{
nsTimer::Shutdown();
}
NS_IMPL_NSGETMODULE_WITH_DTOR(nsWidgetModule, components,
nsWidgetWinModuleDtor)

Просмотреть файл

@ -51,10 +51,9 @@
static NS_DEFINE_CID(kTimerManagerCID, NS_TIMERMANAGER_CID);
static nsCOMPtr<nsIWindowsTimerMap> sTimerMap;
static nsCOMPtr<nsITimerQueue> sTimerQueue;
class nsTimer;
static PRBool sCachedServices = PR_FALSE;
static nsIWindowsTimerMap *sTimerMap = nsnull;
static nsITimerQueue *sTimerQueue = nsnull;
#define NS_PRIORITY_IMMEDIATE 10
@ -119,13 +118,11 @@ nsTimer::nsTimer() : nsITimer()
mTimerID = 0;
mTimerRunning = false;
static int cachedService = 0;
if (cachedService == 0) {
cachedService = 1;
if (!sCachedServices) {
sCachedServices = PR_TRUE;
nsresult rv;
sTimerMap = do_GetService(kTimerManagerCID, &rv);
sTimerQueue = do_GetService(kTimerManagerCID, &rv);
CallGetService(kTimerManagerCID, &sTimerMap);
CallQueryInterface(sTimerMap, &sTimerQueue);
}
}
@ -159,6 +156,13 @@ NS_IMETHODIMP nsTimer::Init(nsTimerCallbackFunc aFunc,
return Init(aDelay, aPriority, aType);
}
/* static */ void nsTimer::Shutdown()
{
sCachedServices = PR_FALSE;
NS_IF_RELEASE(sTimerMap);
NS_IF_RELEASE(sTimerQueue);
}
NS_IMETHODIMP nsTimer::Init(nsITimerCallback *aCallback,
PRUint32 aDelay,

Просмотреть файл

@ -65,6 +65,9 @@ public:
PRUint32 aType = NS_TYPE_ONE_SHOT
);
// Free statics
static void Shutdown();
NS_DECL_ISUPPORTS
NS_IMETHOD_(void) Cancel();