Relanding bug 326777, r=bsmedberg, sr=jst

git-svn-id: svn://10.0.0.236/trunk@229650 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
bzbarsky%mit.edu
2007-07-11 00:57:17 +00:00
parent eb1526b74a
commit f4d44ca58c
5 changed files with 68 additions and 1 deletions

View File

@@ -44,6 +44,7 @@
#include "nsAutoPtr.h"
#include "nsCOMPtr.h"
#include "prlog.h"
#include "nsThreadUtilsInternal.h"
#ifdef PR_LOGGING
static PRLogModuleInfo *sLog = PR_NewLogModule("nsThread");
@@ -52,6 +53,8 @@ static PRLogModuleInfo *sLog = PR_NewLogModule("nsThread");
NS_DECL_CI_INTERFACE_GETTER(nsThread)
nsIThreadObserver* nsThread::sGlobalObserver;
//-----------------------------------------------------------------------------
// Because we do not have our own nsIFactory, we have to implement nsIClassInfo
// somewhat manually.
@@ -464,6 +467,10 @@ nsThread::ProcessNextEvent(PRBool mayWait, PRBool *result)
NS_ENSURE_STATE(PR_GetCurrentThread() == mThread);
if (sGlobalObserver)
sGlobalObserver->OnProcessNextEvent(this, mayWait && !ShuttingDown(),
mRunningEvent);
nsCOMPtr<nsIThreadObserver> obs = mObserver;
if (obs)
obs->OnProcessNextEvent(this, mayWait && !ShuttingDown(), mRunningEvent);
@@ -489,6 +496,9 @@ nsThread::ProcessNextEvent(PRBool mayWait, PRBool *result)
if (obs)
obs->AfterProcessNextEvent(this, mRunningEvent);
if (sGlobalObserver)
sGlobalObserver->AfterProcessNextEvent(this, mRunningEvent);
return rv;
}
@@ -618,3 +628,18 @@ nsThreadSyncDispatch::Run()
}
return NS_OK;
}
nsresult
NS_SetGlobalThreadObserver(nsIThreadObserver* aObserver)
{
if (aObserver && nsThread::sGlobalObserver) {
return NS_ERROR_NOT_AVAILABLE;
}
if (!NS_IsMainThread()) {
return NS_ERROR_UNEXPECTED;
}
nsThread::sGlobalObserver = aObserver;
return NS_OK;
}