mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-28 06:55:50 +00:00
Factor upTime() out of KeyCache, fix warnings
This commit is contained in:
@@ -1,15 +1,15 @@
|
||||
#ifndef KEY_CACHE__H
|
||||
#define KEY_CACHE__H
|
||||
#ifndef RIPPLE_KEYCACHE_H
|
||||
#define RIPPLE_KEYCACHE_H
|
||||
|
||||
#include <string>
|
||||
/** Maintains a cache of keys with no associated data
|
||||
|
||||
#include <boost/unordered_map.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
Timer must have this interface:
|
||||
|
||||
extern int upTime();
|
||||
|
||||
template <typename c_Key> class KeyCache
|
||||
{ // Maintains a cache of keys with no associated data
|
||||
static int Timer::getElapsedSeconds ();
|
||||
*/
|
||||
template <typename c_Key, class Timer>
|
||||
class KeyCache
|
||||
{
|
||||
public:
|
||||
typedef c_Key key_type;
|
||||
typedef boost::unordered_map<key_type, int> map_type;
|
||||
@@ -67,7 +67,7 @@ public:
|
||||
if (it == mCache.end())
|
||||
return false;
|
||||
if (refresh)
|
||||
it->second = upTime();
|
||||
it->second = Timer::getElapsedSeconds ();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -90,16 +90,16 @@ public:
|
||||
map_iterator it = mCache.find(key);
|
||||
if (it != mCache.end())
|
||||
{
|
||||
it->second = upTime();
|
||||
it->second = Timer::getElapsedSeconds ();
|
||||
return false;
|
||||
}
|
||||
mCache.insert(std::make_pair(key, upTime()));
|
||||
mCache.insert(std::make_pair(key, Timer::getElapsedSeconds ()));
|
||||
return true;
|
||||
}
|
||||
|
||||
void sweep()
|
||||
{ // Remove stale entries from the cache
|
||||
int now = upTime();
|
||||
int now = Timer::getElapsedSeconds ();
|
||||
boost::mutex::scoped_lock sl(mNCLock);
|
||||
|
||||
int target;
|
||||
@@ -34,7 +34,14 @@
|
||||
|
||||
#include <ctime>
|
||||
|
||||
#include "src/cpp/ripple/IntegerTypes.h"
|
||||
// KeyCache
|
||||
#include <string>
|
||||
#include <boost/unordered_map.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
|
||||
#include "types/ripple_IntegerTypes.h"
|
||||
|
||||
#include "containers/ripple_KeyCache.h"
|
||||
|
||||
#include "events/ripple_UptimeTimer.h"
|
||||
|
||||
|
||||
@@ -24,18 +24,6 @@
|
||||
|
||||
#include "ripple_db.h"
|
||||
|
||||
// VFALCO: TODO, fix these warnings!
|
||||
#ifdef _MSC_VER
|
||||
//#pragma warning (push) // Causes spurious C4503 "decorated name exceeds maximum length"
|
||||
//#pragma warning (disable: 4018) // signed/unsigned mismatch
|
||||
//#pragma warning (disable: 4244) // conversion, possible loss of data
|
||||
#endif
|
||||
|
||||
#include "src/cpp/database/database.cpp"
|
||||
#include "src/cpp/database/SqliteDatabase.cpp"
|
||||
#include "src/cpp/ripple/DBInit.cpp"
|
||||
|
||||
|
||||
#ifdef _MSC_VER
|
||||
//#pragma warning (pop)
|
||||
#endif
|
||||
|
||||
@@ -27,8 +27,9 @@
|
||||
// VFALCO: TODO, fix these warnings!
|
||||
#ifdef _MSC_VER
|
||||
//#pragma warning (push) // Causes spurious C4503 "decorated name exceeds maximum length"
|
||||
//#pragma warning (disable: 4018) // signed/unsigned mismatch
|
||||
//#pragma warning (disable: 4244) // conversion, possible loss of data
|
||||
#pragma warning (disable: 4018) // signed/unsigned mismatch
|
||||
#pragma warning (disable: 4244) // conversion, possible loss of data
|
||||
#pragma warning (disable: 4535) // call requires /EHa
|
||||
#endif
|
||||
|
||||
#include "src/cpp/ripple/Application.cpp"
|
||||
@@ -41,7 +42,6 @@
|
||||
#include "src/cpp/ripple/main.cpp"
|
||||
#include "src/cpp/ripple/ValidationCollection.cpp"
|
||||
|
||||
|
||||
#ifdef _MSC_VER
|
||||
//#pragma warning (pop)
|
||||
#endif
|
||||
|
||||
@@ -27,8 +27,9 @@
|
||||
// VFALCO: TODO, fix these warnings!
|
||||
#ifdef _MSC_VER
|
||||
//#pragma warning (push) // Causes spurious C4503 "decorated name exceeds maximum length"
|
||||
//#pragma warning (disable: 4018) // signed/unsigned mismatch
|
||||
//#pragma warning (disable: 4244) // conversion, possible loss of data
|
||||
#pragma warning (disable: 4018) // signed/unsigned mismatch
|
||||
#pragma warning (disable: 4244) // conversion, possible loss of data
|
||||
#pragma warning (disable: 4309) // truncation of constant value
|
||||
#endif
|
||||
|
||||
#include "src/cpp/ripple/Application.h"
|
||||
|
||||
@@ -1169,8 +1169,10 @@
|
||||
<ClInclude Include="build\proto\ripple.pb.h" />
|
||||
<ClInclude Include="database\sqlite3.h" />
|
||||
<ClInclude Include="database\sqlite3ext.h" />
|
||||
<ClInclude Include="modules\ripple_basics\containers\ripple_KeyCache.h" />
|
||||
<ClInclude Include="modules\ripple_basics\events\ripple_UptimeTimer.h" />
|
||||
<ClInclude Include="modules\ripple_basics\ripple_basics.h" />
|
||||
<ClInclude Include="modules\ripple_basics\types\ripple_IntegerTypes.h" />
|
||||
<ClInclude Include="modules\ripple_client\ripple_client.h" />
|
||||
<ClInclude Include="modules\ripple_db\ripple_db.h" />
|
||||
<ClInclude Include="modules\ripple_ledger\ripple_ledger.h" />
|
||||
@@ -1567,7 +1569,6 @@
|
||||
<ClInclude Include="src\cpp\ripple\Interpreter.h" />
|
||||
<ClInclude Include="src\cpp\ripple\JobQueue.h" />
|
||||
<ClInclude Include="src\cpp\ripple\key.h" />
|
||||
<ClInclude Include="src\cpp\ripple\KeyCache.h" />
|
||||
<ClInclude Include="src\cpp\ripple\Ledger.h" />
|
||||
<ClInclude Include="src\cpp\ripple\LedgerAcquire.h" />
|
||||
<ClInclude Include="src\cpp\ripple\LedgerConsensus.h" />
|
||||
@@ -1634,7 +1635,6 @@
|
||||
<ClInclude Include="src\cpp\ripple\TransactionQueue.h" />
|
||||
<ClInclude Include="src\cpp\ripple\Transactor.h" />
|
||||
<ClInclude Include="src\cpp\ripple\TrustSetTransactor.h" />
|
||||
<ClInclude Include="src\cpp\ripple\IntegerTypes.h" />
|
||||
<ClInclude Include="src\cpp\ripple\uint256.h" />
|
||||
<ClInclude Include="src\cpp\ripple\UniqueNodeList.h" />
|
||||
<ClInclude Include="src\cpp\ripple\utils.h" />
|
||||
|
||||
@@ -1373,21 +1373,21 @@
|
||||
<ClInclude Include="build\proto\ripple.pb.h">
|
||||
<Filter>1. Modules\ripple_mess\protobuf</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\cpp\ripple\IntegerTypes.h">
|
||||
<Filter>1. Modules\ripple_basics\types</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\cpp\ripple\SerializeProto.h">
|
||||
<Filter>1. Modules\ripple_mess\types</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="modules\ripple_mess\ripple_mess.h">
|
||||
<Filter>1. Modules\ripple_mess</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\cpp\ripple\KeyCache.h">
|
||||
<Filter>1. Modules\ripple_basics\containers</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="modules\ripple_basics\events\ripple_UptimeTimer.h">
|
||||
<Filter>1. Modules\ripple_basics\events</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="modules\ripple_basics\containers\ripple_KeyCache.h">
|
||||
<Filter>1. Modules\ripple_basics\containers</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="modules\ripple_basics\types\ripple_IntegerTypes.h">
|
||||
<Filter>1. Modules\ripple_basics\types</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="SConstruct" />
|
||||
|
||||
@@ -128,6 +128,7 @@ int SqliteDatabase::getNumRowsAffected()
|
||||
}
|
||||
|
||||
// VFALCO: TODO, This must be fixed!!! return value needs to be int64
|
||||
//
|
||||
int SqliteDatabase::getLastInsertID()
|
||||
{
|
||||
return(sqlite3_last_insert_rowid(mConnection));
|
||||
@@ -192,12 +193,12 @@ int32 SqliteDatabase::getInt(int colIndex)
|
||||
|
||||
float SqliteDatabase::getFloat(int colIndex)
|
||||
{
|
||||
return(sqlite3_column_double(mCurrentStmt, colIndex));
|
||||
return(static_cast <float> (sqlite3_column_double(mCurrentStmt, colIndex)));
|
||||
}
|
||||
|
||||
bool SqliteDatabase::getBool(int colIndex)
|
||||
{
|
||||
return(sqlite3_column_int(mCurrentStmt, colIndex));
|
||||
return(sqlite3_column_int(mCurrentStmt, colIndex) ? true : false);
|
||||
}
|
||||
|
||||
int SqliteDatabase::getBinary(int colIndex,unsigned char* buf,int maxSize)
|
||||
|
||||
@@ -9,9 +9,21 @@
|
||||
#include "uint256.h"
|
||||
#include "ScopedLock.h"
|
||||
#include "TaggedCache.h"
|
||||
#include "KeyCache.h"
|
||||
#include "InstanceCounter.h"
|
||||
|
||||
|
||||
// VFALCO: TODO, Move this to someplace sensible!!
|
||||
// Adapter to furnish uptime information to KeyCache via UptimeTimer singleton
|
||||
struct KeyCacheUptimeTimer
|
||||
{
|
||||
inline static int getElapsedSeconds ()
|
||||
{
|
||||
return UptimeTimer::getInstance().getElapsedSeconds ();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
DEFINE_INSTANCE(HashedObject);
|
||||
|
||||
class Job;
|
||||
@@ -51,7 +63,7 @@ class HashedObjectStore
|
||||
{
|
||||
protected:
|
||||
TaggedCache<uint256, HashedObject> mCache;
|
||||
KeyCache<uint256> mNegativeCache;
|
||||
KeyCache <uint256, KeyCacheUptimeTimer> mNegativeCache;
|
||||
|
||||
boost::mutex mWriteMutex;
|
||||
boost::condition_variable mWriteCondition;
|
||||
|
||||
@@ -146,7 +146,7 @@ class LedgerAcquireMaster
|
||||
protected:
|
||||
boost::mutex mLock;
|
||||
std::map<uint256, LedgerAcquire::pointer> mLedgers;
|
||||
KeyCache<uint256> mRecentFailures;
|
||||
KeyCache<uint256, KeyCacheUptimeTimer> mRecentFailures;
|
||||
|
||||
public:
|
||||
LedgerAcquireMaster() : mRecentFailures("LedgerAcquireRecentFailures", 0, LEDGER_REACQUIRE_INTERVAL) { ; }
|
||||
|
||||
@@ -1644,7 +1644,7 @@ void Peer::recvGetLedger(ripple::TMGetLedger& packet, ScopedLock& MasterLockHold
|
||||
else
|
||||
WriteLog (lsWARNING, Peer) << "getNodeFat returns false";
|
||||
}
|
||||
catch (std::exception& e)
|
||||
catch (std::exception&)
|
||||
{
|
||||
std::string info;
|
||||
if (packet.itype() == ripple::liTS_CANDIDATE)
|
||||
|
||||
@@ -778,7 +778,7 @@ void SHAMap::fetchRoot(const uint256& hash, SHAMapSyncFilter* filter)
|
||||
{
|
||||
root = fetchNodeExternal(SHAMapNode(), hash);
|
||||
}
|
||||
catch (SHAMapMissingNode& mn)
|
||||
catch (SHAMapMissingNode&)
|
||||
{
|
||||
std::vector<unsigned char> nodeData;
|
||||
if (!filter || !filter->haveNode(SHAMapNode(), hash, nodeData))
|
||||
|
||||
@@ -356,7 +356,7 @@ protected:
|
||||
|
||||
SHAMapType mType;
|
||||
|
||||
static KeyCache<uint256> fullBelowCache;
|
||||
static KeyCache <uint256, KeyCacheUptimeTimer> fullBelowCache;
|
||||
|
||||
void dirtyUp(std::stack<SHAMapTreeNode::pointer>& stack, const uint256& target, uint256 prevHash);
|
||||
std::stack<SHAMapTreeNode::pointer> getStack(const uint256& id, bool include_nonmatching_leaf, bool partialOk);
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
static const uint256 uZero;
|
||||
|
||||
KeyCache<uint256> SHAMap::fullBelowCache("fullBelowCache", 65536, 240);
|
||||
KeyCache <uint256, KeyCacheUptimeTimer> SHAMap::fullBelowCache("fullBelowCache", 65536, 240);
|
||||
|
||||
void SHAMap::getMissingNodes(std::vector<SHAMapNode>& nodeIDs, std::vector<uint256>& hashes, int max,
|
||||
SHAMapSyncFilter* filter)
|
||||
|
||||
Reference in New Issue
Block a user