Title: [130365] trunk/Source/WTF
- Revision
- 130365
- Author
- [email protected]
- Date
- 2012-10-03 23:21:57 -0700 (Wed, 03 Oct 2012)
Log Message
[Refactoring] Tidy NDEBUG optioning in RefCountedBase.
https://bugs.webkit.org/show_bug.cgi?id=98252
Patch by Kangil Han <[email protected]> on 2012-10-03
Reviewed by Benjamin Poulain.
Fixed incomplete implementation for NDEBUG option.
Additionally, adopted CHECK_REF_COUNTED_LIFECYCLE definition to suppress abusing NDEBUG option.
* wtf/RefCounted.h:
(WTF):
(WTF::RefCountedBase::ref):
(WTF::RefCountedBase::hasOneRef):
(WTF::RefCountedBase::refCount):
(WTF::RefCountedBase::turnOffVerifier):
(WTF::RefCountedBase::relaxAdoptionRequirement):
(WTF::RefCountedBase::RefCountedBase):
(WTF::RefCountedBase::~RefCountedBase):
(WTF::RefCountedBase::derefBase):
(RefCountedBase):
(WTF::adopted):
(WTF::RefCountedBase::setMutexForVerifier):
(WTF::RefCountedBase::setDispatchQueueForVerifier):
Modified Paths
Diff
Modified: trunk/Source/WTF/ChangeLog (130364 => 130365)
--- trunk/Source/WTF/ChangeLog 2012-10-04 05:46:28 UTC (rev 130364)
+++ trunk/Source/WTF/ChangeLog 2012-10-04 06:21:57 UTC (rev 130365)
@@ -1,3 +1,28 @@
+2012-10-03 Kangil Han <[email protected]>
+
+ [Refactoring] Tidy NDEBUG optioning in RefCountedBase.
+ https://bugs.webkit.org/show_bug.cgi?id=98252
+
+ Reviewed by Benjamin Poulain.
+
+ Fixed incomplete implementation for NDEBUG option.
+ Additionally, adopted CHECK_REF_COUNTED_LIFECYCLE definition to suppress abusing NDEBUG option.
+
+ * wtf/RefCounted.h:
+ (WTF):
+ (WTF::RefCountedBase::ref):
+ (WTF::RefCountedBase::hasOneRef):
+ (WTF::RefCountedBase::refCount):
+ (WTF::RefCountedBase::turnOffVerifier):
+ (WTF::RefCountedBase::relaxAdoptionRequirement):
+ (WTF::RefCountedBase::RefCountedBase):
+ (WTF::RefCountedBase::~RefCountedBase):
+ (WTF::RefCountedBase::derefBase):
+ (RefCountedBase):
+ (WTF::adopted):
+ (WTF::RefCountedBase::setMutexForVerifier):
+ (WTF::RefCountedBase::setDispatchQueueForVerifier):
+
2012-10-03 Yury Semikhatsky <[email protected]>
Remove MemoryInstrumentation::addCollectionElements
Modified: trunk/Source/WTF/wtf/RefCounted.h (130364 => 130365)
--- trunk/Source/WTF/wtf/RefCounted.h 2012-10-04 05:46:28 UTC (rev 130364)
+++ trunk/Source/WTF/wtf/RefCounted.h 2012-10-04 06:21:57 UTC (rev 130365)
@@ -30,6 +30,12 @@
namespace WTF {
+#ifdef NDEBUG
+#define CHECK_REF_COUNTED_LIFECYCLE 0
+#else
+#define CHECK_REF_COUNTED_LIFECYCLE 1
+#endif
+
// 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).
@@ -37,7 +43,7 @@
public:
void ref()
{
-#ifndef NDEBUG
+#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.
@@ -46,26 +52,30 @@
// We should be able to add a "detachFromThread" method to make this explicit.
if (m_refCount == 1)
m_verifier.setShared(true);
-#endif
// 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
ASSERT(m_verifier.isSafeToUse());
ASSERT(!m_deletionHasBegun);
+#endif
return m_refCount == 1;
}
int refCount() const
{
+#if CHECK_REF_COUNTED_LIFECYCLE
ASSERT(m_verifier.isSafeToUse());
+#endif
return m_refCount;
}
@@ -87,14 +97,14 @@
// safe version of reference counting.
void turnOffVerifier()
{
-#ifndef NDEBUG
+#if CHECK_REF_COUNTED_LIFECYCLE
m_verifier.turnOffVerification();
#endif
}
void relaxAdoptionRequirement()
{
-#ifndef NDEBUG
+#if CHECK_REF_COUNTED_LIFECYCLE
ASSERT(!m_deletionHasBegun);
ASSERT(m_adoptionIsRequired);
m_adoptionIsRequired = false;
@@ -110,7 +120,7 @@
protected:
RefCountedBase()
: m_refCount(1)
-#ifndef NDEBUG
+#if CHECK_REF_COUNTED_LIFECYCLE
, m_deletionHasBegun(false)
, m_adoptionIsRequired(true)
#endif
@@ -119,27 +129,31 @@
~RefCountedBase()
{
+#if CHECK_REF_COUNTED_LIFECYCLE
ASSERT(m_deletionHasBegun);
ASSERT(!m_adoptionIsRequired);
+#endif
}
// Returns whether the pointer should be freed or not.
bool derefBase()
{
+#if CHECK_REF_COUNTED_LIFECYCLE
ASSERT(m_verifier.isSafeToUse());
ASSERT(!m_deletionHasBegun);
ASSERT(!m_adoptionIsRequired);
+#endif
ASSERT(m_refCount > 0);
if (m_refCount == 1) {
-#ifndef NDEBUG
+#if CHECK_REF_COUNTED_LIFECYCLE
m_deletionHasBegun = true;
#endif
return true;
}
--m_refCount;
-#ifndef NDEBUG
+#if CHECK_REF_COUNTED_LIFECYCLE
// Stop thread verification when the ref goes to 1 because it
// is safe to be passed to another thread at this point.
if (m_refCount == 1)
@@ -148,7 +162,7 @@
return false;
}
-#ifndef NDEBUG
+#if CHECK_REF_COUNTED_LIFECYCLE
bool deletionHasBegun() const
{
return m_deletionHasBegun;
@@ -157,20 +171,19 @@
private:
-#ifndef NDEBUG
+#if CHECK_REF_COUNTED_LIFECYCLE
friend void adopted(RefCountedBase*);
#endif
int m_refCount;
-#ifndef NDEBUG
+#if CHECK_REF_COUNTED_LIFECYCLE
bool m_deletionHasBegun;
bool m_adoptionIsRequired;
ThreadRestrictionVerifier m_verifier;
#endif
};
-#ifndef NDEBUG
-
+#if CHECK_REF_COUNTED_LIFECYCLE
inline void adopted(RefCountedBase* object)
{
if (!object)
@@ -178,7 +191,6 @@
ASSERT(!object->m_deletionHasBegun);
object->m_adoptionIsRequired = false;
}
-
#endif
template<typename T> class RefCounted : public RefCountedBase {
@@ -213,24 +225,24 @@
}
};
-#ifdef NDEBUG
-inline void RefCountedBase::setMutexForVerifier(Mutex&) { }
-#else
+#if CHECK_REF_COUNTED_LIFECYCLE
inline void RefCountedBase::setMutexForVerifier(Mutex& mutex)
{
m_verifier.setMutexMode(mutex);
}
+#else
+inline void RefCountedBase::setMutexForVerifier(Mutex&) { }
#endif
#if HAVE(DISPATCH_H)
-#ifdef NDEBUG
-inline void RefCountedBase::setDispatchQueueForVerifier(dispatch_queue_t) { }
-#else
+#if CHECK_REF_COUNTED_LIFECYCLE
inline void RefCountedBase::setDispatchQueueForVerifier(dispatch_queue_t queue)
{
m_verifier.setDispatchQueueMode(queue);
}
-#endif // NDEBUG
+#else
+inline void RefCountedBase::setDispatchQueueForVerifier(dispatch_queue_t) { }
+#endif
#endif // HAVE(DISPATCH_H)
} // namespace WTF
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes