| Index: Source/wtf/RefCounted.h
|
| diff --git a/Source/wtf/RefCounted.h b/Source/wtf/RefCounted.h
|
| index 0504b9ed2818d7ad9fd164fd9c5a256ab6036c9e..d7214a964fc97071f10aae3636cb248756858c30 100644
|
| --- a/Source/wtf/RefCounted.h
|
| +++ b/Source/wtf/RefCounted.h
|
| @@ -33,7 +33,13 @@ namespace WTF {
|
| #ifdef NDEBUG
|
| #define CHECK_REF_COUNTED_LIFECYCLE 0
|
| #else
|
| -#define CHECK_REF_COUNTED_LIFECYCLE 1
|
| +// FIXME(oilpan): Enable this check once we replace all
|
| +// RefCountedHeapAllocated with HeapAllocated.
|
| +// We have to disable the check for RefCountedHeapAllocated
|
| +// since we have to allow the following situation in RefCountedHeapAllocated.
|
| +// (1) A reference count becomes 0, but Handles keep references to the object.
|
| +// (2) The Handle is assigned to a RefPtr. The reference count becomes 1.
|
| +#define CHECK_REF_COUNTED_LIFECYCLE 0
|
| #endif
|
|
|
| // This base class holds the non-template methods and attributes.
|
| @@ -41,27 +47,6 @@ namespace WTF {
|
| // generated by the compiler (technique called template hoisting).
|
| class RefCountedBase {
|
| public:
|
| - void ref()
|
| - {
|
| -#if CHECK_REF_COUNTED_LIFECYCLE
|
| - // Start thread verification as soon as the ref count gets to 2. This
|
| - // heuristic reflects the fact that items are often created on one thread
|
| - // and then given to another thread to be used.
|
| - // FIXME: Make this restriction tigher. Especially as we move to more
|
| - // common methods for sharing items across threads like CrossThreadCopier.h
|
| - // We should be able to add a "detachFromThread" method to make this explicit.
|
| - if (m_refCount == 1)
|
| - m_verifier.setShared(true);
|
| - // If this assert fires, it either indicates a thread safety issue or
|
| - // that the verification needs to change. See ThreadRestrictionVerifier for
|
| - // the different modes.
|
| - ASSERT(m_verifier.isSafeToUse());
|
| - ASSERT(!m_deletionHasBegun);
|
| - ASSERT(!m_adoptionIsRequired);
|
| -#endif
|
| - ++m_refCount;
|
| - }
|
| -
|
| bool hasOneRef() const
|
| {
|
| #if CHECK_REF_COUNTED_LIFECYCLE
|
| @@ -135,6 +120,27 @@ protected:
|
| #endif
|
| }
|
|
|
| + void refBase()
|
| + {
|
| +#if CHECK_REF_COUNTED_LIFECYCLE
|
| + // Start thread verification as soon as the ref count gets to 2. This
|
| + // heuristic reflects the fact that items are often created on one thread
|
| + // and then given to another thread to be used.
|
| + // FIXME: Make this restriction tigher. Especially as we move to more
|
| + // common methods for sharing items across threads like CrossThreadCopier.h
|
| + // We should be able to add a "detachFromThread" method to make this explicit.
|
| + if (m_refCount == 1)
|
| + m_verifier.setShared(true);
|
| + // If this assert fires, it either indicates a thread safety issue or
|
| + // that the verification needs to change. See ThreadRestrictionVerifier for
|
| + // the different modes.
|
| + ASSERT(m_verifier.isSafeToUse());
|
| + ASSERT(!m_deletionHasBegun);
|
| + ASSERT(!m_adoptionIsRequired);
|
| +#endif
|
| + ++m_refCount;
|
| + }
|
| +
|
| // Returns whether the pointer should be freed or not.
|
| bool derefBase()
|
| {
|
| @@ -149,6 +155,7 @@ protected:
|
| #if CHECK_REF_COUNTED_LIFECYCLE
|
| m_deletionHasBegun = true;
|
| #endif
|
| + --m_refCount;
|
| return true;
|
| }
|
|
|
| @@ -196,6 +203,11 @@ inline void adopted(RefCountedBase* object)
|
| template<typename T> class RefCounted : public RefCountedBase {
|
| WTF_MAKE_NONCOPYABLE(RefCounted); WTF_MAKE_FAST_ALLOCATED;
|
| public:
|
| + void ref()
|
| + {
|
| + refBase();
|
| + }
|
| +
|
| void deref()
|
| {
|
| if (derefBase())
|
| @@ -213,6 +225,11 @@ template<typename T> class RefCountedCustomAllocated : public RefCountedBase {
|
| WTF_MAKE_NONCOPYABLE(RefCountedCustomAllocated);
|
|
|
| public:
|
| + void ref()
|
| + {
|
| + refBase();
|
| + }
|
| +
|
| void deref()
|
| {
|
| if (derefBase())
|
|
|