Coverage Report

Created: 2025-08-08 06:58

/src/spdlog/include/spdlog/details/backtracer-inl.h
Line
Count
Source (jump to first uncovered line)
1
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
2
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
3
4
#pragma once
5
6
#ifndef SPDLOG_HEADER_ONLY
7
    #include <spdlog/details/backtracer.h>
8
#endif
9
namespace spdlog {
10
namespace details {
11
0
SPDLOG_INLINE backtracer::backtracer(const backtracer &other) {
12
0
    std::lock_guard<std::mutex> lock(other.mutex_);
13
0
    enabled_ = other.enabled();
14
0
    messages_ = other.messages_;
15
0
}
16
17
SPDLOG_INLINE backtracer::backtracer(backtracer &&other) SPDLOG_NOEXCEPT {
18
    std::lock_guard<std::mutex> lock(other.mutex_);
19
    enabled_ = other.enabled();
20
    messages_ = std::move(other.messages_);
21
}
22
23
0
SPDLOG_INLINE backtracer &backtracer::operator=(backtracer other) {
24
0
    std::lock_guard<std::mutex> lock(mutex_);
25
0
    enabled_ = other.enabled();
26
0
    messages_ = std::move(other.messages_);
27
0
    return *this;
28
0
}
29
30
0
SPDLOG_INLINE void backtracer::enable(size_t size) {
31
0
    std::lock_guard<std::mutex> lock{mutex_};
32
0
    enabled_.store(true, std::memory_order_relaxed);
33
0
    messages_ = circular_q<log_msg_buffer>{size};
34
0
}
35
36
0
SPDLOG_INLINE void backtracer::disable() {
37
0
    std::lock_guard<std::mutex> lock{mutex_};
38
0
    enabled_.store(false, std::memory_order_relaxed);
39
0
}
40
41
2.72k
SPDLOG_INLINE bool backtracer::enabled() const { return enabled_.load(std::memory_order_relaxed); }
42
43
0
SPDLOG_INLINE void backtracer::push_back(const log_msg &msg) {
44
0
    std::lock_guard<std::mutex> lock{mutex_};
45
0
    messages_.push_back(log_msg_buffer{msg});
46
0
}
47
48
0
SPDLOG_INLINE bool backtracer::empty() const {
49
0
    std::lock_guard<std::mutex> lock{mutex_};
50
0
    return messages_.empty();
51
0
}
52
53
// pop all items in the q and apply the given fun on each of them.
54
0
SPDLOG_INLINE void backtracer::foreach_pop(std::function<void(const details::log_msg &)> fun) {
55
0
    std::lock_guard<std::mutex> lock{mutex_};
56
0
    while (!messages_.empty()) {
57
0
        auto &front_msg = messages_.front();
58
0
        fun(front_msg);
59
0
        messages_.pop_front();
60
0
    }
61
0
}
62
}  // namespace details
63
}  // namespace spdlog