summaryrefslogtreecommitdiffstats
path: root/WebCore/platform/TreeShared.h
diff options
context:
space:
mode:
Diffstat (limited to 'WebCore/platform/TreeShared.h')
-rw-r--r--WebCore/platform/TreeShared.h37
1 files changed, 33 insertions, 4 deletions
diff --git a/WebCore/platform/TreeShared.h b/WebCore/platform/TreeShared.h
index b844e5f..6e60656 100644
--- a/WebCore/platform/TreeShared.h
+++ b/WebCore/platform/TreeShared.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2006, 2007, 2009 Apple Inc. All rights reserved.
+ * Copyright (C) 2006, 2007, 2009, 2010 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -23,17 +23,23 @@
#include <wtf/Assertions.h>
#include <wtf/Noncopyable.h>
-#ifndef NDEBUG
#include <wtf/Threading.h>
-#endif
namespace WebCore {
-template<class T> class TreeShared : public Noncopyable {
+#ifndef NDEBUG
+template<typename T> class TreeShared;
+template<typename T> void adopted(TreeShared<T>*);
+#endif
+
+template<typename T> class TreeShared : public Noncopyable {
public:
TreeShared(int initialRefCount = 1)
: m_refCount(initialRefCount)
, m_parent(0)
+#ifndef NDEBUG
+ , m_adoptionIsRequired(initialRefCount == 1)
+#endif
{
ASSERT(isMainThread());
#ifndef NDEBUG
@@ -46,6 +52,7 @@ public:
ASSERT(isMainThread());
ASSERT(!m_refCount);
ASSERT(m_deletionHasBegun);
+ ASSERT(!m_adoptionIsRequired);
}
void ref()
@@ -53,6 +60,7 @@ public:
ASSERT(isMainThread());
ASSERT(!m_deletionHasBegun);
ASSERT(!m_inRemovedLastRefFunction);
+ ASSERT(!m_adoptionIsRequired);
++m_refCount;
}
@@ -62,6 +70,7 @@ public:
ASSERT(m_refCount >= 0);
ASSERT(!m_deletionHasBegun);
ASSERT(!m_inRemovedLastRefFunction);
+ ASSERT(!m_adoptionIsRequired);
if (--m_refCount <= 0 && !m_parent) {
#ifndef NDEBUG
m_inRemovedLastRefFunction = true;
@@ -100,6 +109,10 @@ public:
#endif
private:
+#ifndef NDEBUG
+ friend void adopted<>(TreeShared<T>*);
+#endif
+
virtual void removedLastRef()
{
#ifndef NDEBUG
@@ -110,8 +123,24 @@ private:
int m_refCount;
T* m_parent;
+#ifndef NDEBUG
+ bool m_adoptionIsRequired;
+#endif
};
+#ifndef NDEBUG
+
+template<typename T> inline void adopted(TreeShared<T>* object)
+{
+ if (!object)
+ return;
+ ASSERT(!object->m_deletionHasBegun);
+ ASSERT(!object->m_inRemovedLastRefFunction);
+ object->m_adoptionIsRequired = false;
+}
+
+#endif
+
}
#endif // TreeShared.h