# HG changeset patch # User Sebastien Jodogne # Date 1782477182 -7200 # Node ID 714b20840e91aeb0f5fedc0756d820c680b8aaf6 # Parent ba68acff977a4604993c9e0331d02cb4c7be648c improved concurrency by making loggingListenersMutex_ a readers-writer lock diff -r ba68acff977a -r 714b20840e91 OrthancFramework/Sources/Logging.cpp --- a/OrthancFramework/Sources/Logging.cpp Tue Jun 23 13:09:46 2026 +0200 +++ b/OrthancFramework/Sources/Logging.cpp Fri Jun 26 14:33:02 2026 +0200 @@ -537,10 +537,10 @@ #include "SystemToolbox.h" #include "Toolbox.h" -#include +#include #include #include -#include +#include namespace @@ -632,7 +632,7 @@ static std::map threadNames_; static bool enableThreadNames_ = true; static std::list loggingListeners_; -static boost::mutex loggingListenersMutex_; +static boost::shared_mutex loggingListenersMutex_; namespace Orthanc @@ -784,13 +784,13 @@ void AddLoggingListener(ILoggingListener* listener) { - boost::mutex::scoped_lock lock(loggingListenersMutex_); + boost::unique_lock lock(loggingListenersMutex_); loggingListeners_.push_back(listener); } void ClearLoggingListeners() { - boost::mutex::scoped_lock lock(loggingListenersMutex_); + boost::unique_lock lock(loggingListenersMutex_); loggingListeners_.clear(); } @@ -1134,10 +1134,20 @@ *stream_ << messageStream_.str() << "\n"; stream_->flush(); - boost::mutex::scoped_lock lock(loggingListenersMutex_); - for (std::list::iterator it = loggingListeners_.begin(); it != loggingListeners_.end(); ++it) { - (*it)->HandleLog(level_, category_, pluginName_, file_, line_, messageStream_.str()); + boost::shared_lock lock(loggingListenersMutex_); + + for (std::list::iterator it = loggingListeners_.begin(); it != loggingListeners_.end(); ++it) + { + try + { + (*it)->HandleLog(level_, category_, pluginName_, file_, line_, messageStream_.str()); + } + catch (...) + { + // Don't throw in destructors + } + } } } @@ -1168,4 +1178,4 @@ } #endif // ORTHANC_ENABLE_LOGGING -// NOLINTEND(bugprone-reserved-identifier) \ No newline at end of file +// NOLINTEND(bugprone-reserved-identifier)