Merge branch '0.5.0.x' into 0.5.x
authorLuke Dashjr <luke-jr+git@utopios.org>
Fri, 17 Feb 2012 14:40:00 +0000 (09:40 -0500)
committerLuke Dashjr <luke-jr+git@utopios.org>
Fri, 17 Feb 2012 14:40:00 +0000 (09:40 -0500)
src/bitcoinrpc.cpp
src/net.h
src/util.h

index 506e194..57abe8e 100644 (file)
@@ -1409,33 +1409,31 @@ void ThreadCleanWalletPassphrase(void* parg)
 {
     int64 nMyWakeTime = GetTime() + *((int*)parg);
 
+    ENTER_CRITICAL_SECTION(cs_nWalletUnlockTime);
+
     if (nWalletUnlockTime == 0)
     {
-        CRITICAL_BLOCK(cs_nWalletUnlockTime)
-        {
-            nWalletUnlockTime = nMyWakeTime;
-        }
+        nWalletUnlockTime = nMyWakeTime;
 
         while (GetTime() < nWalletUnlockTime)
-            Sleep(GetTime() - nWalletUnlockTime);
-
-        CRITICAL_BLOCK(cs_nWalletUnlockTime)
         {
-            nWalletUnlockTime = 0;
+            int64 nToSleep = GetTime() - nWalletUnlockTime;
+
+            LEAVE_CRITICAL_SECTION(cs_nWalletUnlockTime);
+            Sleep(nToSleep);
+            ENTER_CRITICAL_SECTION(cs_nWalletUnlockTime);
         }
+
+        nWalletUnlockTime = 0;
+        pwalletMain->Lock();
     }
     else
     {
-        CRITICAL_BLOCK(cs_nWalletUnlockTime)
-        {
-            if (nWalletUnlockTime < nMyWakeTime)
-                nWalletUnlockTime = nMyWakeTime;
-        }
-        delete (int*)parg;
-        return;
+        if (nWalletUnlockTime < nMyWakeTime)
+            nWalletUnlockTime = nMyWakeTime;
     }
 
-    pwalletMain->Lock();
+    LEAVE_CRITICAL_SECTION(cs_nWalletUnlockTime);
 
     delete (int*)parg;
 }
index 4eadeaa..55f4d74 100644 (file)
--- a/src/net.h
+++ b/src/net.h
@@ -284,7 +284,7 @@ public:
 
     void BeginMessage(const char* pszCommand)
     {
-        cs_vSend.Enter("cs_vSend", __FILE__, __LINE__);
+        ENTER_CRITICAL_SECTION(cs_vSend);
         if (nHeaderStart != -1)
             AbortMessage();
         nHeaderStart = vSend.size();
@@ -303,7 +303,7 @@ public:
         vSend.resize(nHeaderStart);
         nHeaderStart = -1;
         nMessageStart = -1;
-        cs_vSend.Leave();
+        LEAVE_CRITICAL_SECTION(cs_vSend);
 
         if (fDebug)
             printf("(aborted)\n");
@@ -341,7 +341,7 @@ public:
 
         nHeaderStart = -1;
         nMessageStart = -1;
-        cs_vSend.Leave();
+        LEAVE_CRITICAL_SECTION(cs_vSend);
     }
 
     void EndMessageAbortIfEmpty()
index df09310..15a45ba 100644 (file)
@@ -258,6 +258,12 @@ public:
 #define CRITICAL_BLOCK(cs)     \
     if (CCriticalBlock criticalblock = CCriticalBlock(cs, #cs, __FILE__, __LINE__))
 
+#define ENTER_CRITICAL_SECTION(cs) \
+    (cs).Enter(#cs, __FILE__, __LINE__)
+
+#define LEAVE_CRITICAL_SECTION(cs) \
+    (cs).Leave()
+
 class CTryCriticalBlock
 {
 protected: