Mercurial > hg > orthanc
changeset 6856:f71f56755608 streaming
added comment
| author | Sebastien Jodogne <s.jodogne@gmail.com> |
|---|---|
| date | Sat, 23 May 2026 11:56:03 +0200 |
| parents | c954bd4872dc |
| children | 58740529b511 |
| files | OrthancFramework/Sources/DataSource/DataSourceReader.cpp OrthancFramework/Sources/DataSource/DataSourceReader.h OrthancFramework/Sources/DataSource/DicomDataSource.cpp OrthancFramework/Sources/DataSource/StorageAreaDataSource.cpp OrthancFramework/Sources/DataSource/TranscoderDataSource.cpp |
| diffstat | 5 files changed, 27 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- 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<Internals::DataSourceMemoryBudget> budget_; public: - DataSourceRunnable(boost::shared_ptr<DataSourceAnswer>& answer, + DataSourceRunnable(const boost::shared_ptr<DataSourceAnswer>& answer, IDataSource& source, IDataIdentifier* id, boost::shared_ptr<SharedObjectCache>& 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<DataSourceAnswer> 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<IDynamicObject> value; std::unique_ptr<OrthancException> 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<DataSourceAnswer> 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<IDataIdentifier> protection(id);
--- 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<DataSourceAnswer> Submit(DataSourceRequest* request /* takes ownership */); - DataSourceAnswer::Item* ReadSingleWithIdentifier(IDataIdentifier* id /* takes ownership */); + DataSourceAnswer::Item* ReadSingle(IDataIdentifier* id /* takes ownership */); void Stop() {
--- 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<DataSourceAnswer::Item> item(reader.ReadSingleWithIdentifier(request)); + std::unique_ptr<DataSourceAnswer::Item> item(reader.ReadSingle(request)); return new Dicom(item.release()); } }
--- 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<DataSourceAnswer::Item> item(reader.ReadSingleWithIdentifier(request)); + std::unique_ptr<DataSourceAnswer::Item> item(reader.ReadSingle(request)); const Identifier& id = dynamic_cast<const Identifier&>(item->GetId());
--- 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<DataSourceAnswer::Item> item(reader.ReadSingleWithIdentifier(request)); + std::unique_ptr<DataSourceAnswer::Item> item(reader.ReadSingle(request)); return new Transcoded(item.release()); } }
