Changeset 27763 in webkit for trunk/JavaScriptCore/wtf/Shared.h
- Timestamp:
- Nov 13, 2007, 4:30:19 PM (18 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/wtf/Shared.h
r27721 r27763 25 25 #include <wtf/Noncopyable.h> 26 26 27 namespace W ebCore{27 namespace WTF { 28 28 29 29 template<class T> class Shared : Noncopyable { … … 72 72 }; 73 73 74 template<class T> class TreeShared : Noncopyable { 75 public: 76 TreeShared() 77 : m_refCount(0) 78 , m_parent(0) 79 { 80 #ifndef NDEBUG 81 m_deletionHasBegun = false; 82 m_inRemovedLastRefFunction = false; 83 #endif 84 } 85 TreeShared(T* parent) 86 : m_refCount(0) 87 , m_parent(0) 88 { 89 #ifndef NDEBUG 90 m_deletionHasBegun = false; 91 m_inRemovedLastRefFunction = false; 92 #endif 93 } 94 virtual ~TreeShared() 95 { 96 ASSERT(m_deletionHasBegun); 97 } 74 } // namespace WTF 98 75 99 void ref() 100 { 101 ASSERT(!m_deletionHasBegun); 102 ASSERT(!m_inRemovedLastRefFunction); 103 ++m_refCount; 104 } 105 106 void deref() 107 { 108 ASSERT(!m_deletionHasBegun); 109 ASSERT(!m_inRemovedLastRefFunction); 110 if (--m_refCount <= 0 && !m_parent) { 111 #ifndef NDEBUG 112 m_inRemovedLastRefFunction = true; 113 #endif 114 removedLastRef(); 115 } 116 } 117 118 bool hasOneRef() const 119 { 120 ASSERT(!m_deletionHasBegun); 121 ASSERT(!m_inRemovedLastRefFunction); 122 return m_refCount == 1; 123 } 124 125 int refCount() const 126 { 127 return m_refCount; 128 } 129 130 void setParent(T* parent) { m_parent = parent; } 131 T* parent() const { return m_parent; } 132 133 #ifndef NDEBUG 134 bool m_deletionHasBegun; 135 bool m_inRemovedLastRefFunction; 136 #endif 137 138 private: 139 virtual void removedLastRef() 140 { 141 #ifndef NDEBUG 142 m_deletionHasBegun = true; 143 #endif 144 delete this; 145 } 146 147 int m_refCount; 148 T* m_parent; 149 }; 150 151 } 76 using WTF::Shared; 152 77 153 78 #endif
Note:
See TracChangeset
for help on using the changeset viewer.