Fix atomic level

This commit is contained in:
gabime 2023-09-23 00:42:36 +03:00
parent 3a405ba958
commit 31a7dc6e1e
4 changed files with 12 additions and 12 deletions

View File

@ -173,9 +173,9 @@ enum class log_level
};
#if defined(SPDLOG_NO_ATOMIC_LEVELS)
using level_t = details::null_atomic_log_level;
using atomic_level_t = details::null_atomic<log_level>;
#else
using level_t = std::atomic<log_level>;
using atomic_level_t = std::atomic<log_level>;
#endif
#if !defined(SPDLOG_LEVEL_NAMES)

View File

@ -9,7 +9,6 @@
// null, no cost dummy "mutex" and dummy "atomic" log level
namespace spdlog {
enum class log_level; // forward declaration
namespace details {
struct null_mutex
@ -18,25 +17,26 @@ struct null_mutex
void unlock() const {}
};
struct null_atomic_log_level
template<typename T>
struct null_atomic
{
spdlog::log_level value;
T value;
explicit null_atomic_log_level(spdlog::log_level new_value)
explicit null_atomic(T new_value)
: value(new_value)
{}
[[nodiscard]] log_level load(std::memory_order = std::memory_order_relaxed) const
[[nodiscard]] T load(std::memory_order = std::memory_order_relaxed) const
{
return value;
}
void store(log_level new_value, std::memory_order = std::memory_order_relaxed)
void store(T new_value, std::memory_order = std::memory_order_relaxed)
{
value = new_value;
}
log_level exchange(log_level new_value, std::memory_order = std::memory_order_relaxed)
T exchange(T new_value, std::memory_order = std::memory_order_relaxed)
{
std::swap(new_value, value);
return new_value; // return value before the call

View File

@ -310,8 +310,8 @@ public:
protected:
std::string name_;
std::vector<sink_ptr> sinks_;
spdlog::level_t level_{log_level::info};
spdlog::level_t flush_level_{log_level::off};
spdlog::atomic_level_t level_{log_level::info};
spdlog::atomic_level_t flush_level_{log_level::off};
err_handler custom_err_handler_{nullptr};
// common implementation for after templated public api has been resolved to format string and args

View File

@ -24,7 +24,7 @@ public:
protected:
// sink log level - default is all
level_t level_{log_level::trace};
atomic_level_t level_{log_level::trace};
};
} // namespace sinks