// This base class holds the non-template methods and attributes.
// The RefCounted class inherits from it reducing the template bloat
// generated by the compiler (technique called template hoisting).
-class RefCountedBase : Noncopyable {
+class RefCountedBase {
public:
void ref()
{
}
protected:
- RefCountedBase(int initialRefCount)
- : m_refCount(initialRefCount)
+ RefCountedBase()
+ : m_refCount(1)
#ifndef NDEBUG
, m_deletionHasBegun(false)
#endif
{
}
- ~RefCountedBase() {}
+ ~RefCountedBase()
+ {
+ }
// Returns whether the pointer should be freed or not.
bool derefBase()
return false;
}
-protected:
+ // Helper for generating JIT code. Please do not use for non-JIT purposes.
+ int* addressOfCount()
+ {
+ return &m_refCount;
+ }
+
+#ifndef NDEBUG
+ bool deletionHasBegun() const
+ {
+ return m_deletionHasBegun;
+ }
+#endif
+
+private:
+ template<class T>
+ friend class CrossThreadRefCounted;
+
int m_refCount;
#ifndef NDEBUG
bool m_deletionHasBegun;
};
-template<class T> class RefCounted : public RefCountedBase {
+template<class T> class RefCounted : public RefCountedBase, public Noncopyable {
public:
- RefCounted(int initialRefCount = 1)
- : RefCountedBase(initialRefCount)
+ void deref()
{
+ if (derefBase())
+ delete static_cast<T*>(this);
}
+protected:
+ ~RefCounted()
+ {
+ }
+};
+
+template<class T> class RefCountedCustomAllocated : public RefCountedBase, public NoncopyableCustomAllocated {
+public:
void deref()
{
if (derefBase())
}
protected:
- ~RefCounted() {}
+ ~RefCountedCustomAllocated()
+ {
+ }
};
} // namespace WTF
using WTF::RefCounted;
+using WTF::RefCountedCustomAllocated;
#endif // RefCounted_h