Permalink
Browse files

Change Sleep to MilliSleep

  • Loading branch information...
Tranz5 committed Jul 13, 2014
1 parent aa886c6 commit b174a32d15b62c82caa64e2ac4a2cea77e971be3
Showing with 51 additions and 48 deletions.
  1. +1 −1 src/bitcoinrpc.cpp
  2. +1 −1 src/db.cpp
  3. +5 −5 src/init.cpp
  4. +2 −2 src/irc.cpp
  5. +6 −6 src/miner.cpp
  6. +17 −17 src/net.cpp
  7. +1 −1 src/qt/qtipcserver.cpp
  8. +2 −2 src/qt/walletmodel.cpp
  9. +1 −1 src/rpcwallet.cpp
  10. +8 −5 src/util.h
  11. +4 −4 src/wallet.cpp
  12. +3 −3 src/walletdb.cpp
@@ -988,7 +988,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;
@@ -454,7 +454,7 @@ bool CDB::Rewrite(const string& strFile, const char* pszSkip)
return fSuccess;
}
}
Sleep(100);
MilliSleep(100);
}
return false;
}
@@ -44,7 +44,7 @@ CClientUIInterface uiInterface;
void ExitTimeout(void* parg)
{
#ifdef WIN32
Sleep(5000);
MilliSleep(5000);
ExitProcess(0);
#endif
}
@@ -90,7 +90,7 @@ void Shutdown(void* parg)
delete pWalletManager;
TimerThread::StopTimer(); // for walletpassphrase unlock
NewThread(ExitTimeout, NULL);
Sleep(50);
MilliSleep(50);
printf("HoboNickels exited\n\n");
fExit = true;
#ifndef QT_GUI
@@ -101,8 +101,8 @@ void Shutdown(void* parg)
else
{
while (!fExit)
Sleep(500);
Sleep(100);
MilliSleep(500);
MilliSleep(100);
ExitThread(0);
}
}
@@ -929,7 +929,7 @@ bool AppInit2()
// 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;
@@ -127,7 +127,7 @@ bool Wait(int nSeconds)
{
if (fShutdown)
return false;
Sleep(1000);
MilliSleep(1000);
}
return true;
}
@@ -284,7 +284,7 @@ void ThreadIRCSeed2(void* parg)
return;
}
nNameRetry = 0;
Sleep(500);
MilliSleep(500);
// Get our external IP from the IRC server and re-nick before joining the channel
CNetAddr addrFromIRC;
@@ -544,15 +544,15 @@ void BitcoinMiner(CWallet *pwallet)
return;
while (vNodes.empty() || IsInitialBlockDownload())
{
Sleep(1000);
MilliSleep(1000);
if (fShutdown)
return;
if (!fGenerateBitcoins)
return;
}
while (pwallet->IsLocked())
Sleep(1000);
MilliSleep(1000);
//
// Create new block
@@ -731,7 +731,7 @@ void GenerateBitcoins(bool fGenerate, CWallet* pwallet)
{
if (!NewThread(ThreadBitcoinMiner, pwallet))
printf("Error: NewThread(ThreadBitcoinMiner) failed\n");
Sleep(10);
MilliSleep(10);
}
}
}
@@ -754,14 +754,14 @@ void StakeMiner(CWallet *pwallet)
while (pwallet->IsLocked())
{
strMintWarning = strMintMessage;
Sleep(1000);
MilliSleep(1000);
if (fShutdown)
return;
}
while (vNodes.empty() || IsInitialBlockDownload())
{
Sleep(1000);
MilliSleep(1000);
if (fShutdown)
return;
}
@@ -786,7 +786,7 @@ void StakeMiner(CWallet *pwallet)
SetThreadPriority(THREAD_PRIORITY_LOWEST);
}
Sleep(500);
MilliSleep(500);
continue;
}
}
@@ -168,7 +168,7 @@ bool RecvLine(SOCKET hSocket, string& strLine)
continue;
if (nErr == WSAEWOULDBLOCK || nErr == WSAEINTR || nErr == WSAEINPROGRESS)
{
Sleep(10);
MilliSleep(10);
continue;
}
}
@@ -791,7 +791,7 @@ void ThreadSocketHandler2(void* parg)
}
FD_ZERO(&fdsetSend);
FD_ZERO(&fdsetError);
Sleep(timeout.tv_usec/1000);
MilliSleep(timeout.tv_usec/1000);
}
@@ -985,7 +985,7 @@ void ThreadSocketHandler2(void* parg)
pnode->Release();
}
Sleep(10);
MilliSleep(10);
}
}
@@ -1106,7 +1106,7 @@ void ThreadMapPort2(void* parg)
else
printf("UPnP Port Mapping successful.\n");;
}
Sleep(2000);
MilliSleep(2000);
i++;
}
} else {
@@ -1117,7 +1117,7 @@ void ThreadMapPort2(void* parg)
while (true) {
if (fShutdown || !fUseUPnP)
return;
Sleep(2000);
MilliSleep(2000);
}
}
}
@@ -1240,7 +1240,7 @@ void ThreadDumpAddress2(void* parg)
{
DumpAddresses();
vnThreadsRunning[THREAD_DUMPADDRESS]--;
Sleep(600000);
MilliSleep(600000);
vnThreadsRunning[THREAD_DUMPADDRESS]++;
}
vnThreadsRunning[THREAD_DUMPADDRESS]--;
@@ -1336,12 +1336,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);
}
}
@@ -1352,7 +1352,7 @@ void ThreadOpenConnections2(void* parg)
ProcessOneShot();
vnThreadsRunning[THREAD_OPENCONNECTIONS]--;
Sleep(500);
MilliSleep(500);
vnThreadsRunning[THREAD_OPENCONNECTIONS]++;
if (fShutdown)
return;
@@ -1482,10 +1482,10 @@ void ThreadOpenAddedConnections2(void* parg)
CAddress addr;
CSemaphoreGrant grant(*semOutbound);
OpenNetworkConnection(addr, &grant, strAddNode.c_str());
Sleep(500);
MilliSleep(500);
}
vnThreadsRunning[THREAD_ADDEDCONNECTIONS]--;
Sleep(120000); // Retry every 2 minutes
MilliSleep(120000); // Retry every 2 minutes
vnThreadsRunning[THREAD_ADDEDCONNECTIONS]++;
}
@@ -1532,10 +1532,10 @@ void ThreadOpenAddedConnections2(void* parg)
{
CSemaphoreGrant grant(*semOutbound);
OpenNetworkConnection(CAddress(vserv[i % vserv.size()]), &grant);
Sleep(500);
MilliSleep(500);
}
vnThreadsRunning[THREAD_ADDEDCONNECTIONS]--;
Sleep(120000); // Retry every 2 minutes
MilliSleep(120000); // Retry every 2 minutes
vnThreadsRunning[THREAD_ADDEDCONNECTIONS]++;
}
}
@@ -1650,7 +1650,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]++;
@@ -1914,7 +1914,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");
@@ -1930,8 +1930,8 @@ bool StopNode()
if (vnThreadsRunning[THREAD_DUMPADDRESS] > 0) printf("ThreadDumpAddresses still running\n");
if (vnThreadsRunning[THREAD_MINTER] > 0) printf("ThreadStakeMinter still running\n");
while (vnThreadsRunning[THREAD_MESSAGEHANDLER] > 0 || vnThreadsRunning[THREAD_RPCHANDLER] > 0)
Sleep(20);
Sleep(50);
MilliSleep(20);
MilliSleep(50);
DumpAddresses();
return true;
}
@@ -108,7 +108,7 @@ static void ipcThread2(void* pArg)
if (mq->timed_receive(&buffer, sizeof(buffer), nSize, nPriority, d))
{
uiInterface.ThreadSafeHandleURI(std::string(buffer, nSize));
Sleep(1000);
MilliSleep(1000);
}
if (fShutdown)
@@ -317,7 +317,7 @@ bool WalletModel::setWalletLocked(bool locked, const SecureString &passPhrase, b
// Lock as Requested by user
rc = wallet->Lock();
fStopStaking=true;
Sleep(1000);
MilliSleep(1000);
pWalletManager->RestartStakeMiner();
return rc;
}
@@ -496,7 +496,7 @@ WalletModel::UnlockContext WalletModel::requestUnlock()
if( (!valid) && wallet->fWalletUnlockMintOnly)
{
fStopStaking=true;
Sleep(1000);
MilliSleep(1000);
pWalletManager->RestartStakeMiner();
}
@@ -1575,7 +1575,7 @@ Value walletlock(CWallet* pWallet, const Array& params, bool fHelp)
{
printf ("Halting Stake Mining while we lock wallet(s)\n");
fStopStaking = true;
Sleep(1000);
MilliSleep(1000);
}
pWallet->Lock();
@@ -114,13 +114,16 @@ T* alignup(T* p)
#endif
#else
#define MAX_PATH 1024
inline void Sleep(int64 n)
#endif
inline void MilliSleep(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));
}
#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.
@@ -2537,7 +2537,7 @@ void CWalletLockJob::Run()
{
printf ("Halting Stake Mining while we lock wallet(s)\n");
fStopStaking = true;
Sleep(1000);
MilliSleep(1000);
}
pWalletManager->RestartStakeMiner();
@@ -3026,13 +3026,13 @@ void CWalletManager::RestartStakeMiner()
if (!fShutdown)
{
fStopStaking = true;
Sleep(1000);
MilliSleep(1000);
}
//Re-Start Stake for the remaining wallets
if (!fShutdown)
{
fStopStaking = false;
Sleep(1000);
MilliSleep(1000);
vector<string> vstrNames;
vector<boost::shared_ptr<CWallet> > vpWallets;
@@ -3098,7 +3098,7 @@ bool CWalletManager::UnloadWallet(const std::string& strName)
{
printf ("Halting Stake Mining while we unload wallet(s)\n");
fStopStaking = true;
Sleep(1000);
MilliSleep(1000);
}
boost::shared_ptr<CWallet> spWallet(wallets[strName]);
printf("Unloading wallet %s\n", strName.c_str());
@@ -552,7 +552,7 @@ void CWalletDB::UnloadWallet(CWallet* pwallet)
return;
}
}
Sleep(100);
MilliSleep(100);
}
}
@@ -654,7 +654,7 @@ void ThreadFlushWalletDB(void* parg)
int64 nLastWalletUpdate = GetTime();
while (!fShutdown)
{
Sleep(500);
MilliSleep(500);
if (nLastSeen != nWalletDBUpdated)
{
@@ -743,7 +743,7 @@ bool BackupWallet(const CWallet& wallet, const string& strDest, bool fMulti)
}
}
}
Sleep(100);
MilliSleep(100);
}
return false;
}

0 comments on commit b174a32

Please sign in to comment.