Skip to content

Commit

Permalink
Make s_logMaxFileSizeReached atomic
Browse files Browse the repository at this point in the history
  • Loading branch information
daschuer committed Dec 2, 2024
1 parent 7bcba98 commit 89e955b
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/util/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <QString>
#include <QTextStream>
#include <QThread>
#include <atomic>
#include <string_view>

#include "util/assert.h"
Expand All @@ -29,7 +30,7 @@ QMutex s_mutexStdErr;
// The file handle for Mixxx's log file.
QFile s_logfile;
qint64 s_logMaxFileSize = mixxx::kLogMaxFileSizeDefault;
bool s_logMaxFileSizeReached = false;
std::atomic<bool> s_logMaxFileSizeReached = false;

QLoggingCategory::CategoryFilter oldCategoryFilter = nullptr;

Expand Down Expand Up @@ -151,7 +152,7 @@ inline void writeToFile(
const QString& message,
const QString& threadName,
bool flush) {
if (s_logMaxFileSizeReached) {
if (s_logMaxFileSizeReached.load(std::memory_order_relaxed)) {
return;
}

Expand All @@ -168,7 +169,7 @@ inline void writeToFile(
formattedMessage =
"Maximum log file size reached. It can be adjusted via: "
"--log-max-file-size <bytes>";
s_logMaxFileSizeReached = true;
s_logMaxFileSizeReached.store(true, std::memory_order_relaxed);
flush = true;
}
const int written = s_logfile.write(formattedMessage);
Expand Down

0 comments on commit 89e955b

Please sign in to comment.