File indexing completed on 2025-07-05 09:10:22
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 std::lock_guard<std::mutex> lock(other.mutex_);
0013 enabled_ = other.enabled();
0014 messages_ = other.messages_;
0015 }
0016
0017 SPDLOG_INLINE backtracer::backtracer(backtracer &&other) SPDLOG_NOEXCEPT {
0018 std::lock_guard<std::mutex> lock(other.mutex_);
0019 enabled_ = other.enabled();
0020 messages_ = std::move(other.messages_);
0021 }
0022
0023 SPDLOG_INLINE backtracer &backtracer::operator=(backtracer other) {
0024 std::lock_guard<std::mutex> lock(mutex_);
0025 enabled_ = other.enabled();
0026 messages_ = std::move(other.messages_);
0027 return *this;
0028 }
0029
0030 SPDLOG_INLINE void backtracer::enable(size_t size) {
0031 std::lock_guard<std::mutex> lock{mutex_};
0032 enabled_.store(true, std::memory_order_relaxed);
0033 messages_ = circular_q<log_msg_buffer>{size};
0034 }
0035
0036 SPDLOG_INLINE void backtracer::disable() {
0037 std::lock_guard<std::mutex> lock{mutex_};
0038 enabled_.store(false, std::memory_order_relaxed);
0039 }
0040
0041 SPDLOG_INLINE bool backtracer::enabled() const { return enabled_.load(std::memory_order_relaxed); }
0042
0043 SPDLOG_INLINE void backtracer::push_back(const log_msg &msg) {
0044 std::lock_guard<std::mutex> lock{mutex_};
0045 messages_.push_back(log_msg_buffer{msg});
0046 }
0047
0048 SPDLOG_INLINE bool backtracer::empty() const {
0049 std::lock_guard<std::mutex> lock{mutex_};
0050 return messages_.empty();
0051 }
0052
0053
0054 SPDLOG_INLINE void backtracer::foreach_pop(std::function<void(const details::log_msg &)> fun) {
0055 std::lock_guard<std::mutex> lock{mutex_};
0056 while (!messages_.empty()) {
0057 auto &front_msg = messages_.front();
0058 fun(front_msg);
0059 messages_.pop_front();
0060 }
0061 }
0062 }
0063 }