From 760610ea44cce14ad7d2808d748f4d03215046c7 Mon Sep 17 00:00:00 2001 From: Nathan Brei Date: Thu, 2 Jan 2025 17:11:07 -0500 Subject: [PATCH] Put logger mutex behind a preprocessor flag The logger mutex is not necessary on the platforms we support. Omitting it causes lots and lots of false positives when running tools like Helgrind. However, including it causes some extremely weird behavior when Helgrind runs, such as segfaults and hanging. I speculate that this behavior is due to the ODR violation that happens with the static logger mutex when JANA is linked incorrectly --- src/libraries/JANA/JLogger.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/libraries/JANA/JLogger.h b/src/libraries/JANA/JLogger.h index 1047af88f..6b49adaf8 100644 --- a/src/libraries/JANA/JLogger.h +++ b/src/libraries/JANA/JLogger.h @@ -14,6 +14,10 @@ #include #include +#ifndef JANA2_USE_LOGGER_MUTEX +#define JANA2_USE_LOGGER_MUTEX 0 +#endif + struct JLogger { enum class Level { TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF }; @@ -107,9 +111,10 @@ class JLogMessage : public std::stringstream { } virtual ~JLogMessage() { +#if JANA2_USE_LOGGER_MUTEX static std::mutex cout_mutex; std::lock_guard lock(cout_mutex); - +#endif std::string line; std::ostringstream oss; while (std::getline(*this, line)) {