# HG changeset patch # User Sebastien Jodogne # Date 1573141995 -3600 # Node ID 6333e6f7248e96cb46d0bade3530be4f2fe25c3b # Parent 8d2f1b25593cbb77775a05242f37f6386fed94c8 fix cache diff -r 8d2f1b25593c -r 6333e6f7248e Framework/Oracle/GenericOracleRunner.cpp --- 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(fileSize), command.IsPixelDataIncluded()); } diff -r 8d2f1b25593c -r 6333e6f7248e Framework/Oracle/ThreadedOracle.cpp --- 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; } } diff -r 8d2f1b25593c -r 6333e6f7248e Framework/Toolbox/ParsedDicomFileCache.cpp --- 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(reader_.GetValue()); - lock_.reset(new boost::mutex::scoped_lock(item_->GetMutex())); + item_ = &dynamic_cast(accessor_.GetValue()); } else { diff -r 8d2f1b25593c -r 6333e6f7248e Framework/Toolbox/ParsedDicomFileCache.h --- 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 lock_; - Item* item_; + Orthanc::MemoryObjectCache::Accessor accessor_; + Item* item_; public: Reader(ParsedDicomFileCache& cache,