]> git.proxmox.com Git - ceph.git/blame - ceph/src/common/RefCountedObj.cc
import ceph quincy 17.2.4
[ceph.git] / ceph / src / common / RefCountedObj.cc
CommitLineData
9f95a23c
TL
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
3//
4#include "include/ceph_assert.h"
5
6#include "common/RefCountedObj.h"
7#include "common/ceph_context.h"
8#include "common/dout.h"
9#include "common/valgrind.h"
10
11namespace TOPNSPC::common {
12RefCountedObject::~RefCountedObject()
13{
14 ceph_assert(nref == 0);
15}
16
17void RefCountedObject::put() const {
18 CephContext *local_cct = cct;
19 auto v = --nref;
20 if (local_cct) {
21 lsubdout(local_cct, refs, 1) << "RefCountedObject::put " << this << " "
22 << (v + 1) << " -> " << v
23 << dendl;
24 }
25 if (v == 0) {
26 ANNOTATE_HAPPENS_AFTER(&nref);
27 ANNOTATE_HAPPENS_BEFORE_FORGET_ALL(&nref);
28 delete this;
29 } else {
30 ANNOTATE_HAPPENS_BEFORE(&nref);
31 }
32}
33
34void RefCountedObject::_get() const {
35 auto v = ++nref;
36 ceph_assert(v > 1); /* it should never happen that _get() sees nref == 0 */
37 if (cct) {
38 lsubdout(cct, refs, 1) << "RefCountedObject::get " << this << " "
39 << (v - 1) << " -> " << v << dendl;
40 }
41}
42
43}