2 * Copyright (C) 2006, 2007, 2009, 2010 Apple Inc. All rights reserved.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
24 #include <wtf/Assertions.h>
25 #include <wtf/MainThread.h>
26 #include <wtf/Noncopyable.h>
31 template<typename T> class TreeShared;
32 template<typename T> void adopted(TreeShared<T>*);
35 template<typename T> class TreeShared {
36 WTF_MAKE_NONCOPYABLE(TreeShared);
42 , m_adoptionIsRequired(true)
45 ASSERT(isMainThread());
47 m_deletionHasBegun = false;
48 m_inRemovedLastRefFunction = false;
53 ASSERT(isMainThread());
55 ASSERT(m_deletionHasBegun);
56 ASSERT(!m_adoptionIsRequired);
61 ASSERT(isMainThread());
62 ASSERT(!m_deletionHasBegun);
63 ASSERT(!m_inRemovedLastRefFunction);
64 ASSERT(!m_adoptionIsRequired);
70 ASSERT(isMainThread());
71 ASSERT(m_refCount >= 0);
72 ASSERT(!m_deletionHasBegun);
73 ASSERT(!m_inRemovedLastRefFunction);
74 ASSERT(!m_adoptionIsRequired);
75 if (--m_refCount <= 0 && !m_parent) {
77 m_inRemovedLastRefFunction = true;
83 bool hasOneRef() const
85 ASSERT(!m_deletionHasBegun);
86 ASSERT(!m_inRemovedLastRefFunction);
87 return m_refCount == 1;
95 void setParent(T* parent)
97 ASSERT(isMainThread());
103 ASSERT(isMainThreadOrGCThread());
108 bool m_deletionHasBegun;
109 bool m_inRemovedLastRefFunction;
113 virtual void removedLastRef()
116 m_deletionHasBegun = true;
123 friend void adopted<>(TreeShared<T>*);
130 bool m_adoptionIsRequired;
136 template<typename T> inline void adopted(TreeShared<T>* object)
140 ASSERT(!object->m_deletionHasBegun);
141 ASSERT(!object->m_inRemovedLastRefFunction);
142 object->m_adoptionIsRequired = false;
149 #endif // TreeShared.h