diff --git a/include/log4cplus/helpers/eventcounter.h b/include/log4cplus/helpers/eventcounter.h index be9f192fb..f305de26d 100644 --- a/include/log4cplus/helpers/eventcounter.h +++ b/include/log4cplus/helpers/eventcounter.h @@ -32,6 +32,7 @@ #pragma once #endif +#include #include #include #include @@ -78,9 +79,9 @@ class LOG4CPLUS_EXPORT SteadyClockGate private: log4cplus::thread::SimpleMutex mtx; - Duration const pause_duration; - TimePoint timeout_point; - TimePoint prev_timeout_point; + Duration const pause_duration LOG4CPLUS_TSA_GUARDED_BY (mtx); + TimePoint timeout_point LOG4CPLUS_TSA_GUARDED_BY (mtx); + TimePoint prev_timeout_point LOG4CPLUS_TSA_GUARDED_BY (mtx); }; diff --git a/include/log4cplus/loggingmacros.h b/include/log4cplus/loggingmacros.h index b5826ea70..dc2131d58 100644 --- a/include/log4cplus/loggingmacros.h +++ b/include/log4cplus/loggingmacros.h @@ -530,9 +530,8 @@ LOG4CPLUS_EXPORT void macro_forced_log (log4cplus::Logger const &, //! Helper macro for LOG4CPLUS_ASSERT() macro. #define LOG4CPLUS_ASSERT_STRINGIFY(X) #X -//! If the condition given in second parameter evaluates false, this -//! macro logs it using FATAL log level, including the condition's -//! source text. +//! If the `condition` evaluates false, this macro logs it using FATAL +//! log level, including the `condition`'s source text. #define LOG4CPLUS_ASSERT(logger, condition) \ LOG4CPLUS_SUPPRESS_DOWHILE_WARNING() \ do { \ @@ -544,5 +543,28 @@ LOG4CPLUS_EXPORT void macro_forced_log (log4cplus::Logger const &, } while (false) \ LOG4CPLUS_RESTORE_DOWHILE_WARNING() +//! If the `condition` evaluates false, this macro logs a message +//! formatted from `printf` format string passed in 3rd and remaining +//! arguments. +#define LOG4CPLUS_ASSERT_FMT(logger, condition, ...) \ + LOG4CPLUS_SUPPRESS_DOWHILE_WARNING() \ + do { \ + if (! (condition)) [[unlikely]] { \ + LOG4CPLUS_FATAL_FMT ((logger), __VA_ARGS__); \ + } \ + } while (false) \ + LOG4CPLUS_RESTORE_DOWHILE_WARNING() + +//! If the `condition` evaluates false, this macro logs a message +//! formatted from `std::format` format string passed in 3rd and remaining +//! arguments. +#define LOG4CPLUS_ASSERT_FORMAT(logger, condition, ...) \ + LOG4CPLUS_SUPPRESS_DOWHILE_WARNING() \ + do { \ + if (! (condition)) [[unlikely]] { \ + LOG4CPLUS_FATAL_FORMAT ((logger), __VA_ARGS__); \ + } \ + } while (false) \ + LOG4CPLUS_RESTORE_DOWHILE_WARNING() #endif /* LOG4CPLUS_LOGGING_MACROS_HEADER_ */