diff --git a/include/spdlog/common.h b/include/spdlog/common.h index f843e97f..946a044c 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -5,17 +5,20 @@ #pragma once + #include #include #include #include +#include #include - #if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES) #include #include #endif +#include + //visual studio does not support noexcept yet #ifndef _MSC_VER #define SPDLOG_NOEXCEPT noexcept @@ -23,7 +26,6 @@ #define SPDLOG_NOEXCEPT throw() #endif - namespace spdlog { @@ -39,7 +41,11 @@ using log_clock = std::chrono::system_clock; using sink_ptr = std::shared_ptr < sinks::sink >; using sinks_init_list = std::initializer_list < sink_ptr >; using formatter_ptr = std::shared_ptr; - +#if defined(SPDLOG_NO_ATOMIC_LEVELS) +using atomic_level = details::null_atomic_int; +#else +using atomic_level = std::atomic_int; +#endif //Log level enum namespace level diff --git a/include/spdlog/details/logger_impl.h b/include/spdlog/details/logger_impl.h index e3c6611c..7733e9ae 100644 --- a/include/spdlog/details/logger_impl.h +++ b/include/spdlog/details/logger_impl.h @@ -7,7 +7,6 @@ #include -#include #include #include diff --git a/include/spdlog/details/null_mutex.h b/include/spdlog/details/null_mutex.h index 19e90bfc..6d2d9a3d 100644 --- a/include/spdlog/details/null_mutex.h +++ b/include/spdlog/details/null_mutex.h @@ -5,7 +5,8 @@ #pragma once -// null, no cost mutex +#include +// null, no cost dummy "mutex" and dummy "atomic" int namespace spdlog { @@ -20,5 +21,25 @@ struct null_mutex return true; } }; + +struct null_atomic_int +{ + int value; + null_atomic_int() = default; + + null_atomic_int(int val):value(val) + {} + + int load(std::memory_order) const + { + return value; + } + + void store(int val) + { + value = val; + } +}; + } } diff --git a/include/spdlog/logger.h b/include/spdlog/logger.h index e90090f0..b86b29b2 100644 --- a/include/spdlog/logger.h +++ b/include/spdlog/logger.h @@ -18,7 +18,6 @@ #include #include -#include #include namespace spdlog @@ -103,9 +102,8 @@ protected: friend details::line_logger; std::string _name; std::vector _sinks; - formatter_ptr _formatter; - std::atomic_int _level; - + formatter_ptr _formatter; + spdlog::atomic_level _level; }; } diff --git a/include/spdlog/tweakme.h b/include/spdlog/tweakme.h index cfd8a54f..84b054b4 100644 --- a/include/spdlog/tweakme.h +++ b/include/spdlog/tweakme.h @@ -53,6 +53,12 @@ /////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// +// Uncomment to avoid spdlog's usage of atomic log levels +// Use only if your code never modifies a logger's log levels concurrently. +// #define SPDLOG_NO_ATOMIC_LEVELS +/////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////// // Uncomment to enable usage of wchar_t for file names on Windows. // #define SPDLOG_WCHAR_FILENAMES diff --git a/tests/logs/.gitignore b/tests/logs/.gitignore deleted file mode 100644 index 2211df63..00000000 --- a/tests/logs/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.txt