Mercurial > hg > orthanc-dicomweb
changeset 760:8d5af1f1c971
use ScopedThreadNameSetter
| author | Alain Mazy <am@orthanc.team> |
|---|---|
| date | Tue, 21 Apr 2026 15:58:42 +0200 |
| parents | b51f2d806a47 |
| children | bdd552cd3bfc |
| files | CMakeLists.txt Plugin/WadoRs.cpp |
| diffstat | 2 files changed, 27 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- 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()
--- 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<std::string>(preloaderThreadsCounter++); + preloaderThreadsCounter %= 1000000; + + return threadName; +} + + static WeightedAverageMetrics<float> 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<std::string>(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<std::string>(threadCounter++)); + Orthanc::Logging::ScopedThreadNameSetter setter(std::string("DW-META-") + boost::lexical_cast<std::string>(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<InstanceWorkerData>(threadData)); instancesWorkers.push_back(boost::shared_ptr<boost::thread>(new boost::thread(InstanceWorkerThread, threadData))); }
