Bug 886791 - Deadlock can occur if nsThreadPool::Dispatch() is called under lock, r=bsmedberg

This commit is contained in:
Michal Novotny 2013-06-26 01:18:39 +02:00
Родитель 3efaff8e99
Коммит 0f41803005
1 изменённых файлов: 9 добавлений и 1 удалений

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

@ -100,7 +100,15 @@ nsThreadPool::PutEvent(nsIRunnable *event)
}
LOG(("THRD-P(%p) put [%p kill=%d]\n", this, thread.get(), killThread));
if (killThread) {
thread->Shutdown();
// Pending events are processed on the current thread during
// nsIThread::Shutdown() execution, so if nsThreadPool::Dispatch() is called
// under caller's lock then deadlock could occur. This happens e.g. in case
// of nsStreamCopier. To prevent this situation, dispatch a shutdown event
// to the current thread instead of calling nsIThread::Shutdown() directly.
nsRefPtr<nsIRunnable> r = NS_NewRunnableMethod(thread,
&nsIThread::Shutdown);
NS_DispatchToCurrentThread(r);
} else {
thread->Dispatch(this, NS_DISPATCH_NORMAL);
}