Update copyrights to 2012 for files modified this year
[novacoin.git] / src / util.cpp
index 390b3a3..85ca02f 100644 (file)
@@ -1,5 +1,5 @@
 // Copyright (c) 2009-2010 Satoshi Nakamoto
-// Copyright (c) 2011 The Bitcoin developers
+// Copyright (c) 2009-2012 The Bitcoin developers
 // Distributed under the MIT/X11 software license, see the accompanying
 // file license.txt or http://www.opensource.org/licenses/mit-license.php.
 #include "headers.h"
@@ -389,7 +389,7 @@ bool ParseMoney(const char* pszIn, int64& nRet)
     for (; *p; p++)
         if (!isspace(*p))
             return false;
-    if (strWhole.size() > 14)
+    if (strWhole.size() > 10) // guard against 63 bit overflow
         return false;
     if (nUnits < 0 || nUnits > COIN)
         return false;
@@ -472,6 +472,23 @@ void ParseParameters(int argc, char* argv[])
     }
 }
 
+bool SoftSetArg(const std::string& strArg, const std::string& strValue)
+{
+    if (mapArgs.count(strArg))
+        return false;
+    mapArgs[strArg] = strValue;
+    return true;
+}
+
+bool SoftSetArg(const std::string& strArg, bool fValue)
+{
+    if (fValue)
+        return SoftSetArg(strArg, std::string("1"));
+    else
+        return SoftSetArg(strArg, std::string("0"));
+}
+
+
 
 const char* wxGetTranslation(const char* pszEnglish)
 {
@@ -923,16 +940,22 @@ string FormatFullVersion()
 
 struct CLockLocation
 {
-    std::string mutexName;
-    std::string sourceFile;
-    int sourceLine;
-
     CLockLocation(const char* pszName, const char* pszFile, int nLine)
     {
         mutexName = pszName;
         sourceFile = pszFile;
         sourceLine = nLine;
     }
+
+    std::string ToString() const
+    {
+        return mutexName+"  "+sourceFile+":"+itostr(sourceLine);
+    }
+
+private:
+    std::string mutexName;
+    std::string sourceFile;
+    int sourceLine;
 };
 
 typedef std::vector< std::pair<CCriticalSection*, CLockLocation> > LockStack;
@@ -950,14 +973,14 @@ static void potential_deadlock_detected(const std::pair<CCriticalSection*, CCrit
     {
         if (i.first == mismatch.first) printf(" (1)");
         if (i.first == mismatch.second) printf(" (2)");
-        printf(" %s  %s:%d\n", i.second.mutexName.c_str(), i.second.sourceFile.c_str(), i.second.sourceLine);
+        printf(" %s\n", i.second.ToString().c_str());
     }
     printf("Current lock order is:\n");
     BOOST_FOREACH(const PAIRTYPE(CCriticalSection*, CLockLocation)& i, s1)
     {
         if (i.first == mismatch.first) printf(" (1)");
         if (i.first == mismatch.second) printf(" (2)");
-        printf(" %s  %s:%d\n", i.second.mutexName.c_str(), i.second.sourceFile.c_str(), i.second.sourceLine);
+        printf(" %s\n", i.second.ToString().c_str());
     }
 }
 
@@ -967,6 +990,7 @@ static void push_lock(CCriticalSection* c, const CLockLocation& locklocation)
     if (lockstack.get() == NULL)
         lockstack.reset(new LockStack);
 
+    if (fDebug) printf("Locking: %s\n", locklocation.ToString().c_str());
     dd_mutex.lock();
 
     (*lockstack).push_back(std::make_pair(c, locklocation));
@@ -992,7 +1016,14 @@ static void push_lock(CCriticalSection* c, const CLockLocation& locklocation)
 
 static void pop_lock()
 {
+    if (fDebug) 
+    {
+        const CLockLocation& locklocation = (*lockstack).rbegin()->second;
+        printf("Unlocked: %s\n", locklocation.ToString().c_str());
+    }
+    dd_mutex.lock();
     (*lockstack).pop_back();
+    dd_mutex.unlock();
 }
 
 void CCriticalSection::Enter(const char* pszName, const char* pszFile, int nLine)