From fb188421564e5e43d81f218be1dd9ae68d2ad23f Mon Sep 17 00:00:00 2001 From: "danm%netscape.com" Date: Sun, 13 Jun 1999 03:30:38 +0000 Subject: [PATCH] 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 --- .../xpcom/proxy/src/nsProxyObjectManager.cpp | 26 +++++++++---------- mozilla/xpcom/threads/nsIThread.h | 9 +++++++ mozilla/xpcom/threads/nsThread.cpp | 23 ++++++++++++++++ .../xpfe/appshell/public/nsIAppShellService.h | 1 - .../xpfe/appshell/src/nsAppShellService.cpp | 7 ----- mozilla/xpfe/bootstrap/nsAppRunner.cpp | 2 ++ 6 files changed, 46 insertions(+), 22 deletions(-) diff --git a/mozilla/xpcom/proxy/src/nsProxyObjectManager.cpp b/mozilla/xpcom/proxy/src/nsProxyObjectManager.cpp index fff8b9f094e..2135225c9b0 100644 --- a/mozilla/xpcom/proxy/src/nsProxyObjectManager.cpp +++ b/mozilla/xpcom/proxy/src/nsProxyObjectManager.cpp @@ -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 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; diff --git a/mozilla/xpcom/threads/nsIThread.h b/mozilla/xpcom/threads/nsIThread.h index bf23db45368..490057d1488 100644 --- a/mozilla/xpcom/threads/nsIThread.h +++ b/mozilla/xpcom/threads/nsIThread.h @@ -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; diff --git a/mozilla/xpcom/threads/nsThread.cpp b/mozilla/xpcom/threads/nsThread.cpp index 11681831862..999c6a99693 100644 --- a/mozilla/xpcom/threads/nsThread.cpp +++ b/mozilla/xpcom/threads/nsThread.cpp @@ -21,6 +21,7 @@ //#include 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) diff --git a/mozilla/xpfe/appshell/public/nsIAppShellService.h b/mozilla/xpfe/appshell/public/nsIAppShellService.h index 123775208ba..5e0461ef40f 100644 --- a/mozilla/xpfe/appshell/public/nsIAppShellService.h +++ b/mozilla/xpfe/appshell/public/nsIAppShellService.h @@ -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, diff --git a/mozilla/xpfe/appshell/src/nsAppShellService.cpp b/mozilla/xpfe/appshell/src/nsAppShellService.cpp index cd6a7bd36b0..94eb9294520 100644 --- a/mozilla/xpfe/appshell/src/nsAppShellService.cpp +++ b/mozilla/xpfe/appshell/src/nsAppShellService.cpp @@ -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; diff --git a/mozilla/xpfe/bootstrap/nsAppRunner.cpp b/mozilla/xpfe/bootstrap/nsAppRunner.cpp index e30ba2ff6ec..579ac4a1c83 100644 --- a/mozilla/xpfe/bootstrap/nsAppRunner.cpp +++ b/mozilla/xpfe/bootstrap/nsAppRunner.cpp @@ -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;