diff --git a/src/utiltime.cpp b/src/utiltime.cpp index e9dde57be6a..ab78fb3b685 100644 --- a/src/utiltime.cpp +++ b/src/utiltime.cpp @@ -12,7 +12,6 @@ #include #include -#include #include #include #include @@ -47,6 +46,14 @@ template std::chrono::seconds GetTime(); template std::chrono::milliseconds GetTime(); template std::chrono::microseconds GetTime(); +template +static T GetSystemTime() +{ + const auto now = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()); + assert(now.count() > 0); + return now; +} + int64_t GetMockableTimeMicros() { int64_t mocktime = GetMockTime(); @@ -66,23 +73,17 @@ int64_t GetMockTime() int64_t GetTimeMillis() { - int64_t now = (boost::posix_time::microsec_clock::universal_time() - - boost::posix_time::ptime(boost::gregorian::date(1970,1,1))).total_milliseconds(); - assert(now > 0); - return now; + return int64_t{GetSystemTime().count()}; } int64_t GetTimeMicros() { - int64_t now = (boost::posix_time::microsec_clock::universal_time() - - boost::posix_time::ptime(boost::gregorian::date(1970,1,1))).total_microseconds(); - assert(now > 0); - return now; + return int64_t{GetSystemTime().count()}; } int64_t GetSystemTimeInSeconds() { - return GetTimeMicros()/1000000; + return int64_t{GetSystemTime().count()}; } /** Return a time useful for the debug log */ @@ -93,11 +94,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()); diff --git a/src/utiltime.h b/src/utiltime.h index 6761e3f9fce..b0cd34a6f91 100644 --- a/src/utiltime.h +++ b/src/utiltime.h @@ -58,8 +58,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 T GetTime(); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index be4bd1dbf8c..305dedc5d94 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -4032,7 +4032,7 @@ bool CWallet::BackupWallet(const std::string& strDest) } } } - MilliSleep(100); + boost::this_thread::sleep_for(boost::chrono::milliseconds(100)); } return false; } diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp index 516dac2cbf0..b36db720e19 100644 --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -796,7 +796,7 @@ void ThreadFlushWalletDB() int64_t nLastWalletUpdate = GetTime(); while (true) { - MilliSleep(500); + boost::this_thread::sleep_for(boost::chrono::milliseconds(500)); if (nLastSeen != CWalletDB::GetUpdateCounter()) {