Skip to content

Commit

Permalink
replace boost sleep with std sleep
Browse files Browse the repository at this point in the history
makes compat  with modern boost version when compiling on WSL
  • Loading branch information
justinvforvendetta committed Sep 28, 2023
1 parent 878ad9e commit 6adb82d
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/httprpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ static bool HTTPReq_JSONRPC(HTTPRequest* req, const std::string &)
/* Deter brute-forcing
If this results in a DoS the user really
shouldn't have their RPC port exposed. */
MilliSleep(250);
UninterruptibleSleep(std::chrono::milliseconds{250});

req->WriteHeader("WWW-Authenticate", WWW_AUTH_HEADER_DATA);
req->WriteReply(HTTP_UNAUTHORIZED);
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ UniValue stop(const JSONRPCRequest& jsonRequest)
// this reply will get back to the client.
StartShutdown();
if (jsonRequest.params[0].isNum()) {
MilliSleep(jsonRequest.params[0].get_int());
UninterruptibleSleep(std::chrono::milliseconds{jsonRequest.params[0].get_int()});
}
return "Verge server stopping";
}
Expand Down
24 changes: 4 additions & 20 deletions src/util/time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@

#include <atomic>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/thread.hpp>
#include <ctime>
#include <thread>
#include <tinyformat.h>

void UninterruptibleSleep(const std::chrono::microseconds& n) { std::this_thread::sleep_for(n); }

static std::atomic<int64_t> nMockTime(0); //!< For unit testing

int64_t GetTime()
Expand Down Expand Up @@ -59,24 +61,6 @@ int64_t GetSystemTimeInSeconds()
return GetTimeMicros()/1000000;
}

void MilliSleep(int64_t n)
{

/**
* Boost's sleep_for was uninterruptible when backed by nanosleep from 1.50
* until fixed in 1.52. Use the deprecated sleep method for the broken case.
* See: https://svn.boost.org/trac/boost/ticket/7238
*/
#if defined(HAVE_WORKING_BOOST_SLEEP_FOR)
boost::this_thread::sleep_for(boost::chrono::milliseconds(n));
#elif defined(HAVE_WORKING_BOOST_SLEEP)
boost::this_thread::sleep(boost::posix_time::milliseconds(n));
#else
//should never get here
#error missing boost sleep implementation
#endif
}

std::string FormatISO8601DateTime(int64_t nTime) {
struct tm ts;
time_t time_val = nTime;
Expand Down Expand Up @@ -127,4 +111,4 @@ int64_t ParseISO8601DateTime(const std::string & str)
if (ptime.is_not_a_date_time() || epoch > ptime)
return 0;
return (ptime - epoch).total_seconds();
}
}
4 changes: 3 additions & 1 deletion src/util/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

#include <stdint.h>
#include <string>
#include <chrono>

void UninterruptibleSleep(const std::chrono::microseconds& n);

/**
* GetTimeMicros() and GetTimeMillis() both return the system time, but in
Expand All @@ -26,7 +29,6 @@ int64_t GetTimeMicros();
int64_t GetSystemTimeInSeconds(); // Like GetTime(), but not mockable
void SetMockTime(int64_t nMockTimeIn);
int64_t GetMockTime();
void MilliSleep(int64_t n);

/**
* ISO 8601 formatting is preferred. Use the FormatISO8601{DateTime,Date,Time}
Expand Down
2 changes: 1 addition & 1 deletion src/verge-cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ static int CommandLineRPC(int argc, char *argv[])
}
catch (const CConnectionFailed&) {
if (fWait)
MilliSleep(1000);
UninterruptibleSleep(std::chrono::milliseconds{1000});
else
throw;
}
Expand Down
2 changes: 1 addition & 1 deletion src/verged.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static void WaitForShutdown()
{
while (!ShutdownRequested())
{
MilliSleep(200);
UninterruptibleSleep(std::chrono::milliseconds{200});
}
Interrupt();
}
Expand Down
4 changes: 2 additions & 2 deletions src/wallet/db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ bool BerkeleyBatch::Rewrite(BerkeleyDatabase& database, const char* pszSkip)
return fSuccess;
}
}
MilliSleep(100);
UninterruptibleSleep(std::chrono::milliseconds{100});
}
}

Expand Down Expand Up @@ -787,7 +787,7 @@ bool BerkeleyDatabase::Backup(const std::string& strDest)
}
}
}
MilliSleep(100);
UninterruptibleSleep(std::chrono::milliseconds{100});
}
}

Expand Down

0 comments on commit 6adb82d

Please sign in to comment.