From 85bb9d5b2031441b9c259e29c2f6c3f41c1f084c Mon Sep 17 00:00:00 2001 From: "dougt%netscape.com" Date: Thu, 6 Jan 2000 19:46:44 +0000 Subject: [PATCH] Fix for bug 22933 submitted by jonas.utterstrom@vittran.norrnod.se. r=dougt. git-svn-id: svn://10.0.0.236/trunk@56975 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/xpcom/threads/nsEventQueue.cpp | 28 +++++++++++++++++++ mozilla/xpcom/threads/nsEventQueue.h | 1 + mozilla/xpcom/threads/nsEventQueueService.cpp | 22 +++++++-------- mozilla/xpcom/threads/nsEventQueueService.h | 3 +- mozilla/xpcom/threads/nsIEventQueue.h | 1 + mozilla/xpcom/threads/nsIEventQueueService.h | 6 ++-- 6 files changed, 45 insertions(+), 16 deletions(-) diff --git a/mozilla/xpcom/threads/nsEventQueue.cpp b/mozilla/xpcom/threads/nsEventQueue.cpp index 9071235fa26..cd9812da420 100644 --- a/mozilla/xpcom/threads/nsEventQueue.cpp +++ b/mozilla/xpcom/threads/nsEventQueue.cpp @@ -22,6 +22,9 @@ #include "nsCOMPtr.h" #include "nsEventQueue.h" +#include "nsIEventQueueService.h" +#include "nsIThread.h" + #include "nsIServiceManager.h" #include "nsIObserverService.h" #include "nsString2.h" @@ -72,6 +75,31 @@ nsEventQueueImpl::Init() return NS_OK; } +NS_IMETHODIMP +nsEventQueueImpl::InitFromPRThread(PRThread* thread) +{ + if (thread == NS_CURRENT_THREAD) + { + thread = PR_GetCurrentThread(); + } + else if (thread == NS_UI_THREAD) + { + nsCOMPtr mainIThread; + nsresult rv; + + // Get the primordial thread + rv = nsIThread::GetMainThread(getter_AddRefs(mainIThread)); + if (NS_FAILED(rv)) return rv; + + rv = mainIThread->GetPRThread(&thread); + if (NS_FAILED(rv)) return rv; + } + + mEventQueue = PL_CreateNativeEventQueue("Thread event queue...", thread); + NotifyObservers(gActivatedNotification); + return NS_OK; +} + NS_IMETHODIMP nsEventQueueImpl::InitFromPLQueue(PLEventQueue* aQueue) { diff --git a/mozilla/xpcom/threads/nsEventQueue.h b/mozilla/xpcom/threads/nsEventQueue.h index d924ac9a16f..8cbdeffcbac 100644 --- a/mozilla/xpcom/threads/nsEventQueue.h +++ b/mozilla/xpcom/threads/nsEventQueue.h @@ -51,6 +51,7 @@ public: NS_IMETHOD_(PRInt32) GetEventQueueSelectFD(); NS_IMETHOD Init(); + NS_IMETHOD InitFromPRThread(PRThread* thread); NS_IMETHOD InitFromPLQueue(PLEventQueue* aQueue); NS_IMETHOD EnterMonitor(); diff --git a/mozilla/xpcom/threads/nsEventQueueService.cpp b/mozilla/xpcom/threads/nsEventQueueService.cpp index 3b67a506ac0..85e76c35557 100644 --- a/mozilla/xpcom/threads/nsEventQueueService.cpp +++ b/mozilla/xpcom/threads/nsEventQueueService.cpp @@ -33,11 +33,9 @@ static NS_DEFINE_CID(kEventQueueCID, NS_EVENTQUEUE_CID); // XXX move to nsID.h or nsHashtable.h? (copied from nsComponentManager.cpp) class ThreadKey: public nsHashKey { -private: - const PRThread* id; - + public: - ThreadKey(const PRThread* aID) { + ThreadKey(PRThread* aID) { id = aID; } @@ -56,6 +54,9 @@ public: nsHashKey *Clone(void) const { return new ThreadKey(id); } + + PRThread* id; + }; //////////////////////////////////////////////////////////////////////////////// @@ -77,7 +78,7 @@ public: NS_DECL_ISUPPORTS nsIEventQueue* GetEventQueue(void); // addrefs! - nsresult MakeNewQueue(nsIEventQueue **aQueue); + nsresult MakeNewQueue(PRThread* thread, nsIEventQueue **aQueue); nsresult AddQueue(void); void RemoveQueue(nsIEventQueue *aQueue); // queue goes dark, and is released @@ -106,7 +107,7 @@ EventQueueEntry::EventQueueEntry(nsEventQueueServiceImpl *aService, ThreadKey &a { NS_INIT_REFCNT(); mService = aService; - MakeNewQueue(&mQueue); + MakeNewQueue(aKey.id, &mQueue); NS_ASSERTION(mQueue, "EventQueueEntry constructor failed"); if (mService) mService->AddEventQueueEntry(this); @@ -136,7 +137,7 @@ nsIEventQueue* EventQueueEntry::GetEventQueue(void) return answer; } -nsresult EventQueueEntry::MakeNewQueue(nsIEventQueue **aQueue) +nsresult EventQueueEntry::MakeNewQueue(PRThread* thread, nsIEventQueue **aQueue) { nsIEventQueue *queue = 0; nsresult rv; @@ -145,7 +146,7 @@ nsresult EventQueueEntry::MakeNewQueue(nsIEventQueue **aQueue) NS_GET_IID(nsIEventQueue), (void**) &queue); if (NS_SUCCEEDED(rv)) { - rv = queue->Init(); + rv = queue->InitFromPRThread(thread); if (NS_FAILED(rv)) { NS_RELEASE(queue); queue = 0; // redundant, but makes me feel better @@ -161,7 +162,7 @@ nsresult EventQueueEntry::AddQueue(void) nsresult rv = NS_ERROR_NOT_INITIALIZED; if (mQueue) { - rv = MakeNewQueue(&newQueue); + rv = MakeNewQueue(PR_GetCurrentThread(), &newQueue); // add it to our chain of queues if (NS_SUCCEEDED(rv)) { @@ -536,7 +537,6 @@ nsEventQueueServiceImpl::ResolveEventQueue(nsIEventQueue* queueOrConstant, nsIEv return NS_OK; } - #ifdef XP_MAC // MAC specific. Will go away someday // Bwah ha ha h ha ah aha ha ha @@ -566,5 +566,3 @@ NS_IMETHODIMP nsEventQueueServiceImpl::ProcessEvents() } #endif - -//////////////////////////////////////////////////////////////////////////////// diff --git a/mozilla/xpcom/threads/nsEventQueueService.h b/mozilla/xpcom/threads/nsEventQueueService.h index 321cf7c6f3a..ea0a40fddae 100644 --- a/mozilla/xpcom/threads/nsEventQueueService.h +++ b/mozilla/xpcom/threads/nsEventQueueService.h @@ -68,9 +68,10 @@ public: NS_IMETHOD PushThreadEventQueue(nsIEventQueue **aNewQueue); NS_IMETHOD PopThreadEventQueue(nsIEventQueue *aQueue); + #ifdef XP_MAC NS_IMETHOD ProcessEvents(); -#endif // XP_MAC +#endif private: NS_IMETHOD CreateEventQueue(PRThread *aThread); diff --git a/mozilla/xpcom/threads/nsIEventQueue.h b/mozilla/xpcom/threads/nsIEventQueue.h index b5bc495d4d8..e776e3b551f 100644 --- a/mozilla/xpcom/threads/nsIEventQueue.h +++ b/mozilla/xpcom/threads/nsIEventQueue.h @@ -58,6 +58,7 @@ public: NS_IMETHOD_(PRInt32) GetEventQueueSelectFD() = 0; NS_IMETHOD Init() = 0; + NS_IMETHOD InitFromPRThread(PRThread* thread) = 0; NS_IMETHOD InitFromPLQueue(PLEventQueue* aQueue) = 0; NS_IMETHOD EnterMonitor() = 0; diff --git a/mozilla/xpcom/threads/nsIEventQueueService.h b/mozilla/xpcom/threads/nsIEventQueueService.h index 632edf6aaa2..c4a963571cd 100644 --- a/mozilla/xpcom/threads/nsIEventQueueService.h +++ b/mozilla/xpcom/threads/nsIEventQueueService.h @@ -72,9 +72,9 @@ public: NS_IMETHOD ResolveEventQueue(nsIEventQueue* queueOrConstant, nsIEventQueue* *resultQueue) = 0; #ifdef XP_MAC -// This is ment to be temporary until something better is worked out - NS_IMETHOD ProcessEvents() = 0; -#endif + NS_IMETHOD ProcessEvents() = 0; +#endif + }; #endif /* nsIEventQueueService_h___ */