Allow XPCOM to be restarted. r+sr=darin with grudging consent from dougt. Bug 239819

git-svn-id: svn://10.0.0.236/trunk@156232 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
bsmedberg%covad.net
2004-05-11 09:38:50 +00:00
parent 9c4c1d7e09
commit ff6cab48ca
6 changed files with 100 additions and 71 deletions

View File

@@ -46,14 +46,13 @@
#include "nsIEventQueue.h"
#include "prmem.h"
static PRInt32 gGenerator = 0;
static TimerThread* gThread = nsnull;
static PRBool gFireOnIdle = PR_FALSE;
static nsTimerManager* gManager = nsnull;
#include "prmem.h"
#include "prinit.h"
#ifdef DEBUG_TIMERS
#include <math.h>
@@ -139,23 +138,6 @@ NS_IMETHODIMP_(nsrefcnt) nsTimerImpl::Release(void)
return count;
}
PR_STATIC_CALLBACK(PRStatus) InitThread(void)
{
gThread = new TimerThread();
if (!gThread)
return PR_FAILURE;
NS_ADDREF(gThread);
nsresult rv = gThread->Init();
if (NS_FAILED(rv)) {
NS_RELEASE(gThread);
return PR_FAILURE;
}
return PR_SUCCESS;
}
nsTimerImpl::nsTimerImpl() :
mClosure(nsnull),
mCallbackType(CALLBACK_TYPE_UNKNOWN),
@@ -167,11 +149,9 @@ nsTimerImpl::nsTimerImpl() :
mDelay(0),
mTimeout(0)
{
// XXXbsmedberg: shouldn't this be in Init()?
nsIThread::GetCurrent(getter_AddRefs(mCallingThread));
static PRCallOnceType once;
PR_CallOnce(&once, InitThread);
mCallback.c = nsnull;
#ifdef DEBUG_TIMERS
@@ -185,6 +165,24 @@ nsTimerImpl::~nsTimerImpl()
ReleaseCallback();
}
//static
nsresult
nsTimerImpl::Startup()
{
nsresult rv;
gThread = new TimerThread();
if (!gThread) return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(gThread);
rv = gThread->InitLocks();
if (NS_FAILED(rv)) {
NS_RELEASE(gThread);
}
return rv;
}
void nsTimerImpl::Shutdown()
{
@@ -210,6 +208,13 @@ void nsTimerImpl::Shutdown()
nsresult nsTimerImpl::InitCommon(PRUint32 aType, PRUint32 aDelay)
{
nsresult rv;
NS_ENSURE_TRUE(gThread, NS_ERROR_NOT_INITIALIZED);
rv = gThread->Init();
NS_ENSURE_SUCCESS(rv, rv);
/**
* In case of re-Init, both with and without a preceding Cancel, clear the
* mCanceled flag and assign a new mGeneration. But first, remove any armed
@@ -240,9 +245,6 @@ NS_IMETHODIMP nsTimerImpl::InitWithFuncCallback(nsTimerCallbackFunc aFunc,
PRUint32 aDelay,
PRUint32 aType)
{
if (!gThread)
return NS_ERROR_FAILURE;
ReleaseCallback();
mCallbackType = CALLBACK_TYPE_FUNC;
mCallback.c = aFunc;
@@ -255,9 +257,6 @@ NS_IMETHODIMP nsTimerImpl::InitWithCallback(nsITimerCallback *aCallback,
PRUint32 aDelay,
PRUint32 aType)
{
if (!gThread)
return NS_ERROR_FAILURE;
ReleaseCallback();
mCallbackType = CALLBACK_TYPE_INTERFACE;
mCallback.i = aCallback;
@@ -270,9 +269,6 @@ NS_IMETHODIMP nsTimerImpl::Init(nsIObserver *aObserver,
PRUint32 aDelay,
PRUint32 aType)
{
if (!gThread)
return NS_ERROR_FAILURE;
ReleaseCallback();
mCallbackType = CALLBACK_TYPE_OBSERVER;
mCallback.o = aObserver;