From 31f6b371cb729a24c6706103fbf504175e20427d Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Sat, 7 Dec 2024 11:00:31 +0200 Subject: [PATCH] Fix compile --- include/spdlog/details/context.h | 1 - include/spdlog/details/periodic_worker.h | 57 ------------------------ src/details/context.cpp | 5 --- src/sinks/ansicolor_sink.cpp | 14 +++--- src/sinks/base_sink.cpp | 3 +- src/sinks/basic_file_sink.cpp | 2 +- src/sinks/rotating_file_sink.cpp | 2 - src/sinks/stdout_sinks.cpp | 4 +- src/sinks/wincolor_sink.cpp | 3 +- 9 files changed, 12 insertions(+), 79 deletions(-) delete mode 100644 include/spdlog/details/periodic_worker.h diff --git a/include/spdlog/details/context.h b/include/spdlog/details/context.h index 6059c7b5..dd27b045 100644 --- a/include/spdlog/details/context.h +++ b/include/spdlog/details/context.h @@ -13,7 +13,6 @@ #include #include "../common.h" -#include "./periodic_worker.h" namespace spdlog { class logger; diff --git a/include/spdlog/details/periodic_worker.h b/include/spdlog/details/periodic_worker.h deleted file mode 100644 index a01f66a8..00000000 --- a/include/spdlog/details/periodic_worker.h +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -// periodic worker thread - periodically executes the given callback function. -// -// RAII over the owned thread: -// creates the thread on construction. -// stops and joins the thread on destruction (if the thread is executing a callback, wait for it -// to finish first). - -#include -#include -#include -#include -#include - -#include "../common.h" - -namespace spdlog { -namespace details { - -class SPDLOG_API periodic_worker { -public: - template - periodic_worker(const std::function &callback_fun, std::chrono::duration interval) { - active_ = (interval > std::chrono::duration::zero()); - if (!active_) { - return; - } - - worker_thread_ = std::thread([this, callback_fun, interval]() { - for (;;) { - std::unique_lock lock(this->mutex_); - if (this->cv_.wait_for(lock, interval, [this] { return !this->active_; })) { - return; // active_ == false, so exit this thread - } - callback_fun(); - } - }); - } - std::thread &get_thread() { return worker_thread_; } - periodic_worker(const periodic_worker &) = delete; - periodic_worker &operator=(const periodic_worker &) = delete; - // stop the worker thread and join it - ~periodic_worker(); - -private: - bool active_; - std::thread worker_thread_; - std::mutex mutex_; - std::condition_variable cv_; -}; - -} // namespace details -} // namespace spdlog diff --git a/src/details/context.cpp b/src/details/context.cpp index 580a5e21..eb462c77 100644 --- a/src/details/context.cpp +++ b/src/details/context.cpp @@ -2,13 +2,8 @@ // Distributed under the MIT License (http://opensource.org/licenses/MIT) #include "spdlog/details/context.h" - #include "spdlog/logger.h" -#ifndef SPDLOG_DISABLE_GLOBAL_LOGGER - #include "spdlog/sinks/stdout_color_sinks.h" -#endif // SPDLOG_DISABLE_GLOBAL_LOGGER - #include namespace spdlog { diff --git a/src/sinks/ansicolor_sink.cpp b/src/sinks/ansicolor_sink.cpp index 5de60b48..c4d02b64 100644 --- a/src/sinks/ansicolor_sink.cpp +++ b/src/sinks/ansicolor_sink.cpp @@ -5,7 +5,6 @@ #include -#include "spdlog/details/null_mutex.h" #include "spdlog/details/os.h" #include "spdlog/pattern_formatter.h" @@ -111,11 +110,12 @@ ansicolor_stderr_sink::ansicolor_stderr_sink(color_mode mode) : ansicolor_sink(stderr, mode) {} -// template instantiations -template class SPDLOG_API ansicolor_stdout_sink; -template class SPDLOG_API ansicolor_stdout_sink; -template class SPDLOG_API ansicolor_stderr_sink; -template class SPDLOG_API ansicolor_stderr_sink; - } // namespace sinks } // namespace spdlog + +// template instantiations +#include "spdlog/details/null_mutex.h" +template class SPDLOG_API spdlog::sinks::ansicolor_stdout_sink; +template class SPDLOG_API spdlog::sinks::ansicolor_stdout_sink; +template class SPDLOG_API spdlog::sinks::ansicolor_stderr_sink; +template class SPDLOG_API spdlog::sinks::ansicolor_stderr_sink; diff --git a/src/sinks/base_sink.cpp b/src/sinks/base_sink.cpp index ab01cdc6..3ac28a46 100644 --- a/src/sinks/base_sink.cpp +++ b/src/sinks/base_sink.cpp @@ -4,6 +4,7 @@ #include "spdlog/sinks/base_sink.h" #include +#include #include "spdlog/common.h" #include "spdlog/pattern_formatter.h" @@ -55,9 +56,7 @@ void base_sink::set_formatter_(std::unique_ptr sink_formatter) } // namespace sinks } // namespace spdlog - // template instantiations -#include #include "spdlog/details/null_mutex.h" template class SPDLOG_API spdlog::sinks::base_sink; template class SPDLOG_API spdlog::sinks::base_sink; diff --git a/src/sinks/basic_file_sink.cpp b/src/sinks/basic_file_sink.cpp index c120592c..a48d3a90 100644 --- a/src/sinks/basic_file_sink.cpp +++ b/src/sinks/basic_file_sink.cpp @@ -3,6 +3,7 @@ #include "spdlog/sinks/basic_file_sink.h" #include "spdlog/common.h" +#include namespace spdlog { namespace sinks { @@ -35,7 +36,6 @@ void basic_file_sink::flush_() { // template instantiations -#include #include "spdlog/details/null_mutex.h" template class SPDLOG_API spdlog::sinks::basic_file_sink; template class SPDLOG_API spdlog::sinks::basic_file_sink; \ No newline at end of file diff --git a/src/sinks/rotating_file_sink.cpp b/src/sinks/rotating_file_sink.cpp index 490fbcc2..b58115bd 100644 --- a/src/sinks/rotating_file_sink.cpp +++ b/src/sinks/rotating_file_sink.cpp @@ -139,9 +139,7 @@ bool rotating_file_sink::rename_file_(const filename_t &src_filename, con } // namespace sinks } // namespace spdlog - // template instantiations -#include #include "spdlog/details/null_mutex.h" template class SPDLOG_API spdlog::sinks::rotating_file_sink; template class SPDLOG_API spdlog::sinks::rotating_file_sink; \ No newline at end of file diff --git a/src/sinks/stdout_sinks.cpp b/src/sinks/stdout_sinks.cpp index efee54cf..450edb58 100644 --- a/src/sinks/stdout_sinks.cpp +++ b/src/sinks/stdout_sinks.cpp @@ -4,6 +4,8 @@ #include "spdlog/sinks/stdout_sinks.h" #include +#include + #include "spdlog/details/os.h" #include "spdlog/pattern_formatter.h" @@ -83,9 +85,7 @@ stderr_sink::stderr_sink() } // namespace sinks } // namespace spdlog - // template instantiations -#include #include "spdlog/details/null_mutex.h" template class SPDLOG_API spdlog::sinks::stdout_sink; template class SPDLOG_API spdlog::sinks::stdout_sink; diff --git a/src/sinks/wincolor_sink.cpp b/src/sinks/wincolor_sink.cpp index d71aec1c..5fa8542e 100644 --- a/src/sinks/wincolor_sink.cpp +++ b/src/sinks/wincolor_sink.cpp @@ -4,6 +4,7 @@ // clang-format off #include "spdlog/details/windows_include.h" #include +#include // clang-format on #include "spdlog/sinks/wincolor_sink.h" @@ -134,9 +135,7 @@ wincolor_stderr_sink::wincolor_stderr_sink(color_mode mode) } // namespace sinks } // namespace spdlog - // template instantiations -#include #include "spdlog/details/null_mutex.h" template class SPDLOG_API spdlog::sinks::wincolor_stdout_sink; template class SPDLOG_API spdlog::sinks::wincolor_stdout_sink;