Skip to content

Commit

Permalink
优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
HEYAHONG committed Jan 20, 2025
1 parent 371413f commit 48300b9
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions hbox/cpp/hobj.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,21 +124,19 @@ class hstaticobjectext:public hstaticobjectbase
*/
virtual void ref_inc()
{
lock();
hlockguard<hlock> m_lock(*this);
((hobject_base_t *)(*this))->ref_cnt++;
unlock();
}
/*
* 引用计数减
*/
virtual void ref_dec()
{
lock();
hlockguard<hlock> m_lock(*this);
if(ref_count()>0)
{
((hobject_base_t *)(*this))->ref_cnt--;
}
unlock();
}
};

Expand Down Expand Up @@ -306,26 +304,31 @@ class hstaticobject:public hstaticobjectbase
{
return hobject_uint64((hobject_base_t *)&obj_data);
}
/*
* 获取当前引用计数,0表示无任何引用(此时可以删除对象)
*/
virtual size_t ref_count()
{
return ((hobject_base_t *)(*this))->ref_cnt;
}
/*
* 引用计数加
*/
virtual void ref_inc()
{
lock();
hlockguard<hlock> m_lock(*this);
((hobject_base_t *)(*this))->ref_cnt++;
unlock();
}
/*
* 引用计数减
*/
virtual void ref_dec()
{
lock();
hlockguard<hlock> m_lock(*this);
if(ref_count()>0)
{
((hobject_base_t *)(*this))->ref_cnt--;
}
unlock();
}
};

Expand Down

0 comments on commit 48300b9

Please sign in to comment.