diff --git a/include/xrpl/basics/TaggedCache.h b/include/xrpl/basics/TaggedCache.h index 99c91fe393..445dca2a0d 100644 --- a/include/xrpl/basics/TaggedCache.h +++ b/include/xrpl/basics/TaggedCache.h @@ -170,9 +170,6 @@ public: bool retrieve(key_type const& key, T& data); - mutex_type& - peekMutex(); - std::vector getKeys() const; diff --git a/include/xrpl/basics/TaggedCache.ipp b/include/xrpl/basics/TaggedCache.ipp index 16a3f7587a..0ed3c7d497 100644 --- a/include/xrpl/basics/TaggedCache.ipp +++ b/include/xrpl/basics/TaggedCache.ipp @@ -668,29 +668,6 @@ TaggedCache< return true; } -template < - class Key, - class T, - bool IsKeyCache, - class SharedWeakUnionPointer, - class SharedPointerType, - class Hash, - class KeyEqual, - class Mutex> -inline auto -TaggedCache< - Key, - T, - IsKeyCache, - SharedWeakUnionPointer, - SharedPointerType, - Hash, - KeyEqual, - Mutex>::peekMutex() -> mutex_type& -{ - return m_mutex; -} - template < class Key, class T, diff --git a/src/xrpld/app/ledger/LedgerHistory.cpp b/src/xrpld/app/ledger/LedgerHistory.cpp index a9fd097be5..86fa38e5be 100644 --- a/src/xrpld/app/ledger/LedgerHistory.cpp +++ b/src/xrpld/app/ledger/LedgerHistory.cpp @@ -62,8 +62,6 @@ LedgerHistory::insert( ledger->stateMap().getHash().isNonZero(), "ripple::LedgerHistory::insert : nonzero hash"); - std::unique_lock sl(m_ledgers_by_hash.peekMutex()); - bool const alreadyHad = m_ledgers_by_hash.canonicalize_replace_cache( ledger->info().hash, ledger); if (validated) @@ -81,7 +79,6 @@ LedgerHistory::insert( LedgerHash LedgerHistory::getLedgerHash(LedgerIndex index) { - std::unique_lock sl(m_ledgers_by_hash.peekMutex()); if (auto p = mLedgersByIndex.get(index)) return *p; return {}; @@ -90,14 +87,10 @@ LedgerHistory::getLedgerHash(LedgerIndex index) std::shared_ptr LedgerHistory::getLedgerBySeq(LedgerIndex index) { + if (auto p = mLedgersByIndex.get(index)) { - std::unique_lock sl(m_ledgers_by_hash.peekMutex()); - if (auto p = mLedgersByIndex.get(index)) - { - uint256 const hash = *p; - sl.unlock(); - return getLedgerByHash(hash); - } + uint256 const hash = *p; + return getLedgerByHash(hash); } std::shared_ptr ret = loadByIndex(index, app_); @@ -111,8 +104,6 @@ LedgerHistory::getLedgerBySeq(LedgerIndex index) { // Add this ledger to the local tracking by index - std::unique_lock sl(m_ledgers_by_hash.peekMutex()); - XRPL_ASSERT( ret->isImmutable(), "ripple::LedgerHistory::getLedgerBySeq : immutable result ledger"); @@ -466,8 +457,6 @@ LedgerHistory::builtLedger( XRPL_ASSERT( !hash.isZero(), "ripple::LedgerHistory::builtLedger : nonzero hash"); - std::unique_lock sl(m_consensus_validated.peekMutex()); - auto entry = std::make_shared(); m_consensus_validated.canonicalize_replace_client(index, entry); @@ -508,8 +497,6 @@ LedgerHistory::validatedLedger( !hash.isZero(), "ripple::LedgerHistory::validatedLedger : nonzero hash"); - std::unique_lock sl(m_consensus_validated.peekMutex()); - auto entry = std::make_shared(); m_consensus_validated.canonicalize_replace_client(index, entry); @@ -543,7 +530,6 @@ LedgerHistory::validatedLedger( bool LedgerHistory::fixIndex(LedgerIndex ledgerIndex, LedgerHash const& ledgerHash) { - std::unique_lock sl(m_ledgers_by_hash.peekMutex()); if (auto cur = mLedgersByIndex.get(ledgerIndex)) { if (*cur != ledgerHash) diff --git a/src/xrpld/app/ledger/LedgerHistory.h b/src/xrpld/app/ledger/LedgerHistory.h index b1acc3cb2e..383779b3bb 100644 --- a/src/xrpld/app/ledger/LedgerHistory.h +++ b/src/xrpld/app/ledger/LedgerHistory.h @@ -22,7 +22,7 @@ #include #include -#include +#include #include #include @@ -150,7 +150,8 @@ private: ConsensusValidated m_consensus_validated; // Maps ledger indexes to the corresponding hash. - LRUMap mLedgersByIndex; // validated ledgers + LRUCache + mLedgersByIndex; // validated ledgers beast::Journal j_; }; diff --git a/src/xrpld/core/detail/LRUMap.h b/src/xrpld/core/detail/LRUCache.h similarity index 90% rename from src/xrpld/core/detail/LRUMap.h rename to src/xrpld/core/detail/LRUCache.h index 49a94e57d0..d166d06bbc 100644 --- a/src/xrpld/core/detail/LRUMap.h +++ b/src/xrpld/core/detail/LRUCache.h @@ -17,8 +17,8 @@ */ //============================================================================== -#ifndef RIPPLE_APP_LRU_MAP_H_INCLUDED -#define RIPPLE_APP_LRU_MAP_H_INCLUDED +#ifndef RIPPLE_APP_LRU_CACHE_H_INCLUDED +#define RIPPLE_APP_LRU_CACHE_H_INCLUDED #include #include @@ -59,7 +59,7 @@ template < class Key, class Value, class Concurrency = concurrency::SingleThreaded> -class LRUMap +class LRUCache { using List = std::list; // MRU .. LRU using DataMap = std::unordered_map; // Key -> Value @@ -69,31 +69,31 @@ class LRUMap // list public: - explicit LRUMap(std::size_t capacity) : capacity_(capacity) + explicit LRUCache(std::size_t capacity) : capacity_(capacity) { if (capacity_ == 0) - throw std::invalid_argument("LRUMap capacity must be positive."); + throw std::invalid_argument("LRUCache capacity must be positive."); data_.reserve(capacity_); pos_.reserve(capacity_); // TODO: // static_assert(std::is_default_constructible_v, - // "LRUMap requires Value to be default-constructible for + // "LRUCache requires Value to be default-constructible for // operator[]"); // static_assert(std::is_copy_constructible_v || // std::is_move_constructible_v, - // "LRUMap requires Key to be copy- or move-constructible"); + // "LRUCache requires Key to be copy- or move-constructible"); } - LRUMap(LRUMap const&) = delete; + LRUCache(LRUCache const&) = delete; - LRUMap& - operator=(LRUMap const&) = delete; + LRUCache& + operator=(LRUCache const&) = delete; - LRUMap(LRUMap&&) = delete; + LRUCache(LRUCache&&) = delete; - LRUMap& - operator=(LRUMap&&) = delete; + LRUCache& + operator=(LRUCache&&) = delete; Value& operator[](Key const& key)