comparison OrthancServer/Sources/ServerJobs/ResourceModificationJob.cpp @ 5141:023569e7155b

moved DicomModification thread safety into ResourceModificationJob (trying to avoid mutex in OrthancFramework as much as possible)
author Alain Mazy <am@osimis.io>
date Fri, 20 Jan 2023 18:10:42 +0100
parents 021d7fdcb659
children 45ce9dfa42e0
comparison
equal deleted inserted replaced
5140:b2b38f9fb9d1 5141:023569e7155b
228 228
229 /** 229 /**
230 * Compute the resulting DICOM instance. 230 * Compute the resulting DICOM instance.
231 **/ 231 **/
232 232
233 modification_->Apply(*modified); 233 {
234 boost::recursive_mutex::scoped_lock lock(mutex_); // DicomModification object is not thread safe, we must protect it from here
235
236 modification_->Apply(*modified);
237 }
234 238
235 const std::string modifiedUid = IDicomTranscoder::GetSopInstanceUid(modified->GetDcmtkObject()); 239 const std::string modifiedUid = IDicomTranscoder::GetSopInstanceUid(modified->GetDcmtkObject());
236 240
237 if (transcode_) 241 if (transcode_)
238 { 242 {
404 { 408 {
405 SetOrigin(DicomInstanceOrigin::FromRest(call)); 409 SetOrigin(DicomInstanceOrigin::FromRest(call));
406 } 410 }
407 411
408 412
413 #if ORTHANC_BUILD_UNIT_TESTS == 1
409 const DicomModification& ResourceModificationJob::GetModification() const 414 const DicomModification& ResourceModificationJob::GetModification() const
410 { 415 {
411 if (modification_.get() == NULL) 416 if (modification_.get() == NULL)
412 { 417 {
413 throw OrthancException(ErrorCode_BadSequenceOfCalls); 418 throw OrthancException(ErrorCode_BadSequenceOfCalls);
415 else 420 else
416 { 421 {
417 return *modification_; 422 return *modification_;
418 } 423 }
419 } 424 }
420 425 #endif
421 426
422 DicomTransferSyntax ResourceModificationJob::GetTransferSyntax() const 427 DicomTransferSyntax ResourceModificationJob::GetTransferSyntax() const
423 { 428 {
424 if (transcode_) 429 if (transcode_)
425 { 430 {
625 } 630 }
626 631
627 origin_.Serialize(value[ORIGIN]); 632 origin_.Serialize(value[ORIGIN]);
628 633
629 Json::Value tmp; 634 Json::Value tmp;
630 modification_->Serialize(tmp); 635
636 {
637 boost::recursive_mutex::scoped_lock lock(mutex_); // DicomModification object is not thread safe, we must protect it from here
638
639 modification_->Serialize(tmp);
640 }
641
631 value[MODIFICATION] = tmp; 642 value[MODIFICATION] = tmp;
632 643
633 // New in Orthanc 1.9.4 644 // New in Orthanc 1.9.4
634 value[IS_SINGLE_RESOURCE] = IsSingleResourceModification(); 645 value[IS_SINGLE_RESOURCE] = IsSingleResourceModification();
635 if (IsSingleResourceModification()) 646 if (IsSingleResourceModification())
755 { 766 {
756 throw OrthancException(ErrorCode_BadRequest, std::string("Trying to change patient tags in a study. The Patient already exists and has other studies. You are trying to replace a tag that is not defined yet in this patient. Try using /patients/../modify instead to modify the patient. Failing tag: ") + mainPatientTag->Format()); 767 throw OrthancException(ErrorCode_BadRequest, std::string("Trying to change patient tags in a study. The Patient already exists and has other studies. You are trying to replace a tag that is not defined yet in this patient. Try using /patients/../modify instead to modify the patient. Failing tag: ") + mainPatientTag->Format());
757 } 768 }
758 } 769 }
759 } 770 }
760 // TODO: need reconstruct_
761 } 771 }
762 } 772 }
763 } 773 }
764 774
765 } 775 }