From dc4be3e0939042abb1403bda9cd11a0e26f3e298 Mon Sep 17 00:00:00 2001 From: Vaclav Haisman Date: Mon, 16 Sep 2024 20:17:13 +0200 Subject: [PATCH 1/2] Use TSA annotations for BaseEventCounter. --- include/log4cplus/helpers/eventcounter.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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); }; From 3b218eac09ac67c69e3413a98e4e3e28192dee58 Mon Sep 17 00:00:00 2001 From: Vaclav Haisman Date: Tue, 17 Sep 2024 22:28:24 +0200 Subject: [PATCH 2/2] Implements `LOG4CPLUS_ASSERT_FMT()` and `LOG4CPLUS_ASSERT_FORMAT()`. This implements #617. --- include/log4cplus/loggingmacros.h | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) 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_ */