moved GetPrimordialThread from nsAppShellService to nsThread, as suggested by warren
git-svn-id: svn://10.0.0.236/trunk@35060 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -28,12 +28,10 @@
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#include "nsAppShellCIDs.h"
|
||||
#include "nsIAppShellService.h"
|
||||
#include "nsIEventQueueService.h"
|
||||
#include "nsIThread.h"
|
||||
|
||||
|
||||
|
||||
static NS_DEFINE_IID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID);
|
||||
static NS_DEFINE_IID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
|
||||
|
||||
/***************************************************************************/
|
||||
@@ -144,27 +142,27 @@ nsProxyObjectManager::GetProxyObject(nsIEventQueue *destQueue, REFNSIID aIID, ns
|
||||
|
||||
*aProxyObject = nsnull;
|
||||
|
||||
// post to primordial thread event queue if no queue specified
|
||||
if (postQ == nsnull)
|
||||
{
|
||||
// Get app shell service.
|
||||
nsresult rv;
|
||||
|
||||
NS_WITH_SERVICE(nsIAppShellService, appShell, kAppShellServiceCID, &rv);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIThread> mainIThread;
|
||||
PRThread *mainThread;
|
||||
|
||||
PRThread *aThread;
|
||||
rv = appShell->GetPrimordialThread(&aThread);
|
||||
|
||||
// Get the primordial thread
|
||||
rv = nsIThread::GetMainThread(getter_AddRefs(mainIThread));
|
||||
if ( NS_FAILED( rv ) )
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
rv = mainIThread->GetPRThread(&mainThread);
|
||||
if ( NS_FAILED( rv ) )
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
NS_WITH_SERVICE(nsIEventQueueService, eventQService, kEventQueueServiceCID, &rv);
|
||||
|
||||
if ( NS_FAILED( rv ) )
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
rv = eventQService->GetThreadEventQueue(aThread, &postQ);
|
||||
rv = eventQService->GetThreadEventQueue(mainThread, &postQ);
|
||||
|
||||
if ( NS_FAILED( rv ) )
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
@@ -63,6 +63,15 @@ public:
|
||||
// returns the nsIThread for an arbitrary PRThread:
|
||||
static NS_COM nsresult GetIThread(PRThread* prthread, nsIThread* *result);
|
||||
|
||||
// initializes the "main" thread (really, just saves the current thread
|
||||
// at time of calling. meant to be called once at app startup, in lieu
|
||||
// of proper static initializers, to save the primordial thread
|
||||
// for later recall.)
|
||||
static NS_COM nsresult SetMainThread();
|
||||
|
||||
// return the "main" thread
|
||||
static NS_COM nsresult GetMainThread(nsIThread **result);
|
||||
|
||||
NS_IMETHOD Join() = 0;
|
||||
|
||||
NS_IMETHOD GetPriority(PRThreadPriority *result) = 0;
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
//#include <stdio.h>
|
||||
|
||||
PRUintn nsThread::kIThreadSelfIndex = 0;
|
||||
static nsIThread *gMainThread = 0;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -238,6 +239,28 @@ nsIThread::GetIThread(PRThread* prthread, nsIThread* *result)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_COM nsresult
|
||||
nsIThread::SetMainThread()
|
||||
{
|
||||
// strictly speaking, it could be set twice. but practically speaking,
|
||||
// it's almost certainly an error if it is
|
||||
if (gMainThread != 0)
|
||||
return NS_ERROR_FAILURE;
|
||||
return GetCurrent(&gMainThread);
|
||||
}
|
||||
|
||||
NS_COM nsresult
|
||||
nsIThread::GetMainThread(nsIThread **result)
|
||||
{
|
||||
if (gMainThread == 0)
|
||||
return NS_ERROR_FAILURE;
|
||||
if (*result == 0)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
*result = gMainThread;
|
||||
NS_ADDREF(gMainThread);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsThreadPool::nsThreadPool(PRUint32 minThreads, PRUint32 maxThreads)
|
||||
|
||||
@@ -48,7 +48,6 @@ public:
|
||||
NS_IMETHOD Initialize(nsICmdLineService * aCmdLineService) = 0;
|
||||
NS_IMETHOD Run(void) = 0;
|
||||
NS_IMETHOD Shutdown(void) = 0;
|
||||
NS_IMETHOD GetPrimordialThread(PRThread **aThread) = 0;
|
||||
|
||||
NS_IMETHOD CreateTopLevelWindow(nsIWebShellWindow * aParent,
|
||||
nsIURL* aUrl,
|
||||
|
||||
@@ -93,8 +93,6 @@ public:
|
||||
NS_IMETHOD Initialize(nsICmdLineService*aCmdLineService);
|
||||
NS_IMETHOD Run(void);
|
||||
NS_IMETHOD Shutdown(void);
|
||||
NS_IMETHOD GetPrimordialThread(PRThread **aThread)
|
||||
{ *aThread = mPrimordialThread; return NS_OK; }
|
||||
|
||||
NS_IMETHOD CreateTopLevelWindow(nsIWebShellWindow * aParent,
|
||||
nsIURL* aUrl,
|
||||
@@ -128,7 +126,6 @@ protected:
|
||||
nsIAppShell* mAppShell;
|
||||
nsISupportsArray* mWindowList;
|
||||
nsICmdLineService* mCmdLineService;
|
||||
PRThread* mPrimordialThread;
|
||||
};
|
||||
|
||||
|
||||
@@ -139,7 +136,6 @@ nsAppShellService::nsAppShellService()
|
||||
mAppShell = nsnull;
|
||||
mWindowList = nsnull;
|
||||
mCmdLineService = nsnull;
|
||||
mPrimordialThread = nsnull;
|
||||
}
|
||||
|
||||
nsAppShellService::~nsAppShellService()
|
||||
@@ -167,9 +163,6 @@ nsAppShellService::Initialize( nsICmdLineService *aCmdLineService )
|
||||
#ifdef MOZ_FULLCIRCLE
|
||||
FCInitialize();
|
||||
#endif
|
||||
// assume no new threads have been spun up yet, or at least if they have,
|
||||
// they haven't been made the current one
|
||||
mPrimordialThread = PR_CurrentThread();
|
||||
|
||||
// Remember cmd line service.
|
||||
mCmdLineService = aCmdLineService;
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
|
||||
#include "nsIAppShell.h"
|
||||
#include "nsICmdLineService.h"
|
||||
#include "nsIThread.h"
|
||||
#include "nsIAppShellService.h"
|
||||
#include "nsIAppShellComponent.h"
|
||||
#include "nsAppShellCIDs.h"
|
||||
@@ -117,6 +118,7 @@ int main(int argc, char* argv[])
|
||||
nsresult rv;
|
||||
|
||||
nsICmdLineService * cmdLineArgs = nsnull;
|
||||
NS_VERIFY(NS_SUCCEEDED(nsIThread::SetMainThread()), "couldn't set main thread");
|
||||
|
||||
char * urlstr=nsnull;
|
||||
//char * progname = nsnull;
|
||||
|
||||
Reference in New Issue
Block a user