Changeset 41536 in webkit for trunk/JavaScriptCore/wtf/Threading.h
- Timestamp:
- Mar 9, 2009, 2:01:42 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/wtf/Threading.h
r40122 r41536 206 206 #endif 207 207 208 template<class T> class ThreadSafeShared: Noncopyable {209 public: 210 ThreadSafeShared (int initialRefCount = 1)208 class ThreadSafeSharedBase : Noncopyable { 209 public: 210 ThreadSafeSharedBase(int initialRefCount = 1) 211 211 : m_refCount(initialRefCount) 212 212 { … … 223 223 } 224 224 225 void deref() 225 bool hasOneRef() 226 { 227 return refCount() == 1; 228 } 229 230 int refCount() const 231 { 232 #if !USE(LOCKFREE_THREADSAFESHARED) 233 MutexLocker locker(m_mutex); 234 #endif 235 return static_cast<int const volatile &>(m_refCount); 236 } 237 238 protected: 239 // Returns whether the pointer should be freed or not. 240 bool derefBase() 226 241 { 227 242 #if USE(LOCKFREE_THREADSAFESHARED) 228 243 if (atomicDecrement(&m_refCount) <= 0) 229 #else 244 return true; 245 #else 246 int refCount; 230 247 { 231 248 MutexLocker locker(m_mutex); 232 249 --m_refCount; 250 refCount = m_refCount; 233 251 } 234 if (m_refCount <= 0) 235 #endif 236 delete static_cast<T*>(this); 237 } 238 239 bool hasOneRef() 240 { 241 return refCount() == 1; 242 } 243 244 int refCount() const 245 { 246 #if !USE(LOCKFREE_THREADSAFESHARED) 247 MutexLocker locker(m_mutex); 248 #endif 249 return static_cast<int const volatile &>(m_refCount); 252 if (refCount <= 0) 253 return true; 254 #endif 255 return false; 250 256 } 251 257 252 258 private: 259 template<class T> 260 friend class CrossThreadRefCounted; 261 253 262 int m_refCount; 254 263 #if !USE(LOCKFREE_THREADSAFESHARED) 255 264 mutable Mutex m_mutex; 256 265 #endif 266 }; 267 268 template<class T> class ThreadSafeShared : public ThreadSafeSharedBase { 269 public: 270 ThreadSafeShared(int initialRefCount = 1) 271 : ThreadSafeSharedBase(initialRefCount) 272 { 273 } 274 275 void deref() 276 { 277 if (derefBase()) 278 delete static_cast<T*>(this); 279 } 257 280 }; 258 281
Note:
See TracChangeset
for help on using the changeset viewer.