comparison OrthancServer/ServerContext.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 4e3593c3511d
children 381f90e2b69d
comparison
equal deleted inserted replaced
776:be87dd517416 778:aebf0071020e
220 context_.ReadFile(content, instancePublicId, FileContentType_Dicom); 220 context_.ReadFile(content, instancePublicId, FileContentType_Dicom);
221 return new ParsedDicomFile(content); 221 return new ParsedDicomFile(content);
222 } 222 }
223 223
224 224
225 ParsedDicomFile& ServerContext::GetDicomFile(const std::string& instancePublicId) 225 ServerContext::DicomCacheLocker::DicomCacheLocker(ServerContext& that,
226 const std::string& instancePublicId) :
227 that_(that)
226 { 228 {
227 #if ENABLE_DICOM_CACHE == 0 229 #if ENABLE_DICOM_CACHE == 0
228 static std::auto_ptr<IDynamicObject> p; 230 static std::auto_ptr<IDynamicObject> p;
229 p.reset(provider_.Provide(instancePublicId)); 231 p.reset(provider_.Provide(instancePublicId));
230 return dynamic_cast<ParsedDicomFile&>(*p); 232 dicom_ = dynamic_cast<ParsedDicomFile*>(p.get());
231 #else 233 #else
232 return dynamic_cast<ParsedDicomFile&>(dicomCache_.Access(instancePublicId)); 234 that_.dicomCacheMutex_.lock();
235 dicom_ = &dynamic_cast<ParsedDicomFile&>(that_.dicomCache_.Access(instancePublicId));
236 #endif
237 }
238
239
240 ServerContext::DicomCacheLocker::~DicomCacheLocker()
241 {
242 #if ENABLE_DICOM_CACHE == 0
243 #else
244 that_.dicomCacheMutex_.unlock();
233 #endif 245 #endif
234 } 246 }
235 247
236 248
237 StoreStatus ServerContext::Store(std::string& resultPublicId, 249 StoreStatus ServerContext::Store(std::string& resultPublicId,