Make three changes:

1)  Use GetWeak() on the queue hashtable where possible
2)  Fix what looks like a bug in CreateEventQueue (passing wrong thread
    to MakeNewQueue).
3)  Fix what looks like a bug in PushThreadEventQueue (looking at the original
    queue for the thread rather than the youngest one).

Bug 230092, r=danm, sr=darin
This commit is contained in:
bzbarsky%mit.edu 2004-01-28 23:13:48 +00:00
parent 065f5ce3fc
commit 6d6ba3ce56

View File

@ -106,6 +106,10 @@ nsEventQueueServiceImpl::~nsEventQueueServiceImpl()
nsresult
nsEventQueueServiceImpl::Init()
{
NS_ENSURE_TRUE(mEventQMonitor, NS_ERROR_OUT_OF_MEMORY);
// This will only be called once on the main thread, so it's safe to
// not enter the monitor here.
if (!mEventQTable.Init()) {
return NS_ERROR_OUT_OF_MEMORY;
}
@ -178,17 +182,15 @@ NS_IMETHODIMP
nsEventQueueServiceImpl::CreateEventQueue(PRThread *aThread, PRBool aNative)
{
nsresult rv = NS_OK;
nsCOMPtr<nsIEventQueue> queue;
/* Enter the lock that protects the EventQ hashtable... */
PR_EnterMonitor(mEventQMonitor);
/* create only one event queue chain per thread... */
mEventQTable.Get(aThread, getter_AddRefs(queue));
if (!mEventQTable.GetWeak(aThread)) {
nsCOMPtr<nsIEventQueue> queue;
if (!queue) {
// we don't have one in the table
rv = MakeNewQueue(PR_GetCurrentThread(), aNative, getter_AddRefs(queue)); // create new queue
rv = MakeNewQueue(aThread, aNative, getter_AddRefs(queue)); // create new queue
mEventQTable.Put(aThread, queue); // add to the table (initial addref)
}
@ -271,15 +273,15 @@ nsEventQueueServiceImpl::PushThreadEventQueue(nsIEventQueue **aNewQueue)
/* Enter the lock that protects the EventQ hashtable... */
PR_EnterMonitor(mEventQMonitor);
nsCOMPtr<nsIEventQueue> queue;
mEventQTable.Get(currentThread, getter_AddRefs(queue));
nsIEventQueue* queue = mEventQTable.GetWeak(currentThread);
NS_ASSERTION(queue, "pushed event queue on top of nothing");
if (queue) { // find out what kind of queue our relatives are
nsCOMPtr<nsIEventQueue> youngQueue;
GetYoungestEventQueue(queue, getter_AddRefs(youngQueue));
if (youngQueue) {
queue->IsQueueNative(&native);
youngQueue->IsQueueNative(&native);
}
}