mirror of
https://github.com/gabime/spdlog.git
synced 2024-12-26 02:21:34 +08:00
Fix atomic level
This commit is contained in:
parent
3a405ba958
commit
31a7dc6e1e
@ -173,9 +173,9 @@ enum class log_level
|
|||||||
};
|
};
|
||||||
|
|
||||||
#if defined(SPDLOG_NO_ATOMIC_LEVELS)
|
#if defined(SPDLOG_NO_ATOMIC_LEVELS)
|
||||||
using level_t = details::null_atomic_log_level;
|
using atomic_level_t = details::null_atomic<log_level>;
|
||||||
#else
|
#else
|
||||||
using level_t = std::atomic<log_level>;
|
using atomic_level_t = std::atomic<log_level>;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(SPDLOG_LEVEL_NAMES)
|
#if !defined(SPDLOG_LEVEL_NAMES)
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
// null, no cost dummy "mutex" and dummy "atomic" log level
|
// null, no cost dummy "mutex" and dummy "atomic" log level
|
||||||
|
|
||||||
namespace spdlog {
|
namespace spdlog {
|
||||||
enum class log_level; // forward declaration
|
|
||||||
|
|
||||||
namespace details {
|
namespace details {
|
||||||
struct null_mutex
|
struct null_mutex
|
||||||
@ -18,25 +17,26 @@ struct null_mutex
|
|||||||
void unlock() const {}
|
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)
|
: 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;
|
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;
|
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);
|
std::swap(new_value, value);
|
||||||
return new_value; // return value before the call
|
return new_value; // return value before the call
|
||||||
|
@ -310,8 +310,8 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
std::string name_;
|
std::string name_;
|
||||||
std::vector<sink_ptr> sinks_;
|
std::vector<sink_ptr> sinks_;
|
||||||
spdlog::level_t level_{log_level::info};
|
spdlog::atomic_level_t level_{log_level::info};
|
||||||
spdlog::level_t flush_level_{log_level::off};
|
spdlog::atomic_level_t flush_level_{log_level::off};
|
||||||
err_handler custom_err_handler_{nullptr};
|
err_handler custom_err_handler_{nullptr};
|
||||||
|
|
||||||
// common implementation for after templated public api has been resolved to format string and args
|
// common implementation for after templated public api has been resolved to format string and args
|
||||||
|
@ -24,7 +24,7 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
// sink log level - default is all
|
// sink log level - default is all
|
||||||
level_t level_{log_level::trace};
|
atomic_level_t level_{log_level::trace};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sinks
|
} // namespace sinks
|
||||||
|
Loading…
Reference in New Issue
Block a user