Bug 923554 - Backout the atomic weak pointer implementation because it's neither atomic nor thread-safe; r=froydnj
authorEhsan Akhgari <ehsan@mozilla.com>
Wed, 16 Oct 2013 13:48:34 -0400
changeset 164876 287878a32dd22f0d6a26845a3ee1cddc012b961b
parent 164875 8a18721cdd8d70e347f3bd8aa56b335e48afe13a
child 164877 27a00d5fa55dd0d9d1f77ee6161e927575ae353d
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs923554
milestone27.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 923554 - Backout the atomic weak pointer implementation because it's neither atomic nor thread-safe; r=froydnj
mfbt/WeakPtr.h
--- a/mfbt/WeakPtr.h
+++ b/mfbt/WeakPtr.h
@@ -9,19 +9,16 @@
 /**
  * SupportsWeakPtr lets you have a pointer to an object 'Foo' without affecting
  * its lifetime. It works by creating a single shared reference counted object
  * (WeakReference) that each WeakPtr will access 'Foo' through. This lets 'Foo'
  * clear the pointer in the WeakReference without having to know about all of
  * the WeakPtrs to it and allows the WeakReference to live beyond the lifetime
  * of 'Foo'.
  *
- * AtomicSupportsWeakPtr can be used for a variant with an atomically updated
- * reference counter.
- *
  * The overhead of WeakPtr is that accesses to 'Foo' becomes an additional
  * dereference, and an additional heap allocated pointer sized object shared
  * between all of the WeakPtrs.
  *
  * Example of usage:
  *
  *   // To have a class C support weak pointers, inherit from SupportsWeakPtr<C>.
  *   class C : public SupportsWeakPtr<C>
@@ -58,41 +55,40 @@
  * The API was loosely inspired by Chromium's weak_ptr.h:
  * http://src.chromium.org/svn/trunk/src/base/memory/weak_ptr.h
  */
 
 #ifndef mozilla_WeakPtr_h
 #define mozilla_WeakPtr_h
 
 #include "mozilla/Assertions.h"
-#include "mozilla/Atomics.h"
 #include "mozilla/NullPtr.h"
 #include "mozilla/RefPtr.h"
 #include "mozilla/TypeTraits.h"
 
 namespace mozilla {
 
 template <typename T, class WeakReference> class WeakPtrBase;
 template <typename T, class WeakReference> class SupportsWeakPtrBase;
 
 namespace detail {
 
 // This can live beyond the lifetime of the class derived from SupportsWeakPtrBase.
-template<class T, RefCountAtomicity Atomicity>
-class WeakReference : public RefCounted<WeakReference<T, Atomicity>, Atomicity>
+template<class T>
+class WeakReference : public ::mozilla::RefCounted<WeakReference<T> >
 {
   public:
     explicit WeakReference(T* p) : ptr(p) {}
     T* get() const {
       return ptr;
     }
 
   private:
-    friend class WeakPtrBase<T, WeakReference>;
-    friend class SupportsWeakPtrBase<T, WeakReference>;
+    friend class WeakPtrBase<T, WeakReference<T> >;
+    friend class SupportsWeakPtrBase<T, WeakReference<T> >;
     void detach() {
       ptr = nullptr;
     }
     T* ptr;
 };
 
 } // namespace detail
 
@@ -116,40 +112,20 @@ class SupportsWeakPtrBase
 
   private:
     friend class WeakPtrBase<T, WeakReference>;
 
     RefPtr<WeakReference> weakRef;
 };
 
 template <typename T>
-class SupportsWeakPtr
-  : public SupportsWeakPtrBase<T, detail::WeakReference<T, detail::NonAtomicRefCount> >
-{
-};
-
-template <typename T>
-class AtomicSupportsWeakPtr
-  : public SupportsWeakPtrBase<T, detail::WeakReference<T, detail::AtomicRefCount> >
+class SupportsWeakPtr : public SupportsWeakPtrBase<T, detail::WeakReference<T> >
 {
 };
 
-namespace detail {
-
-template <typename T>
-struct WeakReferenceCount
-{
-  static const RefCountAtomicity atomicity =
-    IsBaseOf<AtomicSupportsWeakPtr<T>, T>::value
-    ? AtomicRefCount
-    : NonAtomicRefCount;
-};
-
-}
-
 template <typename T, class WeakReference>
 class WeakPtrBase
 {
   public:
     WeakPtrBase(const WeakPtrBase<T, WeakReference>& o) : ref(o.ref) {}
     // Ensure that ref is dereferenceable in the uninitialized state
     WeakPtrBase() : ref(new WeakReference(nullptr)) {}
 
@@ -172,19 +148,19 @@ class WeakPtrBase
     friend class SupportsWeakPtrBase<T, WeakReference>;
 
     explicit WeakPtrBase(const RefPtr<WeakReference> &o) : ref(o) {}
 
     RefPtr<WeakReference> ref;
 };
 
 template <typename T>
-class WeakPtr : public WeakPtrBase<T, detail::WeakReference<T, detail::WeakReferenceCount<T>::atomicity> >
+class WeakPtr : public WeakPtrBase<T, detail::WeakReference<T> >
 {
-    typedef WeakPtrBase<T, detail::WeakReference<T, detail::WeakReferenceCount<T>::atomicity> > Base;
+    typedef WeakPtrBase<T, detail::WeakReference<T> > Base;
   public:
     WeakPtr(const WeakPtr<T>& o) : Base(o) {}
     WeakPtr(const Base& o) : Base(o) {}
     WeakPtr() {}
 };
 
 } // namespace mozilla