From e227637e3444dc3cc34a0565667d61b0d931d927 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Sat, 25 May 2013 12:08:17 -0700 Subject: [PATCH] Factor upTime() out of KeyCache, fix warnings --- .../containers/ripple_KeyCache.h | 26 +++++++++---------- modules/ripple_basics/ripple_basics.h | 9 ++++++- .../ripple_basics/types/ripple_IntegerTypes.h | 0 modules/ripple_db/ripple_db.cpp | 12 --------- modules/ripple_main/ripple_main.cpp | 6 ++--- modules/ripple_net/ripple_net.cpp | 5 ++-- newcoin.vcxproj | 4 +-- newcoin.vcxproj.filters | 12 ++++----- src/cpp/database/SqliteDatabase.cpp | 5 ++-- src/cpp/ripple/HashedObject.h | 16 ++++++++++-- src/cpp/ripple/LedgerAcquire.h | 2 +- src/cpp/ripple/Peer.cpp | 2 +- src/cpp/ripple/SHAMap.cpp | 2 +- src/cpp/ripple/SHAMap.h | 2 +- src/cpp/ripple/SHAMapSync.cpp | 2 +- 15 files changed, 57 insertions(+), 48 deletions(-) rename src/cpp/ripple/KeyCache.h => modules/ripple_basics/containers/ripple_KeyCache.h (83%) rename src/cpp/ripple/IntegerTypes.h => modules/ripple_basics/types/ripple_IntegerTypes.h (100%) diff --git a/src/cpp/ripple/KeyCache.h b/modules/ripple_basics/containers/ripple_KeyCache.h similarity index 83% rename from src/cpp/ripple/KeyCache.h rename to modules/ripple_basics/containers/ripple_KeyCache.h index 13387fb6d2..64137d31c1 100644 --- a/src/cpp/ripple/KeyCache.h +++ b/modules/ripple_basics/containers/ripple_KeyCache.h @@ -1,15 +1,15 @@ -#ifndef KEY_CACHE__H -#define KEY_CACHE__H +#ifndef RIPPLE_KEYCACHE_H +#define RIPPLE_KEYCACHE_H -#include +/** Maintains a cache of keys with no associated data -#include -#include + Timer must have this interface: -extern int upTime(); - -template class KeyCache -{ // Maintains a cache of keys with no associated data + static int Timer::getElapsedSeconds (); +*/ +template +class KeyCache +{ public: typedef c_Key key_type; typedef boost::unordered_map 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; diff --git a/modules/ripple_basics/ripple_basics.h b/modules/ripple_basics/ripple_basics.h index 3713ed0d9f..3a08e2b442 100644 --- a/modules/ripple_basics/ripple_basics.h +++ b/modules/ripple_basics/ripple_basics.h @@ -34,7 +34,14 @@ #include -#include "src/cpp/ripple/IntegerTypes.h" +// KeyCache +#include +#include +#include + +#include "types/ripple_IntegerTypes.h" + +#include "containers/ripple_KeyCache.h" #include "events/ripple_UptimeTimer.h" diff --git a/src/cpp/ripple/IntegerTypes.h b/modules/ripple_basics/types/ripple_IntegerTypes.h similarity index 100% rename from src/cpp/ripple/IntegerTypes.h rename to modules/ripple_basics/types/ripple_IntegerTypes.h diff --git a/modules/ripple_db/ripple_db.cpp b/modules/ripple_db/ripple_db.cpp index 4384a965e6..f0091a8c49 100644 --- a/modules/ripple_db/ripple_db.cpp +++ b/modules/ripple_db/ripple_db.cpp @@ -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 diff --git a/modules/ripple_main/ripple_main.cpp b/modules/ripple_main/ripple_main.cpp index b0c33abb7a..bcf2e2b726 100644 --- a/modules/ripple_main/ripple_main.cpp +++ b/modules/ripple_main/ripple_main.cpp @@ -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 diff --git a/modules/ripple_net/ripple_net.cpp b/modules/ripple_net/ripple_net.cpp index 2b7025b9e8..02b06b62da 100644 --- a/modules/ripple_net/ripple_net.cpp +++ b/modules/ripple_net/ripple_net.cpp @@ -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" diff --git a/newcoin.vcxproj b/newcoin.vcxproj index bfef258fe4..87d38df894 100644 --- a/newcoin.vcxproj +++ b/newcoin.vcxproj @@ -1169,8 +1169,10 @@ + + @@ -1567,7 +1569,6 @@ - @@ -1634,7 +1635,6 @@ - diff --git a/newcoin.vcxproj.filters b/newcoin.vcxproj.filters index c7db7fa28e..7ad2444236 100644 --- a/newcoin.vcxproj.filters +++ b/newcoin.vcxproj.filters @@ -1373,21 +1373,21 @@ 1. Modules\ripple_mess\protobuf - - 1. Modules\ripple_basics\types - 1. Modules\ripple_mess\types 1. Modules\ripple_mess - - 1. Modules\ripple_basics\containers - 1. Modules\ripple_basics\events + + 1. Modules\ripple_basics\containers + + + 1. Modules\ripple_basics\types + diff --git a/src/cpp/database/SqliteDatabase.cpp b/src/cpp/database/SqliteDatabase.cpp index 6edb44ad19..6d4a1f1402 100644 --- a/src/cpp/database/SqliteDatabase.cpp +++ b/src/cpp/database/SqliteDatabase.cpp @@ -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 (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) diff --git a/src/cpp/ripple/HashedObject.h b/src/cpp/ripple/HashedObject.h index f865df0743..18f4e988d4 100644 --- a/src/cpp/ripple/HashedObject.h +++ b/src/cpp/ripple/HashedObject.h @@ -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 mCache; - KeyCache mNegativeCache; + KeyCache mNegativeCache; boost::mutex mWriteMutex; boost::condition_variable mWriteCondition; diff --git a/src/cpp/ripple/LedgerAcquire.h b/src/cpp/ripple/LedgerAcquire.h index 9e38b00629..76f98af5ac 100644 --- a/src/cpp/ripple/LedgerAcquire.h +++ b/src/cpp/ripple/LedgerAcquire.h @@ -146,7 +146,7 @@ class LedgerAcquireMaster protected: boost::mutex mLock; std::map mLedgers; - KeyCache mRecentFailures; + KeyCache mRecentFailures; public: LedgerAcquireMaster() : mRecentFailures("LedgerAcquireRecentFailures", 0, LEDGER_REACQUIRE_INTERVAL) { ; } diff --git a/src/cpp/ripple/Peer.cpp b/src/cpp/ripple/Peer.cpp index 1ce87dfcf3..fbec945252 100644 --- a/src/cpp/ripple/Peer.cpp +++ b/src/cpp/ripple/Peer.cpp @@ -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) diff --git a/src/cpp/ripple/SHAMap.cpp b/src/cpp/ripple/SHAMap.cpp index 42a8f08bee..7fe0498565 100644 --- a/src/cpp/ripple/SHAMap.cpp +++ b/src/cpp/ripple/SHAMap.cpp @@ -778,7 +778,7 @@ void SHAMap::fetchRoot(const uint256& hash, SHAMapSyncFilter* filter) { root = fetchNodeExternal(SHAMapNode(), hash); } - catch (SHAMapMissingNode& mn) + catch (SHAMapMissingNode&) { std::vector nodeData; if (!filter || !filter->haveNode(SHAMapNode(), hash, nodeData)) diff --git a/src/cpp/ripple/SHAMap.h b/src/cpp/ripple/SHAMap.h index 9d38d780e9..774971019c 100644 --- a/src/cpp/ripple/SHAMap.h +++ b/src/cpp/ripple/SHAMap.h @@ -356,7 +356,7 @@ protected: SHAMapType mType; - static KeyCache fullBelowCache; + static KeyCache fullBelowCache; void dirtyUp(std::stack& stack, const uint256& target, uint256 prevHash); std::stack getStack(const uint256& id, bool include_nonmatching_leaf, bool partialOk); diff --git a/src/cpp/ripple/SHAMapSync.cpp b/src/cpp/ripple/SHAMapSync.cpp index 4f985c7152..91a4efdbd5 100644 --- a/src/cpp/ripple/SHAMapSync.cpp +++ b/src/cpp/ripple/SHAMapSync.cpp @@ -13,7 +13,7 @@ static const uint256 uZero; -KeyCache SHAMap::fullBelowCache("fullBelowCache", 65536, 240); +KeyCache SHAMap::fullBelowCache("fullBelowCache", 65536, 240); void SHAMap::getMissingNodes(std::vector& nodeIDs, std::vector& hashes, int max, SHAMapSyncFilter* filter)