Coverage Report

Created: 2026-06-30 07:33

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/log4cplus/src/pointer.cxx
Line
Count
Source
1
// Module:  Log4CPLUS
2
// File:    pointer.cxx
3
// Created: 6/2001
4
// Author:  Tad E. Smith
5
//
6
//
7
// Copyright 2001-2017 Tad E. Smith
8
//
9
// Licensed under the Apache License, Version 2.0 (the "License");
10
// you may not use this file except in compliance with the License.
11
// You may obtain a copy of the License at
12
//
13
//     http://www.apache.org/licenses/LICENSE-2.0
14
//
15
// Unless required by applicable law or agreed to in writing, software
16
// distributed under the License is distributed on an "AS IS" BASIS,
17
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
// See the License for the specific language governing permissions and
19
// limitations under the License.
20
21
#include <log4cplus/streams.h>
22
#include <log4cplus/helpers/pointer.h>
23
#include <log4cplus/thread/threads.h>
24
#include <log4cplus/thread/impl/syncprims-impl.h>
25
#include <cassert>
26
27
28
namespace log4cplus { namespace helpers {
29
30
31
///////////////////////////////////////////////////////////////////////////////
32
// log4cplus::helpers::SharedObject dtor
33
///////////////////////////////////////////////////////////////////////////////
34
35
SharedObject::~SharedObject()
36
517k
{
37
517k
    assert(count__ == 0);
38
517k
}
39
40
41
42
///////////////////////////////////////////////////////////////////////////////
43
// log4cplus::helpers::SharedObject public methods
44
///////////////////////////////////////////////////////////////////////////////
45
46
void
47
SharedObject::addReference() const LOG4CPLUS_NOEXCEPT
48
9.86M
{
49
#if defined (LOG4CPLUS_SINGLE_THREADED)
50
    ++count__;
51
52
#else
53
9.86M
    std::atomic_fetch_add_explicit (&count__, 1u,
54
9.86M
        std::memory_order_relaxed);
55
56
9.86M
#endif
57
9.86M
}
58
59
60
void
61
SharedObject::removeReference() const
62
9.86M
{
63
9.86M
    assert (count__ > 0);
64
9.86M
    bool destroy;
65
66
#if defined (LOG4CPLUS_SINGLE_THREADED)
67
    destroy = --count__ == 0;
68
69
#else
70
9.86M
    destroy = std::atomic_fetch_sub_explicit (&count__, 1u,
71
9.86M
        std::memory_order_release) == 1;
72
9.86M
    if (LOG4CPLUS_UNLIKELY (destroy))
73
517k
        std::atomic_thread_fence (std::memory_order_acquire);
74
75
9.86M
#endif
76
9.86M
    if (LOG4CPLUS_UNLIKELY (destroy))
77
517k
        delete this;
78
9.86M
}
79
80
81
} } // namespace log4cplus { namespace helpers