From dfeab526b2f16e4fb798673b0843cf515b2b09ba Mon Sep 17 00:00:00 2001 From: "kaie%kuix.de" Date: Tue, 4 Apr 2006 13:18:48 +0000 Subject: [PATCH] Follow-up checkin to bug 111384, fixes the tinderbox tests failure. If the thread runner C function calls the pure virtual Run too early, before the constructor finished, it will crash. This patch delays thread creation and virtual function call to a separate startThread call. Thanks a lot to Jag for his help in finding the problem! r=jag git-svn-id: svn://10.0.0.236/trunk@193503 18797224-902f-48f8-a5cc-f745e15eee43 --- .../ssl/src/nsCertVerificationThread.cpp | 2 -- .../manager/ssl/src/nsNSSComponent.cpp | 8 ++++++++ .../manager/ssl/src/nsPSMBackgroundThread.cpp | 20 +++++++++++++------ .../manager/ssl/src/nsPSMBackgroundThread.h | 4 +++- .../security/manager/ssl/src/nsSSLThread.cpp | 2 -- 5 files changed, 25 insertions(+), 11 deletions(-) diff --git a/mozilla/security/manager/ssl/src/nsCertVerificationThread.cpp b/mozilla/security/manager/ssl/src/nsCertVerificationThread.cpp index 4df572ff5a2..c9d8c34ca98 100644 --- a/mozilla/security/manager/ssl/src/nsCertVerificationThread.cpp +++ b/mozilla/security/manager/ssl/src/nsCertVerificationThread.cpp @@ -100,8 +100,6 @@ nsCertVerificationThread::nsCertVerificationThread() " to create another instance!"); verification_thread_singleton = this; - - NS_ASSERTION(mThreadHandle, "Could not create nsThreadRunner thread\n"); } nsCertVerificationThread::~nsCertVerificationThread() diff --git a/mozilla/security/manager/ssl/src/nsNSSComponent.cpp b/mozilla/security/manager/ssl/src/nsNSSComponent.cpp index 623e49f5ce0..5d1850dc7a0 100644 --- a/mozilla/security/manager/ssl/src/nsNSSComponent.cpp +++ b/mozilla/security/manager/ssl/src/nsNSSComponent.cpp @@ -301,7 +301,11 @@ nsNSSComponent::nsNSSComponent() mShutdownObjectList = nsNSSShutDownList::construct(); mIsNetworkDown = PR_FALSE; mSSLThread = new nsSSLThread(); + if (mSSLThread) + mSSLThread->startThread(); mCertVerificationThread = new nsCertVerificationThread(); + if (mCertVerificationThread) + mCertVerificationThread->startThread(); } nsNSSComponent::~nsNSSComponent() @@ -1953,8 +1957,12 @@ nsNSSComponent::Observe(nsISupports *aSubject, const char *aTopic, PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("receiving network restore topic\n")); delete mSSLThread; mSSLThread = new nsSSLThread(); + if (mSSLThread) + mSSLThread->startThread(); delete mCertVerificationThread; mCertVerificationThread = new nsCertVerificationThread(); + if (mCertVerificationThread) + mCertVerificationThread->startThread(); mIsNetworkDown = PR_FALSE; } diff --git a/mozilla/security/manager/ssl/src/nsPSMBackgroundThread.cpp b/mozilla/security/manager/ssl/src/nsPSMBackgroundThread.cpp index 59a282a5fed..c0fd971f393 100644 --- a/mozilla/security/manager/ssl/src/nsPSMBackgroundThread.cpp +++ b/mozilla/security/manager/ssl/src/nsPSMBackgroundThread.cpp @@ -52,14 +52,22 @@ nsPSMBackgroundThread::nsPSMBackgroundThread() { mMutex = PR_NewLock(); mCond = PR_NewCondVar(mMutex); +} - if (mMutex && mCond) - { - mThreadHandle = PR_CreateThread(PR_USER_THREAD, nsThreadRunner, NS_STATIC_CAST(void*, this), - PR_PRIORITY_NORMAL, PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0); +nsresult nsPSMBackgroundThread::startThread() +{ + if (!mMutex || !mCond) + return NS_ERROR_OUT_OF_MEMORY; - NS_ASSERTION(mThreadHandle, "Could not create nsPSMBackgroundThread\n"); - } + mThreadHandle = PR_CreateThread(PR_USER_THREAD, nsThreadRunner, NS_STATIC_CAST(void*, this), + PR_PRIORITY_NORMAL, PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0); + + NS_ASSERTION(mThreadHandle, "Could not create nsPSMBackgroundThread\n"); + + if (!mThreadHandle) + return NS_ERROR_OUT_OF_MEMORY; + + return NS_OK; } nsPSMBackgroundThread::~nsPSMBackgroundThread() diff --git a/mozilla/security/manager/ssl/src/nsPSMBackgroundThread.h b/mozilla/security/manager/ssl/src/nsPSMBackgroundThread.h index 554bf15071f..e790fb18d36 100644 --- a/mozilla/security/manager/ssl/src/nsPSMBackgroundThread.h +++ b/mozilla/security/manager/ssl/src/nsPSMBackgroundThread.h @@ -39,6 +39,7 @@ #define _NSPSMBACKGROUNDTHREAD_H_ #include "nspr.h" +#include "nscore.h" class nsPSMBackgroundThread { @@ -64,7 +65,8 @@ protected: public: nsPSMBackgroundThread(); virtual ~nsPSMBackgroundThread(); - + + nsresult startThread(); void requestExit(); }; diff --git a/mozilla/security/manager/ssl/src/nsSSLThread.cpp b/mozilla/security/manager/ssl/src/nsSSLThread.cpp index 7c4cd3b7767..06d543ffde0 100644 --- a/mozilla/security/manager/ssl/src/nsSSLThread.cpp +++ b/mozilla/security/manager/ssl/src/nsSSLThread.cpp @@ -50,8 +50,6 @@ nsSSLThread::nsSSLThread() NS_ASSERTION(!ssl_thread_singleton, "nsSSLThread is a singleton, caller attempts to create another instance!"); ssl_thread_singleton = this; - - NS_ASSERTION(mThreadHandle, "Could not create nsSSLThreadRunner thread\n"); } nsSSLThread::~nsSSLThread()