Skip to content

Commit

Permalink
Put logger mutex behind a preprocessor flag
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nathanwbrei committed Jan 2, 2025
1 parent e583654 commit 760610e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/libraries/JANA/JLogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
#include <time.h>
#include <mutex>

#ifndef JANA2_USE_LOGGER_MUTEX
#define JANA2_USE_LOGGER_MUTEX 0
#endif


struct JLogger {
enum class Level { TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF };
Expand Down Expand Up @@ -107,9 +111,10 @@ class JLogMessage : public std::stringstream {
}

virtual ~JLogMessage() {
#if JANA2_USE_LOGGER_MUTEX
static std::mutex cout_mutex;
std::lock_guard<std::mutex> lock(cout_mutex);

#endif
std::string line;
std::ostringstream oss;
while (std::getline(*this, line)) {
Expand Down

0 comments on commit 760610e

Please sign in to comment.