Use RippleMutex instead of boost::mutex

This commit is contained in:
Vinnie Falco
2013-08-22 21:31:22 -07:00
parent c21a53a3ea
commit f14333012b
79 changed files with 798 additions and 721 deletions

View File

@@ -6,9 +6,16 @@
// These must stay at the top of this file
std::map<int, SField::ptr> SField::codeToField;
boost::mutex SField::mapMutex;
int SField::num = 0;
// Solve construction issues for objects with static storage duration.
SField::StaticLockType& SField::getMutex ()
{
static StaticLockType mutex ("SField", __FILE__, __LINE__);
return mutex;
}
SField sfInvalid (-1), sfGeneric (0);
SField sfLedgerEntry (STI_LEDGERENTRY, 1, "LedgerEntry");
SField sfTransaction (STI_TRANSACTION, 1, "Transaction");
@@ -56,7 +63,7 @@ SField::ref SField::getField (int code)
if ((type <= 0) || (field <= 0))
return sfInvalid;
boost::mutex::scoped_lock sl (mapMutex);
StaticScopedLockType sl (getMutex (), __FILE__, __LINE__);
std::map<int, SField::ptr>::iterator it = codeToField.find (code);
@@ -115,7 +122,7 @@ std::string SField::getName () const
SField::ref SField::getField (const std::string& fieldName)
{
// OPTIMIZEME me with a map. CHECKME this is case sensitive
boost::mutex::scoped_lock sl (mapMutex);
StaticScopedLockType sl (getMutex (), __FILE__, __LINE__);
typedef std::map<int, SField::ptr>::value_type int_sfref_pair;
BOOST_FOREACH (const int_sfref_pair & fieldPair, codeToField)
{
@@ -127,7 +134,7 @@ SField::ref SField::getField (const std::string& fieldName)
SField::~SField ()
{
boost::mutex::scoped_lock sl (mapMutex);
StaticScopedLockType sl (getMutex (), __FILE__, __LINE__);
std::map<int, ptr>::iterator it = codeToField.find (fieldCode);
if ((it != codeToField.end ()) && (it->second == this))

View File

@@ -67,7 +67,7 @@ public:
, fieldMeta (sMD_Default)
, signingField (true)
{
boost::mutex::scoped_lock sl (mapMutex);
StaticScopedLockType sl (getMutex (), __FILE__, __LINE__);
codeToField[fieldCode] = this;
@@ -82,7 +82,7 @@ public:
, fieldMeta (sMD_Default)
, signingField (true)
{
boost::mutex::scoped_lock sl (mapMutex);
StaticScopedLockType sl (getMutex (), __FILE__, __LINE__);
codeToField[fieldCode] = this;
@@ -96,7 +96,7 @@ public:
, fieldMeta (sMD_Never)
, signingField (true)
{
boost::mutex::scoped_lock sl (mapMutex);
StaticScopedLockType sl (getMutex (), __FILE__, __LINE__);
fieldNum = ++num;
}
@@ -196,7 +196,13 @@ public:
// VFALCO TODO make these private
protected:
static std::map<int, ptr> codeToField;
static boost::mutex mapMutex;
typedef RippleMutex StaticLockType;
typedef StaticLockType::ScopedLockType StaticScopedLockType;
static StaticLockType& getMutex ();
// VFALCO NOTE can this be replaced with an atomic int???!
static int num;
SField (SerializedTypeID id, int val);

View File

@@ -288,7 +288,10 @@ uint160 RippleAddress::getAccountID () const
}
}
static boost::mutex rncLock;
typedef RippleMutex StaticLockType;
typedef StaticLockType::ScopedLockType StaticScopedLockType;
static StaticLockType s_lock ("RippleAddress", __FILE__, __LINE__);
static boost::unordered_map< Blob , std::string > rncMap;
std::string RippleAddress::humanAccountID () const
@@ -300,7 +303,7 @@ std::string RippleAddress::humanAccountID () const
case VER_ACCOUNT_ID:
{
boost::mutex::scoped_lock sl (rncLock);
StaticScopedLockType sl (s_lock, __FILE__, __LINE__);
boost::unordered_map< Blob , std::string >::iterator it = rncMap.find (vchData);
if (it != rncMap.end ())