Fix compile

This commit is contained in:
Gabi Melman 2024-12-07 11:00:31 +02:00
parent 4b787b3044
commit 31f6b371cb
9 changed files with 12 additions and 79 deletions

View File

@ -13,7 +13,6 @@
#include <string> #include <string>
#include "../common.h" #include "../common.h"
#include "./periodic_worker.h"
namespace spdlog { namespace spdlog {
class logger; class logger;

View File

@ -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 <chrono>
#include <condition_variable>
#include <functional>
#include <mutex>
#include <thread>
#include "../common.h"
namespace spdlog {
namespace details {
class SPDLOG_API periodic_worker {
public:
template <typename Rep, typename Period>
periodic_worker(const std::function<void()> &callback_fun, std::chrono::duration<Rep, Period> interval) {
active_ = (interval > std::chrono::duration<Rep, Period>::zero());
if (!active_) {
return;
}
worker_thread_ = std::thread([this, callback_fun, interval]() {
for (;;) {
std::unique_lock<std::mutex> 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

View File

@ -2,13 +2,8 @@
// Distributed under the MIT License (http://opensource.org/licenses/MIT) // Distributed under the MIT License (http://opensource.org/licenses/MIT)
#include "spdlog/details/context.h" #include "spdlog/details/context.h"
#include "spdlog/logger.h" #include "spdlog/logger.h"
#ifndef SPDLOG_DISABLE_GLOBAL_LOGGER
#include "spdlog/sinks/stdout_color_sinks.h"
#endif // SPDLOG_DISABLE_GLOBAL_LOGGER
#include <memory> #include <memory>
namespace spdlog { namespace spdlog {

View File

@ -5,7 +5,6 @@
#include <mutex> #include <mutex>
#include "spdlog/details/null_mutex.h"
#include "spdlog/details/os.h" #include "spdlog/details/os.h"
#include "spdlog/pattern_formatter.h" #include "spdlog/pattern_formatter.h"
@ -111,11 +110,12 @@ ansicolor_stderr_sink<Mutex>::ansicolor_stderr_sink(color_mode mode)
: ansicolor_sink<Mutex>(stderr, mode) {} : ansicolor_sink<Mutex>(stderr, mode) {}
// template instantiations
template class SPDLOG_API ansicolor_stdout_sink<std::mutex>;
template class SPDLOG_API ansicolor_stdout_sink<details::null_mutex>;
template class SPDLOG_API ansicolor_stderr_sink<std::mutex>;
template class SPDLOG_API ansicolor_stderr_sink<details::null_mutex>;
} // namespace sinks } // namespace sinks
} // namespace spdlog } // namespace spdlog
// template instantiations
#include "spdlog/details/null_mutex.h"
template class SPDLOG_API spdlog::sinks::ansicolor_stdout_sink<std::mutex>;
template class SPDLOG_API spdlog::sinks::ansicolor_stdout_sink<spdlog::details::null_mutex>;
template class SPDLOG_API spdlog::sinks::ansicolor_stderr_sink<std::mutex>;
template class SPDLOG_API spdlog::sinks::ansicolor_stderr_sink<spdlog::details::null_mutex>;

View File

@ -4,6 +4,7 @@
#include "spdlog/sinks/base_sink.h" #include "spdlog/sinks/base_sink.h"
#include <memory> #include <memory>
#include <mutex>
#include "spdlog/common.h" #include "spdlog/common.h"
#include "spdlog/pattern_formatter.h" #include "spdlog/pattern_formatter.h"
@ -55,9 +56,7 @@ void base_sink<Mutex>::set_formatter_(std::unique_ptr<formatter> sink_formatter)
} // namespace sinks } // namespace sinks
} // namespace spdlog } // namespace spdlog
// template instantiations // template instantiations
#include <mutex>
#include "spdlog/details/null_mutex.h" #include "spdlog/details/null_mutex.h"
template class SPDLOG_API spdlog::sinks::base_sink<std::mutex>; template class SPDLOG_API spdlog::sinks::base_sink<std::mutex>;
template class SPDLOG_API spdlog::sinks::base_sink<spdlog::details::null_mutex>; template class SPDLOG_API spdlog::sinks::base_sink<spdlog::details::null_mutex>;

View File

@ -3,6 +3,7 @@
#include "spdlog/sinks/basic_file_sink.h" #include "spdlog/sinks/basic_file_sink.h"
#include "spdlog/common.h" #include "spdlog/common.h"
#include <mutex>
namespace spdlog { namespace spdlog {
namespace sinks { namespace sinks {
@ -35,7 +36,6 @@ void basic_file_sink<Mutex>::flush_() {
// template instantiations // template instantiations
#include <mutex>
#include "spdlog/details/null_mutex.h" #include "spdlog/details/null_mutex.h"
template class SPDLOG_API spdlog::sinks::basic_file_sink<std::mutex>; template class SPDLOG_API spdlog::sinks::basic_file_sink<std::mutex>;
template class SPDLOG_API spdlog::sinks::basic_file_sink<spdlog::details::null_mutex>; template class SPDLOG_API spdlog::sinks::basic_file_sink<spdlog::details::null_mutex>;

View File

@ -139,9 +139,7 @@ bool rotating_file_sink<Mutex>::rename_file_(const filename_t &src_filename, con
} // namespace sinks } // namespace sinks
} // namespace spdlog } // namespace spdlog
// template instantiations // template instantiations
#include <mutex>
#include "spdlog/details/null_mutex.h" #include "spdlog/details/null_mutex.h"
template class SPDLOG_API spdlog::sinks::rotating_file_sink<std::mutex>; template class SPDLOG_API spdlog::sinks::rotating_file_sink<std::mutex>;
template class SPDLOG_API spdlog::sinks::rotating_file_sink<spdlog::details::null_mutex>; template class SPDLOG_API spdlog::sinks::rotating_file_sink<spdlog::details::null_mutex>;

View File

@ -4,6 +4,8 @@
#include "spdlog/sinks/stdout_sinks.h" #include "spdlog/sinks/stdout_sinks.h"
#include <memory> #include <memory>
#include <mutex>
#include "spdlog/details/os.h" #include "spdlog/details/os.h"
#include "spdlog/pattern_formatter.h" #include "spdlog/pattern_formatter.h"
@ -83,9 +85,7 @@ stderr_sink<Mutex>::stderr_sink()
} // namespace sinks } // namespace sinks
} // namespace spdlog } // namespace spdlog
// template instantiations // template instantiations
#include <mutex>
#include "spdlog/details/null_mutex.h" #include "spdlog/details/null_mutex.h"
template class SPDLOG_API spdlog::sinks::stdout_sink<std::mutex>; template class SPDLOG_API spdlog::sinks::stdout_sink<std::mutex>;
template class SPDLOG_API spdlog::sinks::stdout_sink<spdlog::details::null_mutex>; template class SPDLOG_API spdlog::sinks::stdout_sink<spdlog::details::null_mutex>;

View File

@ -4,6 +4,7 @@
// clang-format off // clang-format off
#include "spdlog/details/windows_include.h" #include "spdlog/details/windows_include.h"
#include <wincon.h> #include <wincon.h>
#include <mutex>
// clang-format on // clang-format on
#include "spdlog/sinks/wincolor_sink.h" #include "spdlog/sinks/wincolor_sink.h"
@ -134,9 +135,7 @@ wincolor_stderr_sink<Mutex>::wincolor_stderr_sink(color_mode mode)
} // namespace sinks } // namespace sinks
} // namespace spdlog } // namespace spdlog
// template instantiations // template instantiations
#include <mutex>
#include "spdlog/details/null_mutex.h" #include "spdlog/details/null_mutex.h"
template class SPDLOG_API spdlog::sinks::wincolor_stdout_sink<std::mutex>; template class SPDLOG_API spdlog::sinks::wincolor_stdout_sink<std::mutex>;
template class SPDLOG_API spdlog::sinks::wincolor_stdout_sink<spdlog::details::null_mutex>; template class SPDLOG_API spdlog::sinks::wincolor_stdout_sink<spdlog::details::null_mutex>;