RefCounted
来源:互联网 发布:手机整人软件 编辑:程序博客网 时间:2024/06/07 01:16
class RefCountedBase {
protected:
RefCountedBase();
~RefCountedBase();
void AddRef();
// Returns true if the object should self-delete.
bool Release();
private:
int ref_count_;
#ifndef NDEBUG
bool in_dtor_;
#endif
DFAKE_MUTEX(add_release_);
DISALLOW_COPY_AND_ASSIGN(RefCountedBase);
};
RefCountedBase::RefCountedBase() : ref_count_(0) {
#ifndef NDEBUG
in_dtor_ = false;
#endif
}
RefCountedBase::~RefCountedBase() {
#ifndef NDEBUG
DCHECK(in_dtor_) << "RefCounted object deleted without calling Release()";
#endif
}
void RefCountedBase::AddRef() {
// TODO(maruel): Add back once it doesn't assert 500 times/sec.
// Current thread books the critical section "AddRelease" without release it.
// DFAKE_SCOPED_LOCK_THREAD_LOCKED(add_release_);
#ifndef NDEBUG
DCHECK(!in_dtor_);
#endif
++ref_count_;
}
bool RefCountedBase::Release() {
// TODO(maruel): Add back once it doesn't assert 500 times/sec.
// Current thread books the critical section "AddRelease" without release it.
// DFAKE_SCOPED_LOCK_THREAD_LOCKED(add_release_);
#ifndef NDEBUG
DCHECK(!in_dtor_);
#endif
if (--ref_count_ == 0) {
#ifndef NDEBUG
in_dtor_ = true;
#endif
return true;
}
return false;
}
template <class T>
class RefCounted : public subtle::RefCountedBase {
public:
RefCounted() { }
~RefCounted() { }
void AddRef() {
subtle::RefCountedBase::AddRef();
}
void Release() {
if (subtle::RefCountedBase::Release()) {
delete static_cast<T*>(this);
}
}
private:
DISALLOW_COPY_AND_ASSIGN(RefCounted<T>);
};
- RefCounted
- WebKit源代码里的RefCounted
- WebKit的智能指针分析 - Part 1:RefCounted
- WebKit的智能指针分析 - Part 1:RefCounted
- WebKit的智能指针分析 - Part 1:RefCounted
- WebKit的智能指针分析 - Part 1:RefCounted
- WebKit的智能指针分析 - Part 1:RefCounted
- 探索WebKit内核(五)------ 智能指针解析:RefCounted, RefPtr, PassRefPtr, OwnPtr和PassOwnPtr
- error C2253: 'RefCounted<T>' : pure specifier or abstract override specifier only allowed on virtual
- Linux字符设备驱动程序的编写框架
- Struts原理与实践(3)
- E.OFFICE
- Extjs 研究:事件
- MapXtreme实用技巧与源码10例
- RefCounted
- Moving TempDB
- 利用udev、sys动态创建linux设备结点
- RefCountedThreadSafe
- unix系统vi中常用的命令
- ARM linux系统调用的实现原理
- MFC 日期格式
- 认识网卡
- 数据字典(SQL2005)