Mercurial > hg > orthanc
changeset 7021:27ad2332b84a
hiding dangerous functions PushCurrentThreadContext() and PopCurrentThreadContext()
| author | Sebastien Jodogne <s.jodogne@gmail.com> |
|---|---|
| date | Tue, 07 Jul 2026 15:36:01 +0200 |
| parents | 857f6d9a1089 |
| children | 91b3be9a243a |
| files | OrthancFramework/Sources/Logging.cpp OrthancFramework/Sources/Logging.h OrthancFramework/Sources/MultiThreading/ThreadPool.cpp |
| diffstat | 3 files changed, 22 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancFramework/Sources/Logging.cpp Tue Jul 07 15:14:21 2026 +0200 +++ b/OrthancFramework/Sources/Logging.cpp Tue Jul 07 15:36:01 2026 +0200 @@ -1092,9 +1092,9 @@ } - void PushCurrentThreadContext(const std::string& context) + static void PushCurrentThreadContext(const std::string& context) { - if (context.size() == 0) + if (context.empty()) { throw OrthancException(ErrorCode_ParameterOutOfRange); } @@ -1106,7 +1106,7 @@ } - void PopCurrentThreadContext() + static void PopCurrentThreadContext() { ThreadsInformations::CurrentThreadWriter writer(threadsInformations_); writer.PopContext(); @@ -1121,17 +1121,18 @@ ThreadContextMemento::ScopedSetter::ScopedSetter(const ThreadContextMemento& memento) : - count_(memento.pimpl_->context_.size()) + count_(0) { if (logCallerThreadNameInContext && enableThreadNames_ && !memento.pimpl_->threadName_.empty()) { + PushCurrentThreadContext("from " + memento.pimpl_->threadName_); count_++; - PushCurrentThreadContext("from " + memento.pimpl_->threadName_); } for (std::list<std::string>::const_iterator it = memento.pimpl_->context_.begin(); it != memento.pimpl_->context_.end(); ++it) { PushCurrentThreadContext(*it); + count_++; } } @@ -1378,6 +1379,18 @@ } + ScopedCurrentThreadContextSetter::ScopedCurrentThreadContextSetter(const std::string& context) + { + PushCurrentThreadContext(context); + } + + + ScopedCurrentThreadContextSetter::~ScopedCurrentThreadContextSetter() + { + PopCurrentThreadContext(); + } + + struct InternalLogger::PImpl { boost::mutex::scoped_lock lock_;
--- a/OrthancFramework/Sources/Logging.h Tue Jul 07 15:14:21 2026 +0200 +++ b/OrthancFramework/Sources/Logging.h Tue Jul 07 15:36:01 2026 +0200 @@ -147,10 +147,6 @@ ORTHANC_PUBLIC std::string GetCurrentThreadName(); - ORTHANC_PUBLIC void PushCurrentThreadContext(const std::string& context); - - ORTHANC_PUBLIC void PopCurrentThreadContext(); - ORTHANC_PUBLIC ThreadContextMemento* CreateCurrentThreadContextMemento(); ORTHANC_PUBLIC void AddLoggingListener(ILoggingListener* listener); @@ -204,17 +200,12 @@ class ScopedCurrentThreadContextSetter : public boost::noncopyable { public: - explicit ScopedCurrentThreadContextSetter(const std::string& context) - { - PushCurrentThreadContext(context); - } + explicit ScopedCurrentThreadContextSetter(const std::string& context); - ~ScopedCurrentThreadContextSetter() - { - PopCurrentThreadContext(); - } + ~ScopedCurrentThreadContextSetter(); }; + struct ORTHANC_LOCAL NullStream : public std::ostream { NullStream() :
--- a/OrthancFramework/Sources/MultiThreading/ThreadPool.cpp Tue Jul 07 15:14:21 2026 +0200 +++ b/OrthancFramework/Sources/MultiThreading/ThreadPool.cpp Tue Jul 07 15:36:01 2026 +0200 @@ -209,7 +209,7 @@ void ThreadPool::WorkerLoop(const std::string& threadName) { - Logging::SetCurrentThreadName(threadName); + Logging::ScopedCurrentThreadNameSetter setter(threadName); while (true) {
