Skip to content

Commit 97aadf9

Browse files
committed
Merge #16117: util: Replace boost sleep with std sleep
fae86c3 util: Remove unused MilliSleep (MarcoFalke) fa9af06 scripted-diff: Replace MilliSleep with UninterruptibleSleep (MarcoFalke) fa4620b util: Add UnintrruptibleSleep (MarcoFalke) Pull request description: We don't use the interruptible feature of boost's sleep anywhere, so replace it with the sleep in `std::thread` ACKs for top commit: ajtowns: ACK fae86c3 quick code review practicalswift: ACK fae86c3 -- patch looks correct sipa: Concept and code review ACK fae86c3 fanquake: ACK fae86c3 - note that an instance of `DHAVE_WORKING_BOOST_SLEEP_FOR` was missed in the [linter](https://github.com/bitcoin/bitcoin/blob/master/test/lint/extended-lint-cppcheck.sh#L69), but that can be cleaned up later. Tree-SHA512: 7c0f8eb197664b9f7d9fe6c472c77d384f11c797c913afc31de4b532e3b4fd9ea6dd174f92062ff9d1ec39b25e0900ca7c597435add87f0f2477d9557204848c
2 parents 3f82659 + fae86c3 commit 97aadf9

16 files changed

+21
-104
lines changed

build_msvc/bitcoin_config.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,6 @@
258258
/* Define if the visibility attribute is supported. */
259259
#define HAVE_VISIBILITY_ATTRIBUTE 1
260260

261-
/* Define this symbol if boost sleep works */
262-
/* #undef HAVE_WORKING_BOOST_SLEEP */
263-
264-
/* Define this symbol if boost sleep_for works */
265-
#define HAVE_WORKING_BOOST_SLEEP_FOR 1
266-
267261
/* Define to the sub-directory where libtool stores uninstalled libraries. */
268262
#define LT_OBJDIR ".libs/"
269263

configure.ac

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,57 +1244,6 @@ AC_LINK_IFELSE([AC_LANG_PROGRAM([[
12441244
LIBS="$TEMP_LIBS"
12451245
CPPFLAGS="$TEMP_CPPFLAGS"
12461246

1247-
dnl Boost >= 1.50 uses sleep_for rather than the now-deprecated sleep, however
1248-
dnl it was broken from 1.50 to 1.52 when backed by nanosleep. Use sleep_for if
1249-
dnl a working version is available, else fall back to sleep. sleep was removed
1250-
dnl after 1.56.
1251-
dnl If neither is available, abort.
1252-
TEMP_LIBS="$LIBS"
1253-
LIBS="$BOOST_LIBS $LIBS"
1254-
TEMP_CPPFLAGS="$CPPFLAGS"
1255-
CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
1256-
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1257-
#include <boost/thread/thread.hpp>
1258-
#include <boost/version.hpp>
1259-
]],[[
1260-
#if BOOST_VERSION >= 105000 && (!defined(BOOST_HAS_NANOSLEEP) || BOOST_VERSION >= 105200)
1261-
boost::this_thread::sleep_for(boost::chrono::milliseconds(0));
1262-
#else
1263-
choke me
1264-
#endif
1265-
]])],
1266-
[boost_sleep=yes;
1267-
AC_DEFINE(HAVE_WORKING_BOOST_SLEEP_FOR, 1, [Define this symbol if boost sleep_for works])],
1268-
[boost_sleep=no])
1269-
LIBS="$TEMP_LIBS"
1270-
CPPFLAGS="$TEMP_CPPFLAGS"
1271-
1272-
if test x$boost_sleep != xyes; then
1273-
TEMP_LIBS="$LIBS"
1274-
LIBS="$BOOST_LIBS $LIBS"
1275-
TEMP_CPPFLAGS="$CPPFLAGS"
1276-
CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
1277-
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1278-
#include <boost/version.hpp>
1279-
#include <boost/thread.hpp>
1280-
#include <boost/date_time/posix_time/posix_time_types.hpp>
1281-
]],[[
1282-
#if BOOST_VERSION <= 105600
1283-
boost::this_thread::sleep(boost::posix_time::milliseconds(0));
1284-
#else
1285-
choke me
1286-
#endif
1287-
]])],
1288-
[boost_sleep=yes; AC_DEFINE(HAVE_WORKING_BOOST_SLEEP, 1, [Define this symbol if boost sleep works])],
1289-
[boost_sleep=no])
1290-
LIBS="$TEMP_LIBS"
1291-
CPPFLAGS="$TEMP_CPPFLAGS"
1292-
fi
1293-
1294-
if test x$boost_sleep != xyes; then
1295-
AC_MSG_ERROR(No working boost sleep implementation found.)
1296-
fi
1297-
12981247
fi
12991248

13001249
if test x$use_pkgconfig = xyes; then

src/bench/examples.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
static void Sleep100ms(benchmark::State& state)
1111
{
1212
while (state.KeepRunning()) {
13-
MilliSleep(100);
13+
UninterruptibleSleep(std::chrono::milliseconds{100});
1414
}
1515
}
1616

src/bitcoin-cli.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ static int CommandLineRPC(int argc, char *argv[])
524524
}
525525
catch (const CConnectionFailed&) {
526526
if (fWait)
527-
MilliSleep(1000);
527+
UninterruptibleSleep(std::chrono::milliseconds{1000});
528528
else
529529
throw;
530530
}

src/bitcoind.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static void WaitForShutdown(NodeContext& node)
2929
{
3030
while (!ShutdownRequested())
3131
{
32-
MilliSleep(200);
32+
UninterruptibleSleep(std::chrono::milliseconds{200});
3333
}
3434
Interrupt(node);
3535
}

src/httprpc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ static bool HTTPReq_JSONRPC(HTTPRequest* req, const std::string &)
174174
/* Deter brute-forcing
175175
If this results in a DoS the user really
176176
shouldn't have their RPC port exposed. */
177-
MilliSleep(250);
177+
UninterruptibleSleep(std::chrono::milliseconds{250});
178178

179179
req->WriteHeader("WWW-Authenticate", WWW_AUTH_HEADER_DATA);
180180
req->WriteReply(HTTP_UNAUTHORIZED);

src/rpc/server.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ UniValue stop(const JSONRPCRequest& jsonRequest)
169169
// this reply will get back to the client.
170170
StartShutdown();
171171
if (jsonRequest.params[0].isNum()) {
172-
MilliSleep(jsonRequest.params[0].get_int());
172+
UninterruptibleSleep(std::chrono::milliseconds{jsonRequest.params[0].get_int()});
173173
}
174174
return PACKAGE_NAME " stopping";
175175
}

src/test/blockfilter_index_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ BOOST_FIXTURE_TEST_CASE(blockfilter_index_initial_sync, BuildChainTestingSetup)
138138
int64_t time_start = GetTimeMillis();
139139
while (!filter_index.BlockUntilSyncedToCurrentChain()) {
140140
BOOST_REQUIRE(time_start + timeout_ms > GetTimeMillis());
141-
MilliSleep(100);
141+
UninterruptibleSleep(std::chrono::milliseconds{100});
142142
}
143143

144144
// Check that filter index has all blocks that were in the chain before it started.

src/test/checkqueue_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueueControl_Locks)
393393
CCheckQueueControl<FakeCheck> control(queue.get());
394394
// While sleeping, no other thread should execute to this point
395395
auto observed = ++nThreads;
396-
MilliSleep(10);
396+
UninterruptibleSleep(std::chrono::milliseconds{10});
397397
fails += observed != nThreads;
398398
});
399399
}

src/test/scheduler_tests.cpp

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <random.h>
66
#include <scheduler.h>
7+
#include <util/time.h>
78

89
#include <boost/thread.hpp>
910
#include <boost/test/unit_test.hpp>
@@ -23,18 +24,6 @@ static void microTask(CScheduler& s, boost::mutex& mutex, int& counter, int delt
2324
}
2425
}
2526

26-
static void MicroSleep(uint64_t n)
27-
{
28-
#if defined(HAVE_WORKING_BOOST_SLEEP_FOR)
29-
boost::this_thread::sleep_for(boost::chrono::microseconds(n));
30-
#elif defined(HAVE_WORKING_BOOST_SLEEP)
31-
boost::this_thread::sleep(boost::posix_time::microseconds(n));
32-
#else
33-
//should never get here
34-
#error missing boost sleep implementation
35-
#endif
36-
}
37-
3827
BOOST_AUTO_TEST_CASE(manythreads)
3928
{
4029
// Stress test: hundreds of microsecond-scheduled tasks,
@@ -81,7 +70,7 @@ BOOST_AUTO_TEST_CASE(manythreads)
8170
for (int i = 0; i < 5; i++)
8271
microThreads.create_thread(std::bind(&CScheduler::serviceQueue, &microTasks));
8372

84-
MicroSleep(600);
73+
UninterruptibleSleep(std::chrono::microseconds{600});
8574
now = boost::chrono::system_clock::now();
8675

8776
// More threads and more tasks:

0 commit comments

Comments
 (0)