mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-26 05:55:51 +00:00
Eliminate redundant write set waits. You don't need to wait on future write sets.
This commit is contained in:
@@ -12,7 +12,7 @@ SETUP_LOG();
|
|||||||
DECLARE_INSTANCE(HashedObject);
|
DECLARE_INSTANCE(HashedObject);
|
||||||
|
|
||||||
HashedObjectStore::HashedObjectStore(int cacheSize, int cacheAge) :
|
HashedObjectStore::HashedObjectStore(int cacheSize, int cacheAge) :
|
||||||
mCache("HashedObjectStore", cacheSize, cacheAge), mWritePending(false)
|
mCache("HashedObjectStore", cacheSize, cacheAge), mWritePending(false), mWriteGeneration(0)
|
||||||
{
|
{
|
||||||
mWriteSet.reserve(128);
|
mWriteSet.reserve(128);
|
||||||
}
|
}
|
||||||
@@ -54,7 +54,8 @@ bool HashedObjectStore::store(HashedObjectType type, uint32 index,
|
|||||||
void HashedObjectStore::waitWrite()
|
void HashedObjectStore::waitWrite()
|
||||||
{
|
{
|
||||||
boost::mutex::scoped_lock sl(mWriteMutex);
|
boost::mutex::scoped_lock sl(mWriteMutex);
|
||||||
while (mWritePending)
|
int gen = mWriteGeneration;
|
||||||
|
while (mWritePending && (mWriteGeneration == gen))
|
||||||
mWriteCondition.wait(sl);
|
mWriteCondition.wait(sl);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,10 +71,11 @@ void HashedObjectStore::bulkWrite()
|
|||||||
boost::mutex::scoped_lock sl(mWriteMutex);
|
boost::mutex::scoped_lock sl(mWriteMutex);
|
||||||
mWriteSet.swap(set);
|
mWriteSet.swap(set);
|
||||||
assert(mWriteSet.empty());
|
assert(mWriteSet.empty());
|
||||||
|
++mWriteGeneration;
|
||||||
|
mWriteCondition.notify_all();
|
||||||
if (set.empty())
|
if (set.empty())
|
||||||
{
|
{
|
||||||
mWritePending = false;
|
mWritePending = false;
|
||||||
mWriteCondition.notify_all();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,8 +47,9 @@ class HashedObjectStore
|
|||||||
protected:
|
protected:
|
||||||
TaggedCache<uint256, HashedObject> mCache;
|
TaggedCache<uint256, HashedObject> mCache;
|
||||||
|
|
||||||
boost::mutex mWriteMutex;
|
boost::mutex mWriteMutex;
|
||||||
boost::condition_variable mWriteCondition;
|
boost::condition_variable mWriteCondition;
|
||||||
|
int mWriteGeneration;
|
||||||
|
|
||||||
std::vector< boost::shared_ptr<HashedObject> > mWriteSet;
|
std::vector< boost::shared_ptr<HashedObject> > mWriteSet;
|
||||||
bool mWritePending;
|
bool mWritePending;
|
||||||
|
|||||||
Reference in New Issue
Block a user