Coverage Report

Created: 2025-04-27 02:50

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