44#include " ECExtentCache.h"
55#include " ECUtil.h"
66
7+ #include < mutex>
78#include < ranges>
89
910using namespace std ;
@@ -369,41 +370,37 @@ void ECExtentCache::LRU::add(const Line &line) {
369370
370371 shared_ptr<shard_extent_map_t > cache = line.cache ;
371372
372- mutex. lock () ;
373+ std::lock_guard lock{mutex} ;
373374 ceph_assert (!map.contains (k));
374375 auto i = lru.insert (lru.end (), k);
375376 auto j = make_pair (std::move (i), std::move (cache));
376377 map.insert (std::pair (std::move (k), std::move (j)));
377378 size += line.size ; // This is already accounted for in mempool.
378379 free_maybe ();
379- mutex.unlock ();
380380}
381381
382382shared_ptr<shard_extent_map_t > ECExtentCache::LRU::find (
383383 const hobject_t &oid, uint64_t offset) {
384- Key k (offset, oid);
385384 shared_ptr<shard_extent_map_t > cache = nullptr ;
386- mutex. lock () ;
387- if (map.contains (k )) {
388- auto &&[lru_iter, c] = map. at (k) ;
385+ std::lock_guard lock{mutex} ;
386+ if (auto found = map.find ({offset, oid}); found != map. end ( )) {
387+ auto &&[lru_iter, c] = found-> second ;
389388 cache = c;
390389 auto it = lru_iter; // Intentional copy.
391390 erase (it, false );
392391 }
393- mutex.unlock ();
394392 return cache;
395393}
396394
397395void ECExtentCache::LRU::remove_object (const hobject_t &oid) {
398- mutex. lock () ;
396+ std::lock_guard lock{mutex} ;
399397 for (auto it = lru.begin (); it != lru.end ();) {
400398 if (it->oid == oid) {
401399 it = erase (it, true );
402400 } else {
403401 ++it;
404402 }
405403 }
406- mutex.unlock ();
407404}
408405
409406void ECExtentCache::LRU::free_maybe () {
@@ -414,12 +411,11 @@ void ECExtentCache::LRU::free_maybe() {
414411}
415412
416413void ECExtentCache::LRU::discard () {
417- mutex. lock () ;
414+ std::lock_guard lock{mutex} ;
418415 lru.clear ();
419416 update_mempool (0 - map.size (), 0 - size);
420417 map.clear ();
421418 size = 0 ;
422- mutex.unlock ();
423419}
424420
425421const extent_set ECExtentCache::Op::get_pin_eset (uint64_t alignment) const {
0 commit comments