# HG changeset patch # User Sebastien Jodogne # Date 1782748344 -7200 # Node ID 1f22c8f22ede175aeea1c19c7330bbc7c8c57db3 # Parent 2c0edc2660f0d5076a2aa9c8da28cd009ae399f4 recycling thread information diff -r 2c0edc2660f0 -r 1f22c8f22ede OrthancFramework/Sources/Logging.cpp --- a/OrthancFramework/Sources/Logging.cpp Mon Jun 29 16:13:42 2026 +0200 +++ b/OrthancFramework/Sources/Logging.cpp Mon Jun 29 17:52:24 2026 +0200 @@ -716,11 +716,6 @@ { return context_; } - - void CopyContext(std::list& target) const - { - target = context_; - } }; @@ -815,7 +810,7 @@ if (exists_) { assert(information_ != NULL); - information_->CopyContext(target); + target = information_->GetContext(); } else { @@ -832,12 +827,30 @@ boost::unique_lock lock_; boost::thread::id threadId_; ThreadInformation* information_; + bool valid_; + + void Recycle() + { + if (!information_->HasThreadName() && + information_->GetContext().empty()) + { + Content::iterator found = informations_.content_.find(threadId_); + assert(found != informations_.content_.end()); + assert(found->second != NULL); + + delete found->second; + informations_.content_.erase(found); + + valid_ = false; + } + } public: explicit CurrentThreadWriter(ThreadsInformations& informations) : informations_(informations), lock_(informations.mutex_), - threadId_(boost::this_thread::get_id()) + threadId_(boost::this_thread::get_id()), + valid_(true) { Content::iterator found = informations.content_.find(threadId_); @@ -855,6 +868,11 @@ void SetThreadName(const std::string& name) { + if (!valid_) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); + } + assert(information_ != NULL); information_->SetThreadName(name); @@ -876,22 +894,41 @@ #endif } - void ClearThreadName() - { - assert(information_ != NULL); - information_->ClearThreadName(); - } - void PushContext(const std::string& context) { + if (!valid_) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); + } + assert(information_ != NULL); information_->PushContext(context); } + void ClearThreadName() + { + if (!valid_) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); + } + + assert(information_ != NULL); + information_->ClearThreadName(); + + Recycle(); + } + void PopContext() { + if (!valid_) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); + } + assert(information_ != NULL); information_->PopContext(); + + Recycle(); } }; };