# HG changeset patch # User Alain Mazy # Date 1776779922 -7200 # Node ID 8d5af1f1c971209a1f415dcac4b7a92193b45607 # Parent b51f2d806a47805a6bb989472b376088d52b197f use ScopedThreadNameSetter diff -r b51f2d806a47 -r 8d5af1f1c971 CMakeLists.txt --- a/CMakeLists.txt Wed Apr 15 11:15:58 2026 +0200 +++ b/CMakeLists.txt Tue Apr 21 15:58:42 2026 +0200 @@ -31,6 +31,7 @@ else() # Do NOT use framework 1.12.11 here, which is buggy because of: # https://orthanc.uclouvain.be/hg/orthanc/rev/3bd8715e21bc + # Note: we need the Orthanc::Logging::ScopedThreadNameSetter (not packaged yet) set(ORTHANC_FRAMEWORK_DEFAULT_VERSION "1.12.10") set(ORTHANC_FRAMEWORK_DEFAULT_SOURCE "web") endif() diff -r b51f2d806a47 -r 8d5af1f1c971 Plugin/WadoRs.cpp --- a/Plugin/WadoRs.cpp Wed Apr 15 11:15:58 2026 +0200 +++ b/Plugin/WadoRs.cpp Tue Apr 21 15:58:42 2026 +0200 @@ -61,6 +61,17 @@ static boost::mutex preloaderThreadsCounterMutex; static uint32_t preloaderThreadsCounter = 0; + +static std::string GetWadoLoaderThreadName() +{ + boost::mutex::scoped_lock lock(preloaderThreadsCounterMutex); + std::string threadName = std::string("WADO-LOAD-") + boost::lexical_cast(preloaderThreadsCounter++); + preloaderThreadsCounter %= 1000000; + + return threadName; +} + + static WeightedAverageMetrics wadorsAverageBandwidth(300); static boost::mutex wadoRsTotalBytesTransferredMutex; @@ -530,11 +541,7 @@ static void PreloaderWorkerThread(ThreadedInstanceLoader* that) { - { - boost::mutex::scoped_lock lock(preloaderThreadsCounterMutex); - Orthanc::Logging::SetCurrentThreadName(std::string("WADO-LOAD-") + boost::lexical_cast(preloaderThreadsCounter++)); - preloaderThreadsCounter %= 1000000; - } + Orthanc::Logging::ScopedThreadNameSetter setter(GetWadoLoaderThreadName()); LOG(INFO) << "Loader thread has started"; @@ -1706,14 +1713,17 @@ class InstanceWorkerData : public boost::noncopyable { private: - Orthanc::SharedMessageQueue* instancesQueue_; - std::string wadoBase_; + Orthanc::SharedMessageQueue* instancesQueue_; + std::string wadoBase_; + unsigned int threadId_; public: InstanceWorkerData(Orthanc::SharedMessageQueue* instancesQueue, - const std::string& wadoBase) : + const std::string& wadoBase, + unsigned int threadId) : instancesQueue_(instancesQueue), - wadoBase_(wadoBase) + wadoBase_(wadoBase), + threadId_(threadId) { if (instancesQueue == NULL) { @@ -1730,12 +1740,16 @@ { return wadoBase_; } + + unsigned int GetThreadId() const + { + return threadId_; + } }; void InstanceWorkerThread(InstanceWorkerData* data) { - static uint16_t threadCounter = 0; - Orthanc::Logging::SetCurrentThreadName(std::string("DW-META-") + boost::lexical_cast(threadCounter++)); + Orthanc::Logging::ScopedThreadNameSetter setter(std::string("DW-META-") + boost::lexical_cast(data->GetThreadId())); while (true) { @@ -1825,7 +1839,7 @@ for (unsigned int t = 0; t < workersCount; t++) { - InstanceWorkerData* threadData = new InstanceWorkerData(&instancesQueue, wadoBase); + InstanceWorkerData* threadData = new InstanceWorkerData(&instancesQueue, wadoBase, t); instancesWorkersData.push_back(boost::shared_ptr(threadData)); instancesWorkers.push_back(boost::shared_ptr(new boost::thread(InstanceWorkerThread, threadData))); }