Synchronize DefaultLogger (#5898)

Co-authored-by: Kim Kulling <kimkulling@users.noreply.github.com>
This commit is contained in:
Stefan
2024-12-01 20:35:24 +01:00
committed by GitHub
co-authored by Kim Kulling
parent 72c51a9997
commit 739ebfd207
2 changed files with 22 additions and 1 deletions
+13 -1
View File
@@ -318,9 +318,13 @@ bool DefaultLogger::attachStream(LogStream *pStream, unsigned int severity) {
}
if (0 == severity) {
severity = Logger::Info | Logger::Err | Logger::Warn | Logger::Debugging;
severity = SeverityAll;
}
#ifndef ASSIMP_BUILD_SINGLETHREADED
std::lock_guard<std::mutex> lock(m_arrayMutex);
#endif
for (StreamIt it = m_StreamArray.begin();
it != m_StreamArray.end();
++it) {
@@ -346,6 +350,10 @@ bool DefaultLogger::detachStream(LogStream *pStream, unsigned int severity) {
severity = SeverityAll;
}
#ifndef ASSIMP_BUILD_SINGLETHREADED
std::lock_guard<std::mutex> lock(m_arrayMutex);
#endif
bool res(false);
for (StreamIt it = m_StreamArray.begin(); it != m_StreamArray.end(); ++it) {
if ((*it)->m_pStream == pStream) {
@@ -385,6 +393,10 @@ DefaultLogger::~DefaultLogger() {
void DefaultLogger::WriteToStreams(const char *message, ErrorSeverity ErrorSev) {
ai_assert(nullptr != message);
#ifndef ASSIMP_BUILD_SINGLETHREADED
std::lock_guard<std::mutex> lock(m_arrayMutex);
#endif
// Check whether this is a repeated message
auto thisLen = ::strlen(message);
if (thisLen == lastLen - 1 && !::strncmp(message, lastMsg, lastLen - 1)) {