Skip to content

Commit

Permalink
util: Remove unused MilliSleep
Browse files Browse the repository at this point in the history
Cherry-picked from: fae86c3

Additional edits were needed in wallet.cpp and walletdb.cpp
  • Loading branch information
MarcoFalke authored and xanimo committed Mar 30, 2024
1 parent 2be791a commit afb4174
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 23 deletions.
8 changes: 2 additions & 6 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 "utiltime.h"

#include "test/test_bitcoin.h"

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

static void MicroSleep(uint64_t n)
{
boost::this_thread::sleep_for(boost::chrono::microseconds(n));
}

BOOST_AUTO_TEST_CASE(manythreads)
{
// Stress test: hundreds of microsecond-scheduled tasks,
Expand Down Expand Up @@ -78,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
6 changes: 0 additions & 6 deletions src/utiltime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

#include <atomic>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/thread.hpp>
#include <ctime>
#include <chrono>
#include <thread>
Expand Down Expand Up @@ -93,11 +92,6 @@ int64_t GetLogTimeMicros()
return GetTimeMicros();
}

void MilliSleep(int64_t n)
{
boost::this_thread::sleep_for(boost::chrono::milliseconds(n));
}

std::string DateTimeStrFormat(const char* pszFormat, int64_t nTime)
{
static std::locale classic(std::locale::classic());
Expand Down
9 changes: 0 additions & 9 deletions src/utiltime.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ int64_t GetTimeMicros();
/** Returns the system time (not mockable) */
int64_t GetSystemTimeInSeconds(); // Like GetTime(), but not mockable

/** For testing. Set e.g. with the setmocktime rpc, or -mocktime argument */
void SetMockTime(int64_t nMockTimeIn);
/** For testing */
int64_t GetMockTime();

void MilliSleep(int64_t n);

/**
* GetTimeMicros() and GetTimeMillis() both return the system time, but in
* different units. GetTime() returns the system time in seconds, but also
Expand All @@ -58,8 +51,6 @@ void SetMockTime(int64_t nMockTimeIn);
/** For testing */
int64_t GetMockTime();

void MilliSleep(int64_t n);

/** Return system time (or mocked time, if set) */
template <typename T>
T GetTime();
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4032,7 +4032,7 @@ bool CWallet::BackupWallet(const std::string& strDest)
}
}
}
MilliSleep(100);
UninterruptibleSleep(std::chrono::microseconds{100});
}
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/walletdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ void ThreadFlushWalletDB()
int64_t nLastWalletUpdate = GetTime();
while (true)
{
MilliSleep(500);
UninterruptibleSleep(std::chrono::microseconds{500});

if (nLastSeen != CWalletDB::GetUpdateCounter())
{
Expand Down

0 comments on commit afb4174

Please sign in to comment.