Mercurial > hg > orthanc-stone
changeset 1140:6333e6f7248e broker
fix cache
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 07 Nov 2019 16:53:15 +0100 |
parents | 8d2f1b25593c |
children | 7d23c43ba555 |
files | Framework/Oracle/GenericOracleRunner.cpp Framework/Oracle/ThreadedOracle.cpp Framework/Toolbox/ParsedDicomFileCache.cpp Framework/Toolbox/ParsedDicomFileCache.h |
diffstat | 4 files changed, 26 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/Framework/Oracle/GenericOracleRunner.cpp Thu Nov 07 09:16:31 2019 +0100 +++ b/Framework/Oracle/GenericOracleRunner.cpp Thu Nov 07 16:53:15 2019 +0100 @@ -261,6 +261,10 @@ throw Orthanc::OrthancException(Orthanc::ErrorCode_InexistentFile); } + LOG(TRACE) << "Parsing DICOM file, " + << (command.IsPixelDataIncluded() ? "with" : "witout") + << " pixel data: " << path; + uint64_t fileSize = Orthanc::SystemToolbox::GetFileSize(path); // Check for 32bit systems @@ -293,8 +297,6 @@ #endif } - printf("Reading %s\n", path.c_str()); - if (ok) { handler.Handle(new Orthanc::ParsedDicomFile(dicom), command, path, fileSize); @@ -372,6 +374,11 @@ // Store it into the cache for future use assert(cache_); + + // Invalidate to overwrite DICOM instance that would already + // be stored without pixel data + cache_->Invalidate(path); + cache_->Acquire(path, parsed.release(), static_cast<size_t>(fileSize), command.IsPixelDataIncluded()); }
--- a/Framework/Oracle/ThreadedOracle.cpp Thu Nov 07 09:16:31 2019 +0100 +++ b/Framework/Oracle/ThreadedOracle.cpp Thu Nov 07 16:53:15 2019 +0100 @@ -396,6 +396,7 @@ } else { + LOG(WARNING) << "Starting oracle with " << workers_.size() << " worker threads"; state_ = State_Running; for (unsigned int i = 0; i < workers_.size(); i++) @@ -424,7 +425,7 @@ } else { - LOG(INFO) << "Command not enqueued, as the oracle is stopped"; + LOG(TRACE) << "Command not enqueued, as the oracle has stopped"; return false; } }
--- a/Framework/Toolbox/ParsedDicomFileCache.cpp Thu Nov 07 09:16:31 2019 +0100 +++ b/Framework/Toolbox/ParsedDicomFileCache.cpp Thu Nov 07 16:53:15 2019 +0100 @@ -79,20 +79,16 @@ ParsedDicomFileCache::Reader::Reader(ParsedDicomFileCache& cache, const std::string& path) : - reader_(cache.cache_, path) + /** + * The "DcmFileFormat" object cannot be accessed from multiple + * threads, even if using only getters. An unique lock (mutex) is + * mandatory. + **/ + accessor_(cache.cache_, path, true /* unique */) { - if (reader_.IsValid()) + if (accessor_.IsValid()) { - /** - * The "Orthanc::MemoryObjectCache" uses readers/writers. The - * "Reader" subclass of the cache locks as a reader. This means - * that multiple threads can still access the underlying - * "ParsedDicomFile" object, which is not supported by DCMTK. We - * thus protect the DCMTK object by a simple mutex. - **/ - - item_ = &dynamic_cast<Item&>(reader_.GetValue()); - lock_.reset(new boost::mutex::scoped_lock(item_->GetMutex())); + item_ = &dynamic_cast<Item&>(accessor_.GetValue()); } else {
--- a/Framework/Toolbox/ParsedDicomFileCache.h Thu Nov 07 09:16:31 2019 +0100 +++ b/Framework/Toolbox/ParsedDicomFileCache.h Thu Nov 07 16:53:15 2019 +0100 @@ -38,6 +38,11 @@ { cache_.SetMaximumSize(size); } + + void Invalidate(const std::string& path) + { + cache_.Invalidate(path); + } void Acquire(const std::string& path, Orthanc::ParsedDicomFile* dicom, @@ -47,9 +52,8 @@ class Reader : public boost::noncopyable { private: - Orthanc::MemoryObjectCache::Reader reader_; - std::auto_ptr<boost::mutex::scoped_lock> lock_; - Item* item_; + Orthanc::MemoryObjectCache::Accessor accessor_; + Item* item_; public: Reader(ParsedDicomFileCache& cache,