Skip to content

Commit

Permalink
swap boost sleep with std sleep in bench/test
Browse files Browse the repository at this point in the history
removes all remaining traces of boost sleep, replaces with std chrono/time.h
  • Loading branch information
justinvforvendetta committed Sep 28, 2023
1 parent 19c6040 commit c9fbda0
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/bench/examples.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
static void Sleep100ms(benchmark::State& state)
{
while (state.KeepRunning()) {
MilliSleep(100);
UninterruptibleSleep(std::chrono::milliseconds{100});
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/checkqueue_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueueControl_Locks)
CCheckQueueControl<FakeCheck> control(queue.get());
// While sleeping, no other thread should execute to this point
auto observed = ++nThreads;
MilliSleep(10);
UninterruptibleSleep(std::chrono::milliseconds{10});
fails += observed != nThreads;
});
}
Expand Down
15 changes: 2 additions & 13 deletions src/test/scheduler_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <random.h>
#include <scheduler.h>
#include <util/time.h>

#include <test/setup_common.h>

Expand All @@ -27,18 +28,6 @@ static void microTask(CScheduler& s, boost::mutex& mutex, int& counter, int delt
}
}

static void MicroSleep(uint64_t n)
{
#if defined(HAVE_WORKING_BOOST_SLEEP_FOR)
boost::this_thread::sleep_for(boost::chrono::microseconds(n));
#elif defined(HAVE_WORKING_BOOST_SLEEP)
boost::this_thread::sleep(boost::posix_time::microseconds(n));
#else
//should never get here
#error missing boost sleep implementation
#endif
}

BOOST_AUTO_TEST_CASE(manythreads)
{
// Stress test: hundreds of microsecond-scheduled tasks,
Expand Down Expand Up @@ -85,7 +74,7 @@ BOOST_AUTO_TEST_CASE(manythreads)
for (int i = 0; i < 5; i++)
microThreads.create_thread(boost::bind(&CScheduler::serviceQueue, &microTasks));

MicroSleep(600);
UninterruptibleSleep(std::chrono::microseconds{600});
now = boost::chrono::system_clock::now();

// More threads and more tasks:
Expand Down
2 changes: 1 addition & 1 deletion src/test/txindex_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ BOOST_FIXTURE_TEST_CASE(txindex_initial_sync, TestChain100Setup)
int64_t time_start = GetTimeMillis();
while (!txindex.BlockUntilSyncedToCurrentChain()) {
BOOST_REQUIRE(time_start + timeout_ms > GetTimeMillis());
MilliSleep(100);
UninterruptibleSleep(std::chrono::milliseconds{100});
}

// Check that txindex has all txs that were in the chain before it started.
Expand Down
2 changes: 1 addition & 1 deletion src/test/validation_block_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ void BuildChain(const uint256& root, int height, const unsigned int invalid_rate
threads.join_all();
while (GetMainSignals().CallbacksPending() > 0) {
MilliSleep(100);
UninterruptibleSleep(std::chrono::milliseconds{100});
}
UnregisterValidationInterface(&sub);
Expand Down

0 comments on commit c9fbda0

Please sign in to comment.