@@ -574,26 +574,27 @@ getChunkInfo ::
574574getChunkInfo cacheEnv chunk = do
575575 lastUsed <- LastUsed <$> getMonotonicTime
576576 -- Make sure we don't leave an empty MVar in case of an exception.
577- mbCacheHit <- bracketOnError (takeMVar cacheVar) (tryPutMVar cacheVar) $
577+ ( mbCacheHit, tr) <- modifyMVar cacheVar $
578578 \ cached@ Cached { currentChunk, currentChunkInfo, nbPastChunks } -> if
579579 | chunk == currentChunk -> do
580580 -- Cache hit for the current chunk
581- putMVar cacheVar cached
582- traceWith tracer $ TraceCurrentChunkHit chunk nbPastChunks
583- return $ Just $ Left currentChunkInfo
581+ return ( cached
582+ , ( Just $ Left currentChunkInfo, TraceCurrentChunkHit chunk nbPastChunks)
583+ )
584584 | Just (pastChunkInfo, cached') <- lookupPastChunkInfo chunk lastUsed cached -> do
585585 -- Cache hit for an chunk in the past
586- putMVar cacheVar cached'
587- traceWith tracer $ TracePastChunkHit chunk nbPastChunks
588- return $ Just $ Right pastChunkInfo
586+ return ( cached'
587+ , ( Just $ Right pastChunkInfo, TracePastChunkHit chunk nbPastChunks)
588+ )
589589 | otherwise -> do
590590 -- Cache miss for an chunk in the past. We don't want to hold on to
591591 -- the 'cacheVar' MVar, blocking all other access to the cace, while
592592 -- we're reading things from disk, so put it back now and update the
593593 -- cache afterwards.
594- putMVar cacheVar cached
595- traceWith tracer $ TracePastChunkMiss chunk nbPastChunks
596- return Nothing
594+ return ( cached
595+ , (Nothing , TracePastChunkMiss chunk nbPastChunks)
596+ )
597+ traceWith tracer tr
597598 case mbCacheHit of
598599 Just hit -> return hit
599600 Nothing -> do
0 commit comments