Coverage Report

Created: 2025-05-20 23:17

/root/doris/be/src/gutil/ref_counted.cc
Line
Count
Source (jump to first uncovered line)
1
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style license that can be
3
// found in the LICENSE file.
4
5
#include "gutil/ref_counted.h"
6
7
#include "gutil/atomic_refcount.h"
8
9
namespace doris {
10
11
namespace subtle {
12
13
RefCountedBase::RefCountedBase()
14
        : ref_count_(0)
15
#ifndef NDEBUG
16
          ,
17
          in_dtor_(false)
18
#endif
19
0
{
20
0
}
21
22
0
RefCountedBase::~RefCountedBase() {
23
0
#ifndef NDEBUG
24
0
    DCHECK(in_dtor_) << "RefCounted object deleted without calling Release()";
25
0
#endif
26
0
}
27
28
0
void RefCountedBase::AddRef() const {
29
    // TODO(maruel): Add back once it doesn't assert 500 times/sec.
30
    // Current thread books the critical section "AddRelease" without release it.
31
    // DFAKE_SCOPED_LOCK_THREAD_LOCKED(add_release_);
32
0
#ifndef NDEBUG
33
0
    DCHECK(!in_dtor_);
34
0
#endif
35
0
    ++ref_count_;
36
0
}
37
38
0
bool RefCountedBase::Release() const {
39
    // TODO(maruel): Add back once it doesn't assert 500 times/sec.
40
    // Current thread books the critical section "AddRelease" without release it.
41
    // DFAKE_SCOPED_LOCK_THREAD_LOCKED(add_release_);
42
0
#ifndef NDEBUG
43
0
    DCHECK(!in_dtor_);
44
0
#endif
45
0
    if (--ref_count_ == 0) {
46
0
#ifndef NDEBUG
47
0
        in_dtor_ = true;
48
0
#endif
49
0
        return true;
50
0
    }
51
0
    return false;
52
0
}
53
54
0
bool RefCountedThreadSafeBase::HasOneRef() const {
55
0
    return base::RefCountIsOne(&const_cast<RefCountedThreadSafeBase*>(this)->ref_count_);
56
0
}
57
58
2.75k
RefCountedThreadSafeBase::RefCountedThreadSafeBase() : ref_count_(0) {
59
2.75k
#ifndef NDEBUG
60
2.75k
    in_dtor_ = false;
61
2.75k
#endif
62
2.75k
}
63
64
2.72k
RefCountedThreadSafeBase::~RefCountedThreadSafeBase() {
65
2.72k
#ifndef NDEBUG
66
2.72k
    DCHECK(in_dtor_) << "RefCountedThreadSafe object deleted without "
67
1
                        "calling Release()";
68
2.72k
#endif
69
2.72k
}
70
71
6.60k
void RefCountedThreadSafeBase::AddRef() const {
72
6.60k
#ifndef NDEBUG
73
6.60k
    DCHECK(!in_dtor_);
74
6.60k
#endif
75
6.60k
    base::RefCountInc(&ref_count_);
76
6.60k
}
77
78
6.56k
bool RefCountedThreadSafeBase::Release() const {
79
6.56k
#ifndef NDEBUG
80
6.56k
    DCHECK(!in_dtor_);
81
6.56k
    DCHECK(!base::RefCountIsZero(&ref_count_));
82
6.56k
#endif
83
6.56k
    if (!base::RefCountDec(&ref_count_)) {
84
2.72k
#ifndef NDEBUG
85
2.72k
        in_dtor_ = true;
86
2.72k
#endif
87
2.72k
        return true;
88
2.72k
    }
89
3.83k
    return false;
90
6.56k
}
91
92
} // namespace subtle
93
94
} // namespace doris