diff --git a/src/cpp/ripple/HashedObject.cpp b/src/cpp/ripple/HashedObject.cpp index d64e33a644..fe94aaf045 100644 --- a/src/cpp/ripple/HashedObject.cpp +++ b/src/cpp/ripple/HashedObject.cpp @@ -12,7 +12,7 @@ SETUP_LOG(); DECLARE_INSTANCE(HashedObject); HashedObjectStore::HashedObjectStore(int cacheSize, int cacheAge) : - mCache("HashedObjectStore", cacheSize, cacheAge), mWritePending(false) + mCache("HashedObjectStore", cacheSize, cacheAge), mWritePending(false), mWriteGeneration(0) { mWriteSet.reserve(128); } @@ -54,7 +54,8 @@ bool HashedObjectStore::store(HashedObjectType type, uint32 index, void HashedObjectStore::waitWrite() { boost::mutex::scoped_lock sl(mWriteMutex); - while (mWritePending) + int gen = mWriteGeneration; + while (mWritePending && (mWriteGeneration == gen)) mWriteCondition.wait(sl); } @@ -70,10 +71,11 @@ void HashedObjectStore::bulkWrite() boost::mutex::scoped_lock sl(mWriteMutex); mWriteSet.swap(set); assert(mWriteSet.empty()); + ++mWriteGeneration; + mWriteCondition.notify_all(); if (set.empty()) { mWritePending = false; - mWriteCondition.notify_all(); return; } } diff --git a/src/cpp/ripple/HashedObject.h b/src/cpp/ripple/HashedObject.h index 20a187fb72..69c5e55f79 100644 --- a/src/cpp/ripple/HashedObject.h +++ b/src/cpp/ripple/HashedObject.h @@ -47,8 +47,9 @@ class HashedObjectStore protected: TaggedCache mCache; - boost::mutex mWriteMutex; - boost::condition_variable mWriteCondition; + boost::mutex mWriteMutex; + boost::condition_variable mWriteCondition; + int mWriteGeneration; std::vector< boost::shared_ptr > mWriteSet; bool mWritePending;