Skip to content

Commit cdb7725

Browse files
committed
Thread safety: loadErrorDefinitions
1 parent e0c978f commit cdb7725

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/error_detector.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
#include <sstream>
66
#include <dirent.h>
77
#include <cstring>
8+
#include <mutex>
89

910
// Static member initialization
1011
std::vector<ErrorDefinition> ErrorDetector::errorDefinitions;
1112
bool ErrorDetector::definitionsLoaded = false;
13+
static std::once_flag initFlag;
1214

1315
namespace {
1416
// Case-insensitive string comparison
@@ -121,9 +123,9 @@ void ErrorDetector::loadErrorDefinitions(const std::string& configDir) {
121123
}
122124

123125
void ErrorDetector::ensureLoaded() {
124-
if (!definitionsLoaded) {
126+
std::call_once(initFlag, []() {
125127
loadErrorDefinitions();
126-
}
128+
});
127129
}
128130

129131
bool ErrorDetector::isErrorReading(const std::map<std::string, std::string>& reading) {

0 commit comments

Comments
 (0)