# HG changeset patch # User Sebastien Jodogne # Date 1734702968 -3600 # Node ID 03d33290cba16e094f3ddbd53187067415259a21 # Parent a307ec25a00828c18dcebcead7bcd6ddd54af7a0 fix concurrency issue diff -r a307ec25a008 -r 03d33290cba1 Framework/Inputs/DecodedPyramidCache.cpp --- a/Framework/Inputs/DecodedPyramidCache.cpp Fri Dec 20 13:48:34 2024 +0100 +++ b/Framework/Inputs/DecodedPyramidCache.cpp Fri Dec 20 14:56:08 2024 +0100 @@ -97,23 +97,41 @@ DecodedPyramidCache::CachedPyramid * DecodedPyramidCache::Store(FrameIdentifier identifier, - DecodedTiledPyramid *pyramid) + DecodedTiledPyramid *pyramid) { // Mutex must be locked std::unique_ptr payload(new CachedPyramid(pyramid)); - CachedPyramid* result = payload.get(); + CachedPyramid* result; - MakeRoom(payload->GetMemoryUsage()); + if (cache_.Contains(identifier, result)) + { + // This element has already been cached by another thread + if (result == NULL) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); + } - memoryUsage_ += payload->GetMemoryUsage(); + // Tag the series as the most recently used + cache_.MakeMostRecent(identifier); - // Add a new element to the cache and make it the most - // recently used entry - cache_.Add(identifier, payload.release()); + return result; + } + else + { + result = payload.get(); + + MakeRoom(payload->GetMemoryUsage()); - assert(SanityCheck()); - return result; + memoryUsage_ += payload->GetMemoryUsage(); + + // Add a new element to the cache and make it the most + // recently used entry + cache_.Add(identifier, payload.release()); + + assert(SanityCheck()); + return result; + } }