0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-09 10:43:19 -05:00

scripted-diff: Replace MilliSleep with UninterruptibleSleep

This is safe because MilliSleep is never executed in a boost::thread,
the only type of thread that is interruptible.

* The RPC server uses std::thread
* The wallet is either executed in an RPC thread or the main thread
* bitcoin-cli, benchmarks and tests are only one thread (the main thread)

-BEGIN VERIFY SCRIPT-
sed -i --regexp-extended -e 's/MilliSleep\((\S+)\);/UninterruptibleSleep(std::chrono::milliseconds{\1});/g' $(git grep -l MilliSleep)
-END VERIFY SCRIPT-
This commit is contained in:
MarcoFalke 2020-02-21 09:20:51 -08:00
parent fa4620be78
commit fa9af06d91
No known key found for this signature in database
GPG key ID: CE2B75697E69A548
11 changed files with 13 additions and 13 deletions

View file

@ -10,7 +10,7 @@
static void Sleep100ms(benchmark::State& state) static void Sleep100ms(benchmark::State& state)
{ {
while (state.KeepRunning()) { while (state.KeepRunning()) {
MilliSleep(100); UninterruptibleSleep(std::chrono::milliseconds{100});
} }
} }

View file

@ -524,7 +524,7 @@ static int CommandLineRPC(int argc, char *argv[])
} }
catch (const CConnectionFailed&) { catch (const CConnectionFailed&) {
if (fWait) if (fWait)
MilliSleep(1000); UninterruptibleSleep(std::chrono::milliseconds{1000});
else else
throw; throw;
} }

View file

@ -29,7 +29,7 @@ static void WaitForShutdown(NodeContext& node)
{ {
while (!ShutdownRequested()) while (!ShutdownRequested())
{ {
MilliSleep(200); UninterruptibleSleep(std::chrono::milliseconds{200});
} }
Interrupt(node); Interrupt(node);
} }

View file

@ -174,7 +174,7 @@ static bool HTTPReq_JSONRPC(HTTPRequest* req, const std::string &)
/* Deter brute-forcing /* Deter brute-forcing
If this results in a DoS the user really If this results in a DoS the user really
shouldn't have their RPC port exposed. */ shouldn't have their RPC port exposed. */
MilliSleep(250); UninterruptibleSleep(std::chrono::milliseconds{250});
req->WriteHeader("WWW-Authenticate", WWW_AUTH_HEADER_DATA); req->WriteHeader("WWW-Authenticate", WWW_AUTH_HEADER_DATA);
req->WriteReply(HTTP_UNAUTHORIZED); req->WriteReply(HTTP_UNAUTHORIZED);

View file

@ -169,7 +169,7 @@ UniValue stop(const JSONRPCRequest& jsonRequest)
// this reply will get back to the client. // this reply will get back to the client.
StartShutdown(); StartShutdown();
if (jsonRequest.params[0].isNum()) { if (jsonRequest.params[0].isNum()) {
MilliSleep(jsonRequest.params[0].get_int()); UninterruptibleSleep(std::chrono::milliseconds{jsonRequest.params[0].get_int()});
} }
return PACKAGE_NAME " stopping"; return PACKAGE_NAME " stopping";
} }

View file

@ -138,7 +138,7 @@ BOOST_FIXTURE_TEST_CASE(blockfilter_index_initial_sync, BuildChainTestingSetup)
int64_t time_start = GetTimeMillis(); int64_t time_start = GetTimeMillis();
while (!filter_index.BlockUntilSyncedToCurrentChain()) { while (!filter_index.BlockUntilSyncedToCurrentChain()) {
BOOST_REQUIRE(time_start + timeout_ms > GetTimeMillis()); BOOST_REQUIRE(time_start + timeout_ms > GetTimeMillis());
MilliSleep(100); UninterruptibleSleep(std::chrono::milliseconds{100});
} }
// Check that filter index has all blocks that were in the chain before it started. // Check that filter index has all blocks that were in the chain before it started.

View file

@ -393,7 +393,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueueControl_Locks)
CCheckQueueControl<FakeCheck> control(queue.get()); CCheckQueueControl<FakeCheck> control(queue.get());
// While sleeping, no other thread should execute to this point // While sleeping, no other thread should execute to this point
auto observed = ++nThreads; auto observed = ++nThreads;
MilliSleep(10); UninterruptibleSleep(std::chrono::milliseconds{10});
fails += observed != nThreads; fails += observed != nThreads;
}); });
} }

View file

@ -34,7 +34,7 @@ BOOST_FIXTURE_TEST_CASE(txindex_initial_sync, TestChain100Setup)
int64_t time_start = GetTimeMillis(); int64_t time_start = GetTimeMillis();
while (!txindex.BlockUntilSyncedToCurrentChain()) { while (!txindex.BlockUntilSyncedToCurrentChain()) {
BOOST_REQUIRE(time_start + timeout_ms > GetTimeMillis()); BOOST_REQUIRE(time_start + timeout_ms > GetTimeMillis());
MilliSleep(100); UninterruptibleSleep(std::chrono::milliseconds{100});
} }
// Check that txindex excludes genesis block transactions. // Check that txindex excludes genesis block transactions.

View file

@ -1322,7 +1322,7 @@ BOOST_AUTO_TEST_CASE(util_time_GetTime)
SetMockTime(111); SetMockTime(111);
// Check that mock time does not change after a sleep // Check that mock time does not change after a sleep
for (const auto& num_sleep : {0, 1}) { for (const auto& num_sleep : {0, 1}) {
MilliSleep(num_sleep); UninterruptibleSleep(std::chrono::milliseconds{num_sleep});
BOOST_CHECK_EQUAL(111, GetTime()); // Deprecated time getter BOOST_CHECK_EQUAL(111, GetTime()); // Deprecated time getter
BOOST_CHECK_EQUAL(111, GetTime<std::chrono::seconds>().count()); BOOST_CHECK_EQUAL(111, GetTime<std::chrono::seconds>().count());
BOOST_CHECK_EQUAL(111000, GetTime<std::chrono::milliseconds>().count()); BOOST_CHECK_EQUAL(111000, GetTime<std::chrono::milliseconds>().count());
@ -1333,7 +1333,7 @@ BOOST_AUTO_TEST_CASE(util_time_GetTime)
// Check that system time changes after a sleep // Check that system time changes after a sleep
const auto ms_0 = GetTime<std::chrono::milliseconds>(); const auto ms_0 = GetTime<std::chrono::milliseconds>();
const auto us_0 = GetTime<std::chrono::microseconds>(); const auto us_0 = GetTime<std::chrono::microseconds>();
MilliSleep(1); UninterruptibleSleep(std::chrono::milliseconds{1});
BOOST_CHECK(ms_0 < GetTime<std::chrono::milliseconds>()); BOOST_CHECK(ms_0 < GetTime<std::chrono::milliseconds>());
BOOST_CHECK(us_0 < GetTime<std::chrono::microseconds>()); BOOST_CHECK(us_0 < GetTime<std::chrono::microseconds>());
} }

View file

@ -205,7 +205,7 @@ BOOST_AUTO_TEST_CASE(processnewblock_signals_ordering)
t.join(); t.join();
} }
while (GetMainSignals().CallbacksPending() > 0) { while (GetMainSignals().CallbacksPending() > 0) {
MilliSleep(100); UninterruptibleSleep(std::chrono::milliseconds{100});
} }
UnregisterValidationInterface(&sub); UnregisterValidationInterface(&sub);

View file

@ -756,7 +756,7 @@ bool BerkeleyBatch::Rewrite(BerkeleyDatabase& database, const char* pszSkip)
return fSuccess; return fSuccess;
} }
} }
MilliSleep(100); UninterruptibleSleep(std::chrono::milliseconds{100});
} }
} }
@ -887,7 +887,7 @@ bool BerkeleyDatabase::Backup(const std::string& strDest)
} }
} }
} }
MilliSleep(100); UninterruptibleSleep(std::chrono::milliseconds{100});
} }
} }