Bug 611639 - NS_ProxyRelease does not work for RefPtrs.
authorMarco Bonardo <mbonardo@mozilla.com>
Tue, 16 Nov 2010 01:08:57 +0100
changeset 59334 d65c65ef13a48a3e7b9b1344908d12cf3392dd04
parent 59333 20311c05703ebcc43d74a4ee1fe44c68efecfaba
child 59335 999385f355a3a70f263c21b55be3bc89d678012c
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
bugs611639
milestone2.0b8pre
Bug 611639 - NS_ProxyRelease does not work for RefPtrs. r=shaver a=blocking
xpcom/glue/nsProxyRelease.h
--- a/xpcom/glue/nsProxyRelease.h
+++ b/xpcom/glue/nsProxyRelease.h
@@ -36,16 +36,17 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef nsProxyRelease_h__
 #define nsProxyRelease_h__
 
 #include "nsIEventTarget.h"
 #include "nsCOMPtr.h"
+#include "nsAutoPtr.h"
 
 #ifdef XPCOM_GLUE_AVOID_NSPR
 #error NS_ProxyRelease implementation depends on NSPR.
 #endif
 
 /**
  * Ensure that a nsCOMPtr is released on the target thread.
  *
@@ -57,16 +58,31 @@ NS_ProxyRelease
     (nsIEventTarget *target, nsCOMPtr<T> &doomed, PRBool alwaysProxy=PR_FALSE)
 {
    T* raw = nsnull;
    doomed.swap(raw);
    return NS_ProxyRelease(target, raw, alwaysProxy);
 }
 
 /**
+ * Ensure that a nsRefPtr is released on the target thread.
+ *
+ * @see NS_ProxyRelease(nsIEventTarget*, nsISupports*, PRBool)
+ */
+template <class T>
+inline NS_HIDDEN_(nsresult)
+NS_ProxyRelease
+    (nsIEventTarget *target, nsRefPtr<T> &doomed, PRBool alwaysProxy=PR_FALSE)
+{
+   T* raw = nsnull;
+   doomed.swap(raw);
+   return NS_ProxyRelease(target, raw, alwaysProxy);
+}
+
+/**
  * Ensures that the delete of a nsISupports object occurs on the target thread.
  *
  * @param target
  *        the target thread where the doomed object should be released.
  * @param doomed
  *        the doomed object; the object to be released on the target thread.
  * @param alwaysProxy
  *        normally, if NS_ProxyRelease is called on the target thread, then the