Mercurial > hg > orthanc
comparison OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp @ 778:aebf0071020e
refactoring of the mutex for the dicom cache
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 02 May 2014 11:02:23 +0200 |
parents | 5197fd35333c |
children | a60040857ce6 |
comparison
equal
deleted
inserted
replaced
776:be87dd517416 | 778:aebf0071020e |
---|---|
34 | 34 |
35 #include <glog/logging.h> | 35 #include <glog/logging.h> |
36 | 36 |
37 namespace Orthanc | 37 namespace Orthanc |
38 { | 38 { |
39 // TODO IMPROVE MULTITHREADING | |
40 // Every call to "ParsedDicomFile" must lock this mutex!!! | |
41 static boost::mutex cacheMutex_; | |
42 | |
43 | |
44 // Raw access to the DICOM tags of an instance ------------------------------ | 39 // Raw access to the DICOM tags of an instance ------------------------------ |
45 | 40 |
46 static void GetRawContent(RestApi::GetCall& call) | 41 static void GetRawContent(RestApi::GetCall& call) |
47 { | 42 { |
48 boost::mutex::scoped_lock lock(cacheMutex_); | |
49 | |
50 ServerContext& context = OrthancRestApi::GetContext(call); | |
51 | |
52 std::string id = call.GetUriComponent("id", ""); | 43 std::string id = call.GetUriComponent("id", ""); |
53 ParsedDicomFile& dicom = context.GetDicomFile(id); | 44 |
54 dicom.SendPathValue(call.GetOutput(), call.GetTrailingUri()); | 45 ServerContext::DicomCacheLocker locker(OrthancRestApi::GetContext(call), id); |
46 | |
47 locker.GetDicom().SendPathValue(call.GetOutput(), call.GetTrailingUri()); | |
55 } | 48 } |
56 | 49 |
57 | 50 |
58 | 51 |
59 // Modification of DICOM instances ------------------------------------------ | 52 // Modification of DICOM instances ------------------------------------------ |
336 static void AnonymizeOrModifyInstance(Removals& removals, | 329 static void AnonymizeOrModifyInstance(Removals& removals, |
337 Replacements& replacements, | 330 Replacements& replacements, |
338 bool removePrivateTags, | 331 bool removePrivateTags, |
339 RestApi::PostCall& call) | 332 RestApi::PostCall& call) |
340 { | 333 { |
341 boost::mutex::scoped_lock lock(cacheMutex_); | |
342 ServerContext& context = OrthancRestApi::GetContext(call); | |
343 | |
344 std::string id = call.GetUriComponent("id", ""); | 334 std::string id = call.GetUriComponent("id", ""); |
345 ParsedDicomFile& dicom = context.GetDicomFile(id); | 335 |
346 | 336 ServerContext::DicomCacheLocker locker(OrthancRestApi::GetContext(call), id); |
347 std::auto_ptr<ParsedDicomFile> modified(dicom.Clone()); | 337 |
338 std::auto_ptr<ParsedDicomFile> modified(locker.GetDicom().Clone()); | |
348 ReplaceInstanceInternal(*modified, removals, replacements, DicomReplaceMode_InsertIfAbsent, removePrivateTags); | 339 ReplaceInstanceInternal(*modified, removals, replacements, DicomReplaceMode_InsertIfAbsent, removePrivateTags); |
349 modified->Answer(call.GetOutput()); | 340 modified->Answer(call.GetOutput()); |
350 } | 341 } |
351 | 342 |
352 | 343 |
414 typedef std::list<std::string> Instances; | 405 typedef std::list<std::string> Instances; |
415 | 406 |
416 bool isFirst = true; | 407 bool isFirst = true; |
417 Json::Value result(Json::objectValue); | 408 Json::Value result(Json::objectValue); |
418 | 409 |
419 boost::mutex::scoped_lock lock(cacheMutex_); | |
420 ServerContext& context = OrthancRestApi::GetContext(call); | 410 ServerContext& context = OrthancRestApi::GetContext(call); |
421 | 411 |
422 Instances instances; | 412 Instances instances; |
423 std::string id = call.GetUriComponent("id", ""); | 413 std::string id = call.GetUriComponent("id", ""); |
424 context.GetIndex().GetChildInstances(instances, id); | 414 context.GetIndex().GetChildInstances(instances, id); |
435 UidMap uidMap; | 425 UidMap uidMap; |
436 for (Instances::const_iterator it = instances.begin(); | 426 for (Instances::const_iterator it = instances.begin(); |
437 it != instances.end(); ++it) | 427 it != instances.end(); ++it) |
438 { | 428 { |
439 LOG(INFO) << "Modifying instance " << *it; | 429 LOG(INFO) << "Modifying instance " << *it; |
440 ParsedDicomFile& original = context.GetDicomFile(*it); | 430 |
431 std::auto_ptr<ServerContext::DicomCacheLocker> locker; | |
432 | |
433 try | |
434 { | |
435 locker.reset(new ServerContext::DicomCacheLocker(OrthancRestApi::GetContext(call), *it)); | |
436 } | |
437 catch (OrthancException&) | |
438 { | |
439 // This child instance has been removed in between | |
440 continue; | |
441 } | |
442 | |
443 ParsedDicomFile& original = locker->GetDicom(); | |
441 | 444 |
442 DicomInstanceHasher originalHasher = original.GetHasher(); | 445 DicomInstanceHasher originalHasher = original.GetHasher(); |
443 | 446 |
444 if (isFirst && keepPatientId) | 447 if (isFirst && keepPatientId) |
445 { | 448 { |