File indexing completed on 2025-01-30 10:24:42
0001
0002
0003
0004 #pragma once
0005
0006 #ifndef SPDLOG_HEADER_ONLY
0007 # include <spdlog/details/backtracer.h>
0008 #endif
0009 namespace spdlog {
0010 namespace details {
0011 SPDLOG_INLINE backtracer::backtracer(const backtracer &other)
0012 {
0013 std::lock_guard<std::mutex> lock(other.mutex_);
0014 enabled_ = other.enabled();
0015 messages_ = other.messages_;
0016 }
0017
0018 SPDLOG_INLINE backtracer::backtracer(backtracer &&other) SPDLOG_NOEXCEPT
0019 {
0020 std::lock_guard<std::mutex> lock(other.mutex_);
0021 enabled_ = other.enabled();
0022 messages_ = std::move(other.messages_);
0023 }
0024
0025 SPDLOG_INLINE backtracer &backtracer::operator=(backtracer other)
0026 {
0027 std::lock_guard<std::mutex> lock(mutex_);
0028 enabled_ = other.enabled();
0029 messages_ = std::move(other.messages_);
0030 return *this;
0031 }
0032
0033 SPDLOG_INLINE void backtracer::enable(size_t size)
0034 {
0035 std::lock_guard<std::mutex> lock{mutex_};
0036 enabled_.store(true, std::memory_order_relaxed);
0037 messages_ = circular_q<log_msg_buffer>{size};
0038 }
0039
0040 SPDLOG_INLINE void backtracer::disable()
0041 {
0042 std::lock_guard<std::mutex> lock{mutex_};
0043 enabled_.store(false, std::memory_order_relaxed);
0044 }
0045
0046 SPDLOG_INLINE bool backtracer::enabled() const
0047 {
0048 return enabled_.load(std::memory_order_relaxed);
0049 }
0050
0051 SPDLOG_INLINE void backtracer::push_back(const log_msg &msg)
0052 {
0053 std::lock_guard<std::mutex> lock{mutex_};
0054 messages_.push_back(log_msg_buffer{msg});
0055 }
0056
0057
0058 SPDLOG_INLINE void backtracer::foreach_pop(std::function<void(const details::log_msg &)> fun)
0059 {
0060 std::lock_guard<std::mutex> lock{mutex_};
0061 while (!messages_.empty())
0062 {
0063 auto &front_msg = messages_.front();
0064 fun(front_msg);
0065 messages_.pop_front();
0066 }
0067 }
0068 }
0069 }