xpcom-thread-fixup
author Benjamin Smedberg <benjamin@smedbergs.us>
Sat, 26 Jul 2008 22:49:39 -0400
changeset 167 a4da40849f5436e629c5732f4368c6c48189637f
parent 66 4161d51d7ccbb4019a5cb4d18a855094024a52db
permissions -rw-r--r--
State as of now

diff --git a/xpcom/threads/nsThread.cpp b/xpcom/threads/nsThread.cpp
--- a/xpcom/threads/nsThread.cpp
+++ b/xpcom/threads/nsThread.cpp
@@ -60,15 +60,32 @@ nsIThreadObserver* nsThread::sGlobalObse
 // Because we do not have our own nsIFactory, we have to implement nsIClassInfo
 // somewhat manually.
 
-class nsThreadClassInfo : public nsIClassInfo {
+class nsThreadClassInfo : public XPCOMGCFinalizedObject
+                        , public nsIClassInfo {
 public:
   NS_DECL_ISUPPORTS_INHERITED  // no mRefCnt
   NS_DECL_NSICLASSINFO
 
-  nsThreadClassInfo() {}
+  nsThreadClassInfo() {
+    gThreadClassInfo = this;
+  }
+  ~nsThreadClassInfo() {
+    gThreadClassInfo = nsnull;
+  }
+
+  static nsThreadClassInfo* getSingleton()
+  {
+    if (gThreadClassInfo)
+      return gThreadClassInfo;
+
+    return new nsThreadClassInfo;
+  }
+
+private:
+  static nsThreadClassInfo *gThreadClassInfo;
 };
 
-static nsThreadClassInfo sThreadClassInfo;
+nsThreadClassInfo *nsThreadClassInfo::gThreadClassInfo;
 
 NS_IMPL_QUERY_INTERFACE1(nsThreadClassInfo, nsIClassInfo)
 
@@ -137,7 +154,7 @@ NS_INTERFACE_MAP_BEGIN(nsThread)
   NS_INTERFACE_MAP_ENTRY(nsISupportsPriority)
   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIThread)
   if (aIID.Equals(NS_GET_IID(nsIClassInfo))) {
-    foundInterface = static_cast<nsIClassInfo*>(&sThreadClassInfo);
+    foundInterface = static_cast<nsIClassInfo*>(nsThreadClassInfo::getSingleton());
   } else
 NS_INTERFACE_MAP_END
 NS_IMPL_CI_INTERFACE_GETTER4(nsThread, nsIThread, nsIThreadInternal,
@@ -447,7 +464,10 @@ nsThread::Shutdown()
 
   // Now, it should be safe to join without fear of dead-locking.
 
-  PR_JoinThread(mThread);
+  {
+    nsAutoSuspendRequest srq;
+    PR_JoinThread(mThread);
+  }
   mThread = nsnull;
   return NS_OK;
 }