diff --git a/include/xrpl/basics/TaggedCache.ipp b/include/xrpl/basics/TaggedCache.ipp index cee02749c62..8e235dbb238 100644 --- a/include/xrpl/basics/TaggedCache.ipp +++ b/include/xrpl/basics/TaggedCache.ipp @@ -2,6 +2,7 @@ #include #include +#include namespace xrpl { @@ -536,8 +537,15 @@ TaggedCache v; { - std::scoped_lock const lock(mutex_); - v.reserve(cache_.size()); + std::unique_lock lock(mutex_); + for (auto size = cache_.size(); v.capacity() < size; size = cache_.size()) + { + ScopeUnlock const unlock(lock); + v.reserve(size); + } + XRPL_ASSERT(lock.owns_lock(), "xrpl::TaggedCache::getKeys(): owns lock"); + XRPL_ASSERT( + v.capacity() >= cache_.size(), "xrpl::TaggedCache::getKeys(): sufficient capacity"); for (auto const& _ : cache_) v.push_back(_.first); }