美文网首页
Ceph引用计数对象实现

Ceph引用计数对象实现

作者: phenom | 来源:发表于2016-12-09 11:15 被阅读0次

    类成员:

    struct RefCountedObject {
      private:
        atomic_t nref;
        CephContext *cct;
    

    原子变量nref用于对cct对象进行计数,每当调用get函数,计数加一:

      RefCountedObject *get() {
        int v = nref.inc();
        if (cct)
        lsubdout(cct, refs, 1) << "RefCountedObject::get " << this << " "<< (v - 1) << " -> " << v<< dendl;
        return this;
      }
    

    调用put函数,计数减一:

      void put() {
        CephContext *local_cct = cct;
        int v = nref.dec();
        if (v == 0) {
          ANNOTATE_HAPPENS_AFTER(&nref);
          ANNOTATE_HAPPENS_BEFORE_FORGET_ALL(&nref);
          delete this;
        } else {
          ANNOTATE_HAPPENS_BEFORE(&nref);
        }
        if (local_cct)
            lsubdout(local_cct, refs, 1) << "RefCountedObject::put " << this << " "<< (v + 1) << " -> " << v<< dendl;
      }

    相关文章

      网友评论

          本文标题:Ceph引用计数对象实现

          本文链接:https://www.haomeiwen.com/subject/noyemttx.html