# HG changeset patch # User Sebastien Jodogne # Date 1779530163 -7200 # Node ID f71f567556086bfcdad1a9ec8f6838c63a9fee9b # Parent c954bd4872dc7ed3161cf257b9b07d51facc05c0 added comment diff -r c954bd4872dc -r f71f56755608 OrthancFramework/Sources/DataSource/DataSourceReader.cpp --- a/OrthancFramework/Sources/DataSource/DataSourceReader.cpp Sat May 23 10:31:32 2026 +0200 +++ b/OrthancFramework/Sources/DataSource/DataSourceReader.cpp Sat May 23 11:56:03 2026 +0200 @@ -46,7 +46,7 @@ boost::shared_ptr budget_; public: - DataSourceRunnable(boost::shared_ptr& answer, + DataSourceRunnable(const boost::shared_ptr& answer, IDataSource& source, IDataIdentifier* id, boost::shared_ptr& cache, @@ -66,7 +66,17 @@ virtual void Run() ORTHANC_OVERRIDE { - // Phase 1: Do all the work WITHOUT holding a strong reference to "DataSourceAnswer". + // Phase 1: Make sure the target answer is still alive before doing unnecessary work. + { + boost::shared_ptr lock = answer_.lock(); + if (!lock) + { + // The answer was abandonned, give up the request + return; + } + } + + // Phase 2: Do all the work WITHOUT holding a strong reference to "DataSourceAnswer". boost::shared_ptr value; std::unique_ptr error; @@ -119,7 +129,7 @@ error.reset(new OrthancException(ErrorCode_InternalError)); } - // Phase 2: Acquire budget WITHOUT holding a strong reference to "DataSourceAnswer". + // Phase 3: Acquire budget WITHOUT holding a strong reference to "DataSourceAnswer". // If the "DataSourceAnswer" has been dropped, "answer_.lock()" below will return NULL // and we will immediately "Release()" to revert this. if (!error) @@ -127,7 +137,7 @@ budget_->Acquire(size); // may block; "DataSourceAnswer" CAN be destroyed here } - // Phase 3: Only now take a strong reference to "DataSourceAnswer". + // Phase 4: Only now take a strong reference to "DataSourceAnswer". { boost::shared_ptr lock = answer_.lock(); @@ -207,7 +217,7 @@ } - DataSourceAnswer::Item* DataSourceReader::ReadSingleWithIdentifier(IDataIdentifier* id /* takes ownership */) + DataSourceAnswer::Item* DataSourceReader::ReadSingle(IDataIdentifier* id /* takes ownership */) { std::unique_ptr protection(id); diff -r c954bd4872dc -r f71f56755608 OrthancFramework/Sources/DataSource/DataSourceReader.h --- a/OrthancFramework/Sources/DataSource/DataSourceReader.h Sat May 23 10:31:32 2026 +0200 +++ b/OrthancFramework/Sources/DataSource/DataSourceReader.h Sat May 23 11:56:03 2026 +0200 @@ -41,7 +41,6 @@ class DataSourceMemoryBudget; } - // TODO-Streaming: Is it useful for DataSourceRequest and DataSourceAnswer to handle multiple requests? class ORTHANC_PUBLIC DataSourceReader : public boost::noncopyable { private: @@ -66,9 +65,17 @@ **/ void SetCapacity(uint64_t maximumMemory); + /** + * Request the data source to load a set of items. The values will + * be read in parallel by a thread pool (cf. "executor_") and will + * be answered in no specific order through a message queue + * (cf. class "DataSourceAnswer"). The user data stored in + * "IDataIdentifier" can be used to identify items. If order is + * important, use the class "DataSourceSequentialReader" instead. + **/ boost::shared_ptr Submit(DataSourceRequest* request /* takes ownership */); - DataSourceAnswer::Item* ReadSingleWithIdentifier(IDataIdentifier* id /* takes ownership */); + DataSourceAnswer::Item* ReadSingle(IDataIdentifier* id /* takes ownership */); void Stop() { diff -r c954bd4872dc -r f71f56755608 OrthancFramework/Sources/DataSource/DicomDataSource.cpp --- a/OrthancFramework/Sources/DataSource/DicomDataSource.cpp Sat May 23 10:31:32 2026 +0200 +++ b/OrthancFramework/Sources/DataSource/DicomDataSource.cpp Sat May 23 11:56:03 2026 +0200 @@ -240,7 +240,7 @@ } else { - std::unique_ptr item(reader.ReadSingleWithIdentifier(request)); + std::unique_ptr item(reader.ReadSingle(request)); return new Dicom(item.release()); } } diff -r c954bd4872dc -r f71f56755608 OrthancFramework/Sources/DataSource/StorageAreaDataSource.cpp --- a/OrthancFramework/Sources/DataSource/StorageAreaDataSource.cpp Sat May 23 10:31:32 2026 +0200 +++ b/OrthancFramework/Sources/DataSource/StorageAreaDataSource.cpp Sat May 23 11:56:03 2026 +0200 @@ -417,7 +417,7 @@ } else { - std::unique_ptr item(reader.ReadSingleWithIdentifier(request)); + std::unique_ptr item(reader.ReadSingle(request)); const Identifier& id = dynamic_cast(item->GetId()); diff -r c954bd4872dc -r f71f56755608 OrthancFramework/Sources/DataSource/TranscoderDataSource.cpp --- a/OrthancFramework/Sources/DataSource/TranscoderDataSource.cpp Sat May 23 10:31:32 2026 +0200 +++ b/OrthancFramework/Sources/DataSource/TranscoderDataSource.cpp Sat May 23 11:56:03 2026 +0200 @@ -326,7 +326,7 @@ } else { - std::unique_ptr item(reader.ReadSingleWithIdentifier(request)); + std::unique_ptr item(reader.ReadSingle(request)); return new Transcoded(item.release()); } }