Mercurial > hg > orthanc
comparison OrthancServer/Sources/ServerJobs/ResourceModificationJob.cpp @ 5130:f2dcdbe05884
ResourceModification jobs can now use multiple threads
author | Alain Mazy <am@osimis.io> |
---|---|
date | Thu, 05 Jan 2023 17:24:43 +0100 |
parents | 6eff25f70121 |
children | 6aa41d86b948 |
comparison
equal
deleted
inserted
replaced
5128:ede035d48b8e | 5130:f2dcdbe05884 |
---|---|
291 * lossy transfer syntax is enabled in the Orthanc core, and if | 291 * lossy transfer syntax is enabled in the Orthanc core, and if |
292 * the source instance is not in this transfer syntax. | 292 * the source instance is not in this transfer syntax. |
293 **/ | 293 **/ |
294 // assert(modifiedInstance == modifiedHasher.HashInstance()); | 294 // assert(modifiedInstance == modifiedHasher.HashInstance()); |
295 | 295 |
296 output_->Update(modifiedHasher); | 296 { |
297 boost::recursive_mutex::scoped_lock lock(outputMutex_); | |
298 | |
299 output_->Update(modifiedHasher); | |
300 } | |
297 | 301 |
298 return true; | 302 return true; |
299 } | 303 } |
300 | 304 |
301 | 305 |
302 ResourceModificationJob::ResourceModificationJob(ServerContext& context) : | 306 ResourceModificationJob::ResourceModificationJob(ServerContext& context, unsigned int workersCount) : |
303 CleaningInstancesJob(context, true /* by default, keep source */), | 307 ThreadedSetOfInstancesJob(context, false /* no post processing step */, true /* by default, keep source */, workersCount), |
304 isAnonymization_(false), | 308 isAnonymization_(false), |
305 transcode_(false), | 309 transcode_(false), |
306 transferSyntax_(DicomTransferSyntax_LittleEndianExplicit) // dummy initialization | 310 transferSyntax_(DicomTransferSyntax_LittleEndianExplicit) // dummy initialization |
307 { | 311 { |
308 } | 312 } |
443 assert(output_.get() == NULL); | 447 assert(output_.get() == NULL); |
444 throw OrthancException(ErrorCode_BadSequenceOfCalls); | 448 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
445 } | 449 } |
446 else | 450 else |
447 { | 451 { |
452 boost::recursive_mutex::scoped_lock lock(outputMutex_); | |
453 | |
448 assert(output_.get() != NULL); | 454 assert(output_.get() != NULL); |
449 return output_->IsSingleResource(); | 455 return output_->IsSingleResource(); |
450 } | 456 } |
451 } | 457 } |
452 | 458 |
453 | 459 |
454 ResourceType ResourceModificationJob::GetOutputLevel() const | 460 ResourceType ResourceModificationJob::GetOutputLevel() const |
455 { | 461 { |
462 boost::recursive_mutex::scoped_lock lock(outputMutex_); | |
463 | |
456 if (IsSingleResourceModification()) | 464 if (IsSingleResourceModification()) |
457 { | 465 { |
458 assert(modification_.get() != NULL && | 466 assert(modification_.get() != NULL && |
459 output_.get() != NULL); | 467 output_.get() != NULL); |
460 return dynamic_cast<const SingleOutput&>(*output_).GetLevel(); | 468 return dynamic_cast<const SingleOutput&>(*output_).GetLevel(); |
467 } | 475 } |
468 | 476 |
469 | 477 |
470 void ResourceModificationJob::GetPublicContent(Json::Value& value) | 478 void ResourceModificationJob::GetPublicContent(Json::Value& value) |
471 { | 479 { |
472 CleaningInstancesJob::GetPublicContent(value); | 480 boost::recursive_mutex::scoped_lock lock(outputMutex_); |
481 | |
482 ThreadedSetOfInstancesJob::GetPublicContent(value); | |
473 | 483 |
474 value["IsAnonymization"] = isAnonymization_; | 484 value["IsAnonymization"] = isAnonymization_; |
475 | 485 |
476 if (output_.get() != NULL) | 486 if (output_.get() != NULL) |
477 { | 487 { |
493 static const char* IS_SINGLE_RESOURCE = "IsSingleResource"; | 503 static const char* IS_SINGLE_RESOURCE = "IsSingleResource"; |
494 | 504 |
495 | 505 |
496 ResourceModificationJob::ResourceModificationJob(ServerContext& context, | 506 ResourceModificationJob::ResourceModificationJob(ServerContext& context, |
497 const Json::Value& serialized) : | 507 const Json::Value& serialized) : |
498 CleaningInstancesJob(context, serialized, true /* by default, keep source */), | 508 ThreadedSetOfInstancesJob(context, serialized, false /* no post processing step */, true /* by default, keep source */), |
499 transferSyntax_(DicomTransferSyntax_LittleEndianExplicit) // dummy initialization | 509 transferSyntax_(DicomTransferSyntax_LittleEndianExplicit) // dummy initialization |
500 { | 510 { |
501 assert(serialized.type() == Json::objectValue); | 511 assert(serialized.type() == Json::objectValue); |
502 | 512 |
503 origin_ = DicomInstanceOrigin(serialized[ORIGIN]); | 513 origin_ = DicomInstanceOrigin(serialized[ORIGIN]); |
563 { | 573 { |
564 if (modification_.get() == NULL) | 574 if (modification_.get() == NULL) |
565 { | 575 { |
566 throw OrthancException(ErrorCode_BadSequenceOfCalls); | 576 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
567 } | 577 } |
568 else if (!CleaningInstancesJob::Serialize(value)) | 578 else if (!ThreadedSetOfInstancesJob::Serialize(value)) |
569 { | 579 { |
570 return false; | 580 return false; |
571 } | 581 } |
572 else | 582 else |
573 { | 583 { |