mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 12:32:48 +01:00
Rename util.h Sleep --> MilliSleep
Two reasons for this change: 1. Need to always use boost::thread's sleep, even on Windows, so the sleeps can be interrupted (prior code used Windows' built-in Sleep). 2. I always forgot what units the old Sleep took.
This commit is contained in:
parent
c8c2fbe07f
commit
1b43bf0d3a
@ -1003,7 +1003,7 @@ void ThreadRPCServer3(void* parg)
|
||||
If this results in a DOS the user really
|
||||
shouldn't have their RPC port exposed.*/
|
||||
if (mapArgs["-rpcpassword"].size() < 20)
|
||||
Sleep(250);
|
||||
MilliSleep(250);
|
||||
|
||||
conn->stream() << HTTPReply(HTTP_UNAUTHORIZED, "", false) << std::flush;
|
||||
break;
|
||||
|
@ -413,7 +413,7 @@ bool CDB::Rewrite(const string& strFile, const char* pszSkip)
|
||||
return fSuccess;
|
||||
}
|
||||
}
|
||||
Sleep(100);
|
||||
MilliSleep(100);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
10
src/init.cpp
10
src/init.cpp
@ -43,7 +43,7 @@ enum BindFlags {
|
||||
void ExitTimeout(void* parg)
|
||||
{
|
||||
#ifdef WIN32
|
||||
Sleep(5000);
|
||||
MilliSleep(5000);
|
||||
ExitProcess(0);
|
||||
#endif
|
||||
}
|
||||
@ -105,7 +105,7 @@ void Shutdown(void* parg)
|
||||
UnregisterWallet(pwalletMain);
|
||||
delete pwalletMain;
|
||||
NewThread(ExitTimeout, NULL);
|
||||
Sleep(50);
|
||||
MilliSleep(50);
|
||||
printf("Bitcoin exited\n\n");
|
||||
fExit = true;
|
||||
#ifndef QT_GUI
|
||||
@ -116,8 +116,8 @@ void Shutdown(void* parg)
|
||||
else
|
||||
{
|
||||
while (!fExit)
|
||||
Sleep(500);
|
||||
Sleep(100);
|
||||
MilliSleep(500);
|
||||
MilliSleep(100);
|
||||
ExitThread(0);
|
||||
}
|
||||
}
|
||||
@ -1061,7 +1061,7 @@ bool AppInit2(boost::thread_group& threadGroup)
|
||||
// Loop until process is exit()ed from shutdown() function,
|
||||
// called from ThreadRPCServer thread when a "stop" command is received.
|
||||
while (1)
|
||||
Sleep(5000);
|
||||
MilliSleep(5000);
|
||||
#endif
|
||||
|
||||
return true;
|
||||
|
@ -4520,7 +4520,7 @@ void static BitcoinMiner(CWallet *pwallet)
|
||||
|
||||
try { loop {
|
||||
while (vNodes.empty())
|
||||
Sleep(1000);
|
||||
MilliSleep(1000);
|
||||
|
||||
//
|
||||
// Create new block
|
||||
|
34
src/net.cpp
34
src/net.cpp
@ -165,7 +165,7 @@ bool RecvLine(SOCKET hSocket, string& strLine)
|
||||
continue;
|
||||
if (nErr == WSAEWOULDBLOCK || nErr == WSAEINTR || nErr == WSAEINPROGRESS)
|
||||
{
|
||||
Sleep(10);
|
||||
MilliSleep(10);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@ -909,7 +909,7 @@ void ThreadSocketHandler2(void* parg)
|
||||
}
|
||||
FD_ZERO(&fdsetSend);
|
||||
FD_ZERO(&fdsetError);
|
||||
Sleep(timeout.tv_usec/1000);
|
||||
MilliSleep(timeout.tv_usec/1000);
|
||||
}
|
||||
|
||||
|
||||
@ -1076,7 +1076,7 @@ void ThreadSocketHandler2(void* parg)
|
||||
pnode->Release();
|
||||
}
|
||||
|
||||
Sleep(10);
|
||||
MilliSleep(10);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1197,7 +1197,7 @@ void ThreadMapPort2(void* parg)
|
||||
else
|
||||
printf("UPnP Port Mapping successful.\n");;
|
||||
}
|
||||
Sleep(2000);
|
||||
MilliSleep(2000);
|
||||
i++;
|
||||
}
|
||||
} else {
|
||||
@ -1208,7 +1208,7 @@ void ThreadMapPort2(void* parg)
|
||||
loop {
|
||||
if (fShutdown || !fUseUPnP)
|
||||
return;
|
||||
Sleep(2000);
|
||||
MilliSleep(2000);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1418,7 +1418,7 @@ void ThreadDumpAddress2(void* parg)
|
||||
{
|
||||
DumpAddresses();
|
||||
vnThreadsRunning[THREAD_DUMPADDRESS]--;
|
||||
Sleep(100000);
|
||||
MilliSleep(100000);
|
||||
vnThreadsRunning[THREAD_DUMPADDRESS]++;
|
||||
}
|
||||
vnThreadsRunning[THREAD_DUMPADDRESS]--;
|
||||
@ -1494,12 +1494,12 @@ void ThreadOpenConnections2(void* parg)
|
||||
OpenNetworkConnection(addr, NULL, strAddr.c_str());
|
||||
for (int i = 0; i < 10 && i < nLoop; i++)
|
||||
{
|
||||
Sleep(500);
|
||||
MilliSleep(500);
|
||||
if (fShutdown)
|
||||
return;
|
||||
}
|
||||
}
|
||||
Sleep(500);
|
||||
MilliSleep(500);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1510,7 +1510,7 @@ void ThreadOpenConnections2(void* parg)
|
||||
ProcessOneShot();
|
||||
|
||||
vnThreadsRunning[THREAD_OPENCONNECTIONS]--;
|
||||
Sleep(500);
|
||||
MilliSleep(500);
|
||||
vnThreadsRunning[THREAD_OPENCONNECTIONS]++;
|
||||
if (fShutdown)
|
||||
return;
|
||||
@ -1642,12 +1642,12 @@ void ThreadOpenAddedConnections2(void* parg)
|
||||
CAddress addr;
|
||||
CSemaphoreGrant grant(*semOutbound);
|
||||
OpenNetworkConnection(addr, &grant, strAddNode.c_str());
|
||||
Sleep(500);
|
||||
MilliSleep(500);
|
||||
if (fShutdown)
|
||||
return;
|
||||
}
|
||||
vnThreadsRunning[THREAD_ADDEDCONNECTIONS]--;
|
||||
Sleep(120000); // Retry every 2 minutes
|
||||
MilliSleep(120000); // Retry every 2 minutes
|
||||
vnThreadsRunning[THREAD_ADDEDCONNECTIONS]++;
|
||||
}
|
||||
return;
|
||||
@ -1694,14 +1694,14 @@ void ThreadOpenAddedConnections2(void* parg)
|
||||
{
|
||||
CSemaphoreGrant grant(*semOutbound);
|
||||
OpenNetworkConnection(CAddress(vserv[i % vserv.size()]), &grant);
|
||||
Sleep(500);
|
||||
MilliSleep(500);
|
||||
if (fShutdown)
|
||||
return;
|
||||
}
|
||||
if (fShutdown)
|
||||
return;
|
||||
vnThreadsRunning[THREAD_ADDEDCONNECTIONS]--;
|
||||
Sleep(120000); // Retry every 2 minutes
|
||||
MilliSleep(120000); // Retry every 2 minutes
|
||||
vnThreadsRunning[THREAD_ADDEDCONNECTIONS]++;
|
||||
if (fShutdown)
|
||||
return;
|
||||
@ -1821,7 +1821,7 @@ void ThreadMessageHandler2(void* parg)
|
||||
// Reduce vnThreadsRunning so StopNode has permission to exit while
|
||||
// we're sleeping, but we must always check fShutdown after doing this.
|
||||
vnThreadsRunning[THREAD_MESSAGEHANDLER]--;
|
||||
Sleep(100);
|
||||
MilliSleep(100);
|
||||
if (fRequestShutdown)
|
||||
StartShutdown();
|
||||
vnThreadsRunning[THREAD_MESSAGEHANDLER]++;
|
||||
@ -2068,7 +2068,7 @@ bool StopNode()
|
||||
break;
|
||||
if (GetTime() - nStart > 20)
|
||||
break;
|
||||
Sleep(20);
|
||||
MilliSleep(20);
|
||||
} while(true);
|
||||
if (vnThreadsRunning[THREAD_SOCKETHANDLER] > 0) printf("ThreadSocketHandler still running\n");
|
||||
if (vnThreadsRunning[THREAD_OPENCONNECTIONS] > 0) printf("ThreadOpenConnections still running\n");
|
||||
@ -2082,8 +2082,8 @@ bool StopNode()
|
||||
if (vnThreadsRunning[THREAD_ADDEDCONNECTIONS] > 0) printf("ThreadOpenAddedConnections still running\n");
|
||||
if (vnThreadsRunning[THREAD_DUMPADDRESS] > 0) printf("ThreadDumpAddresses still running\n");
|
||||
while (vnThreadsRunning[THREAD_MESSAGEHANDLER] > 0 || vnThreadsRunning[THREAD_RPCHANDLER] > 0)
|
||||
Sleep(20);
|
||||
Sleep(50);
|
||||
MilliSleep(20);
|
||||
MilliSleep(50);
|
||||
DumpAddresses();
|
||||
|
||||
return true;
|
||||
|
@ -1289,7 +1289,7 @@ void ThreadCleanWalletPassphrase(void* parg)
|
||||
break;
|
||||
|
||||
LEAVE_CRITICAL_SECTION(cs_nWalletUnlockTime);
|
||||
Sleep(nToSleep);
|
||||
MilliSleep(nToSleep);
|
||||
ENTER_CRITICAL_SECTION(cs_nWalletUnlockTime);
|
||||
|
||||
} while(1);
|
||||
|
15
src/util.h
15
src/util.h
@ -100,14 +100,17 @@ T* alignup(T* p)
|
||||
#endif
|
||||
#else
|
||||
#define MAX_PATH 1024
|
||||
inline void Sleep(int64 n)
|
||||
{
|
||||
/*Boost has a year 2038 problem— if the request sleep time is past epoch+2^31 seconds the sleep returns instantly.
|
||||
So we clamp our sleeps here to 10 years and hope that boost is fixed by 2028.*/
|
||||
boost::thread::sleep(boost::get_system_time() + boost::posix_time::milliseconds(n>315576000000LL?315576000000LL:n));
|
||||
}
|
||||
#endif
|
||||
|
||||
inline void MilliSleep(int64 n)
|
||||
{
|
||||
#if BOOST_VERSION >= 105000
|
||||
boost::this_thread::sleep_for(boost::chrono::milliseconds(n));
|
||||
#else
|
||||
boost::this_thread::sleep(boost::posix_time::milliseconds(n));
|
||||
#endif
|
||||
}
|
||||
|
||||
/* This GNU C extension enables the compiler to check the format string against the parameters provided.
|
||||
* X is the number of the "format string" parameter, and Y is the number of the first variadic parameter.
|
||||
* Parameters count from 1.
|
||||
|
@ -500,7 +500,7 @@ void ThreadFlushWalletDB(void* parg)
|
||||
int64 nLastWalletUpdate = GetTime();
|
||||
while (!fShutdown)
|
||||
{
|
||||
Sleep(500);
|
||||
MilliSleep(500);
|
||||
|
||||
if (nLastSeen != nWalletDBUpdated)
|
||||
{
|
||||
@ -579,7 +579,7 @@ bool BackupWallet(const CWallet& wallet, const string& strDest)
|
||||
}
|
||||
}
|
||||
}
|
||||
Sleep(100);
|
||||
MilliSleep(100);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user