Mercurial > hg > orthanc
changeset 6961:714b20840e91
improved concurrency by making loggingListenersMutex_ a readers-writer lock
| author | Sebastien Jodogne <s.jodogne@gmail.com> |
|---|---|
| date | Fri, 26 Jun 2026 14:33:02 +0200 |
| parents | ba68acff977a |
| children | 3948b93ed918 |
| files | OrthancFramework/Sources/Logging.cpp |
| diffstat | 1 files changed, 19 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- 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 <fstream> +#include <boost/date_time/posix_time/posix_time.hpp> #include <boost/filesystem.hpp> #include <boost/thread.hpp> -#include <boost/date_time/posix_time/posix_time.hpp> +#include <fstream> namespace @@ -632,7 +632,7 @@ static std::map<boost::thread::id, std::string> threadNames_; static bool enableThreadNames_ = true; static std::list<Orthanc::Logging::ILoggingListener*> 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<boost::shared_mutex> lock(loggingListenersMutex_); loggingListeners_.push_back(listener); } void ClearLoggingListeners() { - boost::mutex::scoped_lock lock(loggingListenersMutex_); + boost::unique_lock<boost::shared_mutex> lock(loggingListenersMutex_); loggingListeners_.clear(); } @@ -1134,10 +1134,20 @@ *stream_ << messageStream_.str() << "\n"; stream_->flush(); - boost::mutex::scoped_lock lock(loggingListenersMutex_); - for (std::list<Orthanc::Logging::ILoggingListener*>::iterator it = loggingListeners_.begin(); it != loggingListeners_.end(); ++it) { - (*it)->HandleLog(level_, category_, pluginName_, file_, line_, messageStream_.str()); + boost::shared_lock<boost::shared_mutex> lock(loggingListenersMutex_); + + for (std::list<Orthanc::Logging::ILoggingListener*>::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)
