Bug 498010 - Threads should release their observers when they are shut down; r=benjamin

This commit is contained in:
ben turner 2009-06-22 15:08:04 +02:00
Родитель d6dad64b6d
Коммит 66d8174bb0
3 изменённых файлов: 19 добавлений и 1 удалений

Просмотреть файл

@ -51,7 +51,9 @@ interface nsIThreadInternal : nsIThread
/**
* Get/set the current thread observer (may be null). This attribute may be
* read from any thread, but must only be set on the thread corresponding to
* this thread object.
* this thread object. The observer will be released on the thread
* corresponding to this thread object after all other events have been
* processed during a call to Shutdown.
*/
attribute nsIThreadObserver observer;

Просмотреть файл

@ -280,6 +280,9 @@ nsThread::ThreadFunc(void *arg)
event = new nsThreadShutdownAckEvent(self->mShutdownContext);
self->mShutdownContext->joiningThread->Dispatch(event, NS_DISPATCH_NORMAL);
// Release any observer of the thread here.
self->SetObserver(nsnull);
NS_RELEASE(self);
}
@ -468,6 +471,14 @@ nsThread::Shutdown()
PR_JoinThread(mThread);
mThread = nsnull;
#ifdef DEBUG
{
nsAutoLock lock(mLock);
NS_ASSERTION(!mObserver, "Should have been cleared at shutdown!");
}
#endif
return NS_OK;
}

Просмотреть файл

@ -155,6 +155,11 @@ nsThreadManager::Shutdown()
mThreadsByPRThread.Clear();
}
// Normally thread shutdown clears the observer for the thread, but since the
// main thread is special we do it manually here after we're sure all events
// have been processed.
mMainThread->SetObserver(nsnull);
// Release main thread object.
mMainThread = nsnull;