Coverage Report

Created: 2024-11-20 19:28

/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
5
{
20
5
}
21
22
5
RefCountedBase::~RefCountedBase() {
23
5
#ifndef NDEBUG
24
5
    DCHECK(in_dtor_) << "RefCounted object deleted without calling Release()";
25
5
#endif
26
5
}
27
28
27
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
27
#ifndef NDEBUG
33
27
    DCHECK(!in_dtor_);
34
27
#endif
35
27
    ++ref_count_;
36
27
}
37
38
27
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
27
#ifndef NDEBUG
43
27
    DCHECK(!in_dtor_);
44
27
#endif
45
27
    if (--ref_count_ == 0) {
46
5
#ifndef NDEBUG
47
5
        in_dtor_ = true;
48
5
#endif
49
5
        return true;
50
5
    }
51
22
    return false;
52
27
}
53
54
0
bool RefCountedThreadSafeBase::HasOneRef() const {
55
0
    return base::RefCountIsOne(&const_cast<RefCountedThreadSafeBase*>(this)->ref_count_);
56
0
}
57
58
3.90k
RefCountedThreadSafeBase::RefCountedThreadSafeBase() : ref_count_(0) {
59
3.90k
#ifndef NDEBUG
60
3.90k
    in_dtor_ = false;
61
3.90k
#endif
62
3.90k
}
63
64
3.90k
RefCountedThreadSafeBase::~RefCountedThreadSafeBase() {
65
3.90k
#ifndef NDEBUG
66
3.90k
    DCHECK(in_dtor_) << "RefCountedThreadSafe object deleted without "
67
0
                        "calling Release()";
68
3.90k
#endif
69
3.90k
}
70
71
9.06k
void RefCountedThreadSafeBase::AddRef() const {
72
9.06k
#ifndef NDEBUG
73
9.06k
    DCHECK(!in_dtor_);
74
9.06k
#endif
75
9.06k
    base::RefCountInc(&ref_count_);
76
9.06k
}
77
78
9.06k
bool RefCountedThreadSafeBase::Release() const {
79
9.06k
#ifndef NDEBUG
80
9.06k
    DCHECK(!in_dtor_);
81
9.06k
    DCHECK(!base::RefCountIsZero(&ref_count_));
82
9.06k
#endif
83
9.06k
    if (!base::RefCountDec(&ref_count_)) {
84
3.90k
#ifndef NDEBUG
85
3.90k
        in_dtor_ = true;
86
3.90k
#endif
87
3.90k
        return true;
88
3.90k
    }
89
5.16k
    return false;
90
9.06k
}
91
92
} // namespace subtle
93
94
} // namespace doris