From b4ec9a8f10af3d9636976a510ac27cc2a0f69d8e Mon Sep 17 00:00:00 2001 From: "dbaron%fas.harvard.edu" Date: Sat, 8 Dec 2001 22:40:08 +0000 Subject: [PATCH] Fix the holding past XPCOM shutdown of an nsTimerManager in a static nsCOMPtr. r=jag sr=shaver b=43589 --- widget/src/build/nsWinWidgetFactory.cpp | 19 ++++++++++++------ widget/timer/src/windows/nsTimer.cpp | 24 +++++++++++++---------- widget/timer/src/windows/nsWindowsTimer.h | 3 +++ 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/widget/src/build/nsWinWidgetFactory.cpp b/widget/src/build/nsWinWidgetFactory.cpp index ecc14cb8f66d..e520a043a765 100644 --- a/widget/src/build/nsWinWidgetFactory.cpp +++ b/widget/src/build/nsWinWidgetFactory.cpp @@ -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) diff --git a/widget/timer/src/windows/nsTimer.cpp b/widget/timer/src/windows/nsTimer.cpp index 17ef7d05a019..2c84d489472e 100644 --- a/widget/timer/src/windows/nsTimer.cpp +++ b/widget/timer/src/windows/nsTimer.cpp @@ -51,10 +51,9 @@ static NS_DEFINE_CID(kTimerManagerCID, NS_TIMERMANAGER_CID); -static nsCOMPtr sTimerMap; -static nsCOMPtr 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, diff --git a/widget/timer/src/windows/nsWindowsTimer.h b/widget/timer/src/windows/nsWindowsTimer.h index 86f7e3b24eaa..73056911e7b4 100644 --- a/widget/timer/src/windows/nsWindowsTimer.h +++ b/widget/timer/src/windows/nsWindowsTimer.h @@ -65,6 +65,9 @@ public: PRUint32 aType = NS_TYPE_ONE_SHOT ); + // Free statics + static void Shutdown(); + NS_DECL_ISUPPORTS NS_IMETHOD_(void) Cancel();