From ae029189754d96a1cd618cb41bad5f6330745201 Mon Sep 17 00:00:00 2001 From: "dougt%netscape.com" Date: Mon, 15 Apr 2002 22:36:59 +0000 Subject: [PATCH] Addresses some native component loader thread issues. Makes use of the threadsafe version of nsISupports. Adds comments to IDL it indicate that AutoRegister can only be called from the main thread. See 98755 for details. r=jband@netscape.com, sr=waterson@netscape.com git-svn-id: svn://10.0.0.236/trunk@119002 18797224-902f-48f8-a5cc-f745e15eee43 --- .../components/nsIComponentRegistrar.idl | 3 +++ .../components/nsNativeComponentLoader.cpp | 23 +++++++++++-------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/mozilla/xpcom/components/nsIComponentRegistrar.idl b/mozilla/xpcom/components/nsIComponentRegistrar.idl index ec7ce5ccc6c..1dcf202e3c5 100644 --- a/mozilla/xpcom/components/nsIComponentRegistrar.idl +++ b/mozilla/xpcom/components/nsIComponentRegistrar.idl @@ -56,6 +56,8 @@ interface nsIComponentRegistrar : nsISupports * symbols which this loader defines. For example, if the given file is a * native library (which is built into XPCOM), it must export the symbol * "NSGetModule". Other loaders may have different semantics. + * + * This method may only be called from the main thread. * * @param aSpec : Filename spec for component file's location. If aSpec * is a directory, then every component file in the @@ -73,6 +75,7 @@ interface nsIComponentRegistrar : nsISupports * autoUnregister * * Unregister a component file or all component files in a directory. + * This method may only be called from the main thread. * * @param aSpec : Filename spec for component file's location. If aSpec * is a directory, the every component file in the directory diff --git a/mozilla/xpcom/components/nsNativeComponentLoader.cpp b/mozilla/xpcom/components/nsNativeComponentLoader.cpp index 45bc49a2ac6..79b1766d5ad 100644 --- a/mozilla/xpcom/components/nsNativeComponentLoader.cpp +++ b/mozilla/xpcom/components/nsNativeComponentLoader.cpp @@ -41,7 +41,6 @@ #include "nsHashtableEnumerator.h" #include "nsXPIDLString.h" #include "nsCRT.h" - #include "nsIObserverService.h" #if defined(XP_MAC) // sdagley dougt fix @@ -87,7 +86,7 @@ nsNativeComponentLoader::~nsNativeComponentLoader() delete mDllStore; } -NS_IMPL_ISUPPORTS1(nsNativeComponentLoader, nsIComponentLoader); +NS_IMPL_THREADSAFE_ISUPPORTS1(nsNativeComponentLoader, nsIComponentLoader); NS_IMETHODIMP nsNativeComponentLoader::GetFactory(const nsIID & aCID, @@ -180,14 +179,17 @@ nsNativeComponentLoader::Init(nsIComponentManager *aCompMgr, nsISupports *aReg) if (NS_FAILED(rv)) return rv; - if (!mDllStore) { - mDllStore = new nsObjectHashtable(nsnull, nsnull, // never copy - nsDll_Destroy, nsnull, - 256, /* Thead Safe */ PR_TRUE); - if (!mDllStore) - return NS_ERROR_OUT_OF_MEMORY; - } + NS_ASSERTION(!mDllStore, "Init must not be called more than once"); + + mDllStore = new nsObjectHashtable(nsnull, + nsnull, // never copy + nsDll_Destroy, + nsnull, + 256, + PR_TRUE); // thread safe + if (!mDllStore) + return NS_ERROR_OUT_OF_MEMORY; // Read in all dll entries and populate the mDllStore nsCOMPtr dllEnum; @@ -979,13 +981,14 @@ nsNativeComponentLoader::RegisterDeferredComponents(PRInt32 aWhen, mDeferredComponents.RemoveElementAt(i); } } - +#ifdef DEBUG if (*aRegistered) fprintf(stderr, "nNCL: registered deferred, %d left\n", mDeferredComponents.Count()); else fprintf(stderr, "nNCL: didn't register any components, %d left\n", mDeferredComponents.Count()); +#endif /* are there any fatal errors? */ return NS_OK; }